Skip to content

Instantly share code, notes, and snippets.

@steipete
Created December 20, 2011 14:34
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save steipete/1501754 to your computer and use it in GitHub Desktop.
Save steipete/1501754 to your computer and use it in GitHub Desktop.
Use Xcode to automatically set git hash
git=`sh /etc/profile; which git`
version=`$git describe --tags --always`
count=`$git rev-list --all |wc -l`
echo -e "#define GIT_VERSION $version\n#define GIT_COMMIT_COUNT $count" > InfoPlist.h
@ReneLindhorst
Copy link

In my projects I use something similar:

#!/bin/sh
#
# Description: This script extracts the git sha and makes it available for the Xcode 
#              Preprocessor of the "Info.plist" file. 
#              Just configure Xcode to use the "Info.plist.includes".
# Author:      René Lindhorst
# Version:     1.1
#

GIT_PATH=`sh /etc/profile; which git`
VERSION=`$GIT_PATH rev-parse --short HEAD`
INFO_PLIST_INC_FILE=$PROJECT_DIR/App/Info.plist.includes

echo "#define GIT_VERSION $VERSION" > $INFO_PLIST_INC_FILE

@steipete
Copy link
Author

Nice! Your script doesn't show the tag, that's why I chose git describe. Otherwise pretty similar. The git-binary-lookup is nice!

@grgcombs
Copy link

grgcombs commented Jan 5, 2012

When where and how do you make use of this script? I must be doing something wrong:

Edit schemes
Select Build->Pre-Actions
Provide Build Settings From (My App Target)
Pasting in the script
Now Run, or Select Product Build

I don't see anything in the project folder or the console that gives me any indication the this is working or not working.

Can I get a hint?

@grgcombs
Copy link

grgcombs commented Jan 5, 2012

Got it ... found your blog post that references this.

What I'd like to see is a means of triggering git describe –abbrev=0 –tags automatically based on the build configuration or the selected scheme, that way I don't need to have a separate target for the distribution.

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