Setting Xcode build version to Git commit name

One consequence of changing from Subversion to Git for my Xcode projects is that I need to the change the run-script I was using to insert the Subversion revision number into my targets Info.plist file.

I use agvtool to set my projects actual build number but I also like to store the corresponding repository version in a separate key. Previously I had the following run script added to each target of a project:

/usr/libexec/PlistBuddy -c "Set :BuildRevision `/usr/bin/svnversion -n`" \
                           ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}

This just extracted the subversion revision number and inserted it into a key named BuildRevision in the targets Info.plist file. The equivalent that I came up with for Git is as follows:

GIT=/usr/local/git/bin/git
GITOPTIONS="--pretty=oneline --abbrev-commit"
CUT=/usr/bin/cut

/usr/libexec/PlistBuddy -c "Set :BuildRevision `$GIT log -1 $GITOPTIONS | \
                       $CUT -c1-7`" ${TARGET_BUILD_DIR}/${INFOPLIST_PATH}

This generates a string from the first seven characters of the current commit name which should be enough to identify the build.

Never miss a post!

iOS Size Classes Cheat Sheet

Subscribe and get my free iOS Size Classes Cheat Sheet

Success! Now check your email to confirm your subscription and download your free guide to iOS Size Classes.

There was an error submitting your subscription. Please try again.

Unsubscribe at any time.
No time to watch WWDC videos?

Sign up to get my iOS posts direct to your inbox and I will send you a free PDF of my iOS Size Classes Cheat Sheet.

OK! Check your inbox (or spam folder) for an email to confirm your details and download your free guide to iOS Size Classes.

There was an error submitting your subscription. Please try again.

Unsubscribe at any time.
Archives Categories