Skip to content

Instantly share code, notes, and snippets.

@HiddenJester
Last active August 29, 2015 14:20
Show Gist options
  • Save HiddenJester/711365db5fc5981bd87a to your computer and use it in GitHub Desktop.
Save HiddenJester/711365db5fc5981bd87a to your computer and use it in GitHub Desktop.
A script usable as a git pre-commit hook that sets the CFBundleVersion of a specified plist to a count of commits in the repository. This is useful for WatchKit apps that cannot run a Run Scripts phase, but must sync version information to the host app.
#!/bin/sh
# Hacky script to update the version of the WatchKit App bundle version to everything else. All of the other targets
# a run script phase that uses setbuildversion.sh out of HJSKit to set the build version to the commit info from git.
# But WatchKit apps can't have a run script phase yet so this pre-commit script mimics the effects but actually edits
# the Info.plist used by by the WatchKit target. Pieces of this are from buildversion.sh, choppped & screwed.
# Redirect output to stderr.
exec 1>&2
git=`sh /etc/profile; which git`
# Since this a pre-commit script we don't want the *current* commit count, we want the commit count we're about to make
commitCount=`"$git" rev-list --all |wc -l`
nextCommit=$(echo "$commitCount + 1" | bc)
plistFilename="/Users/tsanders/Transporter/code/TodayTimer/TodayTimer WatchKit App/Info.plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $nextCommit" "$plistFilename"
$git add "$plistFilename"
echo "Bumped version in $plistFilename to $nextCommit and staged the file."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment