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

Sign up to get my iOS posts and news direct to your inbox and I'll also send you a PDF of my WWDC Viewing Guide

    Unsubscribe at any time. See privacy policy.

    Archives Categories