Skip to content

Instantly share code, notes, and snippets.

@mitchcohen
mitchcohen / xcode-git-buildnumber.sh
Last active December 17, 2015 16:39 — forked from jpwatts/xcode-git-version.sh
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}