Skip to content

Instantly share code, notes, and snippets.

@incanus
Created December 22, 2010 02:23
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incanus/750985 to your computer and use it in GitHub Desktop.
Save incanus/750985 to your computer and use it in GitHub Desktop.
This is an Xcode build script that will automatically change your app's Info.plist CFBundleVersion string to match the latest git tag for the working copy. If you have commits beyond the last tagged one, it will append a 'd' to the number.
#/bin/sh
INFO=$( echo $PWD )/MyApp-Info
TAG=$( git describe --tags `git rev-list --tags --max-count=1` )
COMMIT=
GITPATH=/usr/bin:/usr/local/bin:/usr/local/git/bin
PATH=$PATH:$GITPATH; export PATH
if [ -z $( which git ) ]; then
echo "Unable to find git binary in \$GITPATH"
exit 1
fi
# check if we've got untagged commits, adding a 'd' if so
if [ $( git log | sed -n '1p' | awk '{ print $2 }' ) != $( git rev-list --tags --max-count=1 ) ]; then
TAG=$( echo $TAG )d
fi
CURRENT=$( defaults read "$INFO" CFBundleVersion )
if [ $CURRENT != $TAG ]; then
# output for Xcode logging
echo "Updating CFBundleVersion to $TAG"
# write it to the Info.plist
defaults write "$INFO" CFBundleVersion $TAG
else
# output for Xcode logging
echo "CFBundleVersion already at $TAG"
fi
@lilyball
Copy link

Why not use something like git describe to find the closest tag?

@incanus
Copy link
Author

incanus commented Dec 22, 2010

Good idea! I think mainly because git help didn't list it, so I wasn't aware of it! It solves both the "latest" issue as well as detecting commits past the last tag. Thanks!

@lilyball
Copy link

git describe in general is a good format for showing the current build. If you don't like the fact that it gives a precise count from the latest tag, along with an abbreviated hash, you can use git describe --abbrev=0 to simply get the tag, and then test if that tag represents the current commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment