Tuesday, September 24, 2013

git-tf : Finally Got It Working with TFS

If you have a mixed computing environment (Windows and Mac) and you want to keep all your source in Team Foundation Server, then you'll most likely use Git-Tf to checkin your git commits into TFS and pull from TFS into git. 

Note: some of this post is copied directly from other sources to preserve clarity, but none of the other sources provided enough of the detail for a beginner to git-tf like me.  So I decided to combine all the separate steps into a single walk through. 

Here's what I had to do after scouring the net for partial solutions:

Assumptions:

  1. You already have TFS up and running and have created a blank project/folder for your iOS source to be committed into.
  2. You have already connected your iOS project to git locally (I am not paying for a private git repo, nor would I want to share this project publicly   All the git commands are working at the local repo on my Mac (except the very last one, "git push". I tell you about it, but I don't actually use it, since I'm not publishing my git repo to the world)

In order to check-in your existing xCode project code into TFS:
  1. On your Mac, download and extract Git-TF. I placed it in /users/{yourloginaccountname}/Git-Tf
  2. Create the .profile file:
    1. Open Terminal and type in "cd ~/" to make sure you are at your home directory.
    2. Create the .profile file with the following command: "touch .profile".
    3. Open the .profile file with the following command: "open .profile".
      1. The Open command will use the default editor, but you could alternatively use nano to edit the file as well: "sudo nano .profile".
  3. Either way, you need to then make sure you have added the following text into the .profile file:
      • export JAVA_HOME=/Library/export JAVA_HOME=/Library/Java/Home
        • export PATH=$PATH:$JAVA_HOME/bin:/git_t
          • export PATH="/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/":$
            • export PATH="/Users/{yourloginaccountname}/Git-Tf/":$PATH
            1. You could just run the above commands one by one in the terminal app as well, but I prefer that they are in the .profile file that gets merged with the $PATH when you start the computer.
              1. But the above is the generic version that you can use.  Notice that the only thing you need to change is the {yourloginaccountname} in the last line, if JAVA is installed in the /Library/Java/Home directory and /Users/{yourloginaccountname}/Git-Tf is really where you installed Git-Tf.
            2. Make sure the double quotes in the lines above (last two commands) are really double quotes and not the curly double quotes which translate to a different character and will not work!
          1. Save the file and close it.
            1. If you are using nano press "Control-x" then press "y"then enter, then press enter again to save the file. (look at the commands at the bottom of the terminal to see this.)
          2. Now still in terminal, change the working directory to your xCode project folder: e.g.:
            cd "/users/{yourloginaccountname}/documents/xCode Projects/testproject1/" Wherever your project lives on file.
          3. If you show all hidden folders & files, you will see the hidden .git folder – this is your projects GIT repository folder. If this folder doesn’t exist, you don’t have GIT setup with your project – read this post to find out how to create one.
          4. Run Commands:
            • For a team working with an existing Git repo, a developer sharing changes to TFS using Git-TF would use the following workflow.
              1. git tf configure http://myserver:8080/tfs/YourCollection $/Projects/Development/Mobile/iOS/iPhone/ 
                Configure the existing repo's relationship with TFS
              2. git tf pull 
                Fetch the latest changes from TFS and merge those changes with the local changes. Note, merging is important when working in a team configuration. See "Rebase vs. Merge" below.
              3. git commit -a -m "merge commit"
              4. git tf checkin
                Check in the merge commit as a single TFS changeset
                • This step game me some problems.  During the checkin, TFS will create a temporary workspace before actually commiting the files.  git-tf will attempt to acuire a lock on the project directory, if it fails (due to some one else having a file checked out) then follow the following steps:
                1. Open Visual Studio 2010
                2. Open the "Team Explorer" tab, you may need to add this tab if you don't have it added already.
                3. Click "Pending Changes" to open the pending changes view.
                4. Click on the drop-down list labeled "Actions" and choose "Manage Workspaces".
                5. Down at the bottom of the "Manage Workspaces", click "Show remote workspaces".
                6. You should then see a workspace with the name like git-tf[some-big-number].  Select it, then delete it.  This will not change your workspace at all, but it will remove the locked workspace.  Once you delete the remote workspace, you can then run the checkin again:
                7. git tf checkin
              5. git push
                Push the merge commit to the origin
                • You only need to use the git push command if you are publishing to a free public git repo or are paying the $7 monthly subscription for a private git repo and you are intending to share the repo with multiple developers.
          5. If you get prompted to install Java in step 5 – do it. Then re-run the command.
          6. Now if(when) you get a java security exception, you will have to install your TFS SSL certificate and register it with JAVA so GIT-TF can talk to your TFS. You will only have to do this once.

              1. Download this InstallCert.jar: I put it inside the Git-TF folder – but it could go anywhere.
              2. In terminal, CD to the folder where you downloaded the .jar file. Then run the command:
                java -jar InstallCert.jar  https://yourtfswebaddress.com/tfs/gittfs
              3. This will create a file “jssecacerts”. Put this file in/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib (your java version may vary)
              4. Rerun the commands in step 5.
              5. Your code should now be in TFS
          How to pull down the code from TFS (if you don't have the project and want to get it for the first time):
          • Steps are nearly the same as above, after installing Git-TF and establishing the path variables, CD to your project directory, and run the command: 


            1. git tf clone http://myserver:8080/tfs/YourCollection $/Projects/Development/Mobile/iOS/iPhone/ 
            • Changes are cloned down from TFS to git


          And Just to Be complete: Individual Developer with a New Repo
          A typical workflow for an individual developer using the Git-TF tools are as follows.
          1. git tf clone http://myserver:8080/tfs/YourCollection $/Projects/Development/Mobile/iOS/iPhone/ 
            Changes are cloned down from TFS to git
          2. Make changes to the file in the Git repo
          3. git commit -a -m "commit one" 
            (commit changes locally)
          4. Make more changes
          5. git commit -a -m "commit two"
          6. git tf pull --rebase
            Fetch the latest changes from TFS and rebase master on top of the fetched changes.  You should research the difference between rebase and merge.  Rebase has potential issues if you are working in a team environment.
          7. git tf checkin 
            Check in the changes from "commit one" and "commit two" as a single TFS changeset

          Friday, June 14, 2013

          SQL - Check Multiple Tables For Data (IF NOT EXISTS) in a Single IF Statement

          Question:  How do you check for existence (IF EXISTS or IF NOT EXISTS) of data across multiple tables in a single if statement in SQL?

          Answer:
          IF NOT EXISTS (SELECT 1 FROM Table1) AND NOT EXISTS (SELECT 1 FROM Table2) AND NOT EXISTS (SELECT 1 FROM Table3)
          BEGIN
          PRINT 'DATA DOES NOT EXIST'
          END
          ELSE
          BEGIN
          PRINT 'DATA DOES EXIST'
          END

          Friday, November 2, 2012

          Fitting Big Files (over 4GB) On A Fat32 Thumb Drive

          Recently I made a back up of a VirtualBox VM drive clone for the intention of moving the drive to another machine.  The VM drive was using a variable sized hard drive with a cap at 200GB.  The clone was only 52GB so far.  I had a spare 64GB thumb drive, so I figured that would be the best way to move it since the target computer was not on the same network as the source computer.  I wanted to compress this folder and them copy it to the thumb drive to speed the copy process.  So I used WinRAR.  It took an hour and a half to zip that 52GB folder to a 19GB ".rar" file.  I then plugged in my trusty thumb drive and attempted to copy the file.  To my horror, I got the dreaded message, "The file 'Ubuntu 10.04 Clone.rar' is too big for the destination file system." ...  What?!  But I have 64GB available!

          Long story short.  The thumb drive was formatted using FAT32 (as opposed to NTFS), which is an "older" Windows file system that does not allow for files greater than 4GB.  WinRAR is now my best friend.  I then needed to re-compress the 52BG folder, but this time set "Split to Volumes, size" as "4,095 MB (FAT32)".  What WinRAR does is creates a set of files that are broken up by the file limit you set.  The last file is usually smaller.  So now I ended up with 5 files all 4GB each except the last one was 2GB.  And copying them to the thumb drive worked great.

          In order to decompress these files, you need them all together, and right click one of them, usually the first file.  Select Extract to... and select the details.

          Problem solved!

          Monday, December 5, 2011

          Determine WHEN and WHAT FILE was LAST Used to RESTORE a SQL SERVER Database

          Sometimes you've restored a database from a production copy or whatever, and you move on to a different project.  Time goes by, and someone needs to run something on that database, but they need to know if the database has already been restored from a recent copy of production...  How do you find out when the last time a database was restored and what file was used to restore it?

          This little script has been a HUGE time saver.  I use this script to determine if I need to have our IT group backup and download a copy of a production database.  If the database I'm looking at was recently refreshed from production already, I don't need them to waste that kind of time.  That can save us up to literally 24 hours in wasted time in some cases.

          To run this, copy and paste this code into SQL Server Management Studio 2005 or greater (I think this works with SQL 2000 as well with Query Analyzer).  Don't forget to make sure you have the database selected in the dropdown list for which you want to find out this information:

          DECLARE @backup_finish_date DATETIME
          DECLARE @source_database_name VARCHAR(100)
          DECLARE @restore_date DATETIME
          DECLARE @backup_file_used_for_restore VARCHAR(500)

          SELECT TOP 1 @restore_date = [rs].[restore_date],
                       @backup_finish_date = [bs].[backup_finish_date],
                       @source_database_name = [bs].[database_name],
                       @backup_file_used_for_restore = [bmf].[physical_device_name]
          FROM   msdb..restorehistory rs
                 INNER JOIN msdb..backupset bs
                   ON [rs].[backup_set_id] = [bs].[backup_set_id]
                 INNER JOIN msdb..backupmediafamily bmf
                   ON [bs].[media_set_id] = [bmf].[media_set_id]
          WHERE  [rs].[destination_database_name] = Db_name()
          ORDER  BY [rs].[restore_date] DESC

          PRINT @@SERVERNAME + ' : ' + Db_name()

          PRINT 'was restored on: ' + Isnull(CAST(@restore_date AS VARCHAR), 'No Date')

          PRINT 'from a backup of database: ' + Isnull(@source_database_name, 'No Name')

          PRINT 'taken on: ' + Isnull(CAST(@backup_finish_date AS VARCHAR), 'No Date')

          PRINT 'in file: ' + Isnull(@backup_file_used_for_restore, 'No Name')  


          The results will typically look like this:

          CCGTESTDB\SQL2005 : stIowaProd
          was restored on: Dec  5 2011  1:15PM
          from a backup of database: db_CNPProd
          taken on: Nov  8 2011  1:49PM
          in file: E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\Iowa\db_CNPProd_201111081349\db_CNPProd_201111081349.bak


          How do you determine this information?  Any better solution, please comment.

          Saturday, December 3, 2011

          5 All-Time Greatest Toys


          The holidays come every year, and we stress over toys and gifts.  But some toys will always be the best...  follow to see the 5 all-time greatest toys ever.

          Sunday, November 6, 2011

          Windows Phone 7.1 SDK Error


          I need your help! "GetCopyToOutputDirectoryContentProjectItems"

          I went to a Microsoft Code Camp a few days ago and got all pumped up about the Windows Phone 7.1 release (Mango) SDK.  They handed it out to us. I installed it.  I have tried building many default projects but to no avail, I'm getting the following error:

          The target "GetCopyToOutputDirectoryContentProjectItems" does not exist in the project.
          WHAT DOES THIS MEAN???? I'm going to lose all my hair from this error.

          I'm using the release candidate (not the beta 2, at least I don't think it is...) that was given to us at the Mango Code Camp here in AZ a few days ago.  I tried to uninstall, re-boot, re-install, re-boot.  And all combinations of the same.  Nothing is working.  There is something else I found strange:  Part of the install cannot install the XNA Game Studio plugin and some other XNA item.  I don't have the XNA Game Studio installed.  I' not sure if it the Windows Phone 7.1 SDK tris to install XNA GS or not, but I tried to manually install it and I' getting an error with that as well.  I think that it had to do with the live installer.  I uninstalled it too and tried to install again.  Still same error.  It seems like the project is fine (since this happens on ALL my Windows Phone Projects including one I've tried to target the 7.0 Windows Mobile.  Something seems like it's missing but I cannot figure it out. I'd be happy to send any log files if needed.

          FYI, The 3 guys at MS that were there at the phone camp had never seen this error and didn't have any idea what to do other than re-install and re-boot.  No help.  PLEASE HELP!!!  Any other ideas?  Thanks!

          Note:  I also uninstalled the Silverlight 4 SDK and even installed the Silverlight 5 SDK once it still did not work and both tries still did nothing to help resolve this.

          Friday, February 11, 2011

          Facebook and Android API Documentation

          I recently integrated Facebook access into one of my android apps (My Missionary). It was the worst pain in the backside! Why, you ask? Because the documentation is not accurate. Documentation directly from Facebook! Its terrible. The only way I figured it out was through scouring the web all night long. And I mean all night. Then, I even had to modify some of the Facebook code (the library you can download from FB) in order to make it work! Oh well. I learned. I'll post my findings here so you don't have to waste a night of sleep...