Created
December 22, 2010 02:23
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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 |
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!
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
Why not use something like
git describe
to find the closest tag?