Skip to content

Instantly share code, notes, and snippets.

@johnhaitas
Created July 10, 2013 16:28
Show Gist options
  • Save johnhaitas/5967801 to your computer and use it in GitHub Desktop.
Save johnhaitas/5967801 to your computer and use it in GitHub Desktop.
cleaned up the script to insert git hash into Info.plist
#!/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"
COMMIT_HASH=`git rev-parse --short HEAD`
if [[ -n $(git status -s ${SUBMODULE_SYNTAX} 2> /dev/null) ]]; then
COMMIT_HASH="${COMMIT_HASH}~dirty"
fi
# 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
GITHASH_PLIST_KEY="GitHash"
# 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