Skip to content

Instantly share code, notes, and snippets.

@johnhaitas
Created July 10, 2013 16:33
Show Gist options
  • Save johnhaitas/5967857 to your computer and use it in GitHub Desktop.
Save johnhaitas/5967857 to your computer and use it in GitHub Desktop.
#!/bin/sh
# insert_git_hash.sh
# ToGoOrder
#
# Created by John Haitas on 7/9/13.
#
# Location of Info.plist in build product
INFOPLISTPATH="${TARGET_BUILD_DIR}/${EXECUTABLE_NAME}.app/Info.plist"
# Location of PlistBuddy
PLISTBUDDY="/usr/libexec/PlistBuddy"
# Get the hash for the current commit
COMMIT_HASH=$(git rev-parse --short HEAD)
# Test if this commit is dirty
if [[ -n $(git status -s ${SUBMODULE_SYNTAX} 2> /dev/null) ]]; then
COMMIT_HASH="${COMMIT_HASH}~dirty"
fi
# The PLIST key
GITHASH_PLIST_KEY="GitHash"
# Should test if key already exist and add it if it does not or set it if it does
# no point in taking the time to do it for now
# Add the key
echo "Adding key";
ADD_KEY_RESULT=$(${PLISTBUDDY} -c "Add :${GITHASH_PLIST_KEY} string ${COMMIT_HASH}" "${INFOPLISTPATH}")
# Set the key to be sure
echo "Setting key";
${PLISTBUDDY} -c "Set :${GITHASH_PLIST_KEY} ${COMMIT_HASH}" "${INFOPLISTPATH}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment