Skip to content

Instantly share code, notes, and snippets.

@timshadel
Forked from ELLIOTTCABLE/autopopulate_git_sha.rb
Created January 5, 2010 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timshadel/269430 to your computer and use it in GitHub Desktop.
Save timshadel/269430 to your computer and use it in GitHub Desktop.
#!/usr/bin/env macruby
# From: http://www.stompy.org/2008/08/14/xcode-and-git-another-build-script/
# Expanded from here: http://www.furmanek.net/36/using-macruby-to-set-xcode-project-version-from-git/
# Xcode auto-versioning script for Subversion by Axel Andersson
# Updated for git by Marcus S. Zarra and Matt Long
# Converted to ruby by Abizern
# Converted to MacRuby by Gregory Furmanek
# Merged with MacRuby version by elliottcable
# Dirty handling, style and build-only version update by timshadel
# Appends the git sha to the version number set in Xcode.
git = '/opt/local/bin/git'
sha = `#{git} rev-parse --short HEAD`.chomp
working_state = `#{git} status 2> /dev/null | tail -n1`.chomp
dirty = (working_state == "nothing to commit (working directory clean)") ? "" : "?"
info_file = ENV['BUILT_PRODUCTS_DIR'] + "/" + ENV['INFOPLIST_PATH']
list = NSMutableDictionary.dictionaryWithContentsOfFile info_file
list['CFBundleVersion'] = "#{dirty}#{sha}#{dirty} #{ENV['BUILD_STYLE']}"
list.writeToFile ENV['BUILT_PRODUCTS_DIR'] + "/" + ENV['INFOPLIST_PATH'], :atomically => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment