Skip to content

Instantly share code, notes, and snippets.

@pilotmoon
Created August 17, 2011 10:30
Show Gist options
  • Save pilotmoon/1151287 to your computer and use it in GitHub Desktop.
Save pilotmoon/1151287 to your computer and use it in GitHub Desktop.
XCode 4 Git Version Script
# This script fixes up the CFBundleShortVersionString with a string derived from git.
# Place it as a Build Phase just before Copy Bundle Resources
# clone: git submodule add git@gist.github.com:1151287.git gist-1151287
# call: ${SRCROOT}/gist-1151287/insert_version.sh
# PlistBuddy and git executables
buddy='/usr/libexec/PlistBuddy'
git='/usr/bin/git'
# the plist file and key to replace
plist=${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}
key='CFBundleShortVersionString'
# version string for debug builds (e.g. 1.0.2-dev-1-g35d3b126)
version=`$git describe --dirty`
# clean string if Release build
if [ $1 == 'clean' ]
then
if [ ${CONFIGURATION} == 'Release' ]
then
# version string for release builds (strip off everything after dash, e.g. 1.0.2)
# i do this so that i can test appstore submission on builds tagged e.g. 1.0.2-test1
clean_version=`echo $version | sed 's/\-.*//'`
echo "Release build: Cleaning version string from $version to $clean_version"
version=$clean_version
fi
fi
# do the replacement
echo "Setting $key to $version in Info.plist"
$buddy -c "Set :CFBundleShortVersionString $version" "$plist"
@pilotmoon
Copy link
Author

I'm using this gist in a couple of products as a submodule.
git submodule add git@gist.github.com:1151287.git gist-1151287

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