├── README ├── autocommit-build.sh └── git-version.sh /README: -------------------------------------------------------------------------------- 1 | Scripts to help you use git on Xcode projects. 2 | 3 | `autocommit-build.sh` will commit to the branch `builds` every time Xcode executes a build. 4 | 5 | `git-version.sh` will set the version number in Info.plist based on the most recent git tag. It will include the number of commits since then, and the short version of the sha1 hash of the exact commit that was built. -------------------------------------------------------------------------------- /autocommit-build.sh: -------------------------------------------------------------------------------- 1 | # Xcode git autocommit script by Andre Arko 2 | # This script will automatically commit any changed files to the project's 3 | # git repository, in the branch "builds" 4 | 5 | # If you use this script, you can create more typical commits in the master 6 | # branch with the commands: 7 | # git checkout master 8 | # git checkout builds . 9 | # git commit -m "Description of changes since last commit to master" 10 | 11 | if [ -z "`git branch | grep builds`" ]; then 12 | git co -b builds 13 | else 14 | git co builds 15 | fi 16 | 17 | git add . 18 | git commit -a -m "`date +'Build on %F at %r'`" 19 | # ignore git-commit exiting >0, since nothing to commit is fine 20 | exit 0 -------------------------------------------------------------------------------- /git-version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # Xcode auto-versioning script for git by Andre Arko 4 | # This script will set your CFBundleVersion number to the name of the most recent 5 | # git tag, and include the current commit's distance from that tag and sha1 hash 6 | 7 | # With tag "v1.0", and two commits since then, the build will be: 8 | # v1.0 (b2 h12345) 9 | 10 | # Create new tags with "git tag -m " 11 | 12 | # based on the ruby script by Abizern which was 13 | # based on the git script by Marcus S. Zarra and Matt Long which was 14 | # based on the Subversion script by Axel Andersson 15 | 16 | # Uncomment to only run when doing a Release build 17 | # if ENV["BUILD_STYLE"] != "Release" 18 | # puts "Not a Release build." 19 | # exit 20 | # end 21 | 22 | 23 | gitnum = `/usr/bin/env git describe --long`.chomp.split("-") 24 | 25 | version = gitnum[0] + " (b#{gitnum[1]} #{gitnum[2]})" 26 | 27 | info_file = File.join(ENV['BUILT_PRODUCTS_DIR'], ENV['INFOPLIST_PATH']) 28 | info = File.open(info_file, "r").read 29 | 30 | version_re = /([\t ]+CFBundleVersion<\/key>\n[\t ]+).*?(<\/string>)/ 31 | info =~ version_re 32 | bundle_version_string = $1 + version + $2 33 | 34 | info.gsub!(version_re, bundle_version_string) 35 | File.open(info_file, "w") { |file| file.write(info) } 36 | puts "Set version string to '#{version}'" 37 | --------------------------------------------------------------------------------