Skip to content

Instantly share code, notes, and snippets.

@mitchcohen
Forked from jpwatts/xcode-git-version.sh
Last active December 17, 2015 16:39
Show Gist options
  • Save mitchcohen/5640287 to your computer and use it in GitHub Desktop.
Save mitchcohen/5640287 to your computer and use it in GitHub Desktop.
Xcode build phase script to set the build number to the number of commits to the git master branch, figuring the commit will be that number in the commit history (never mind the argument of the first commit being #0 or #1...)
# Use the number of commits on the master git branch as build number.
# first, confirm git exists
hash git 2>/dev/null || { echo >&2 "Git required, not installed. Aborting build number update script."; exit 0; }
VERSION=$(git --git-dir="${PROJECT_DIR}/.git" --work-tree="${PROJECT_DIR}" rev-list master | wc -l)
# eventually this will be (number of commits)+1. Mixed opinion here. +1 on dev machine, but not on build/distr machine.
# VERSION=`expr $VERSION + 1`
echo "Build number is now $VERSION"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $VERSION" ${INFOPLIST_FILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment