Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mccaffers/df35b47e3910279c0f0c7c2bb261c914 to your computer and use it in GitHub Desktop.

Select an option

Save mccaffers/df35b47e3910279c0f0c7c2bb261c914 to your computer and use it in GitHub Desktop.
This script updates an iOS app's Info.plist file with the current Git commit hash, creating the GitCommitHashApp key if it doesn't already exist. Useful for reference the git hash inside the Swift application.
INFO_PLIST="${TARGET_BUILD_DIR}"/"${INFOPLIST_PATH}"
# Get the GIT hashes
searchOpsApp=$(git rev-parse --short HEAD)
# Query and save the value; suppress any error message, if key not found.
valueApp=$(/usr/libexec/PlistBuddy -c 'print :GitCommitHashApp' "${INFO_PLIST}" 2>/dev/null)
# Check if value is empty
if [ -z "$valueApp" ]
then
/usr/libexec/PlistBuddy -c "Add :GitCommitHashApp string" "${INFO_PLIST}"
fi
/usr/libexec/PlistBuddy -c "Set :GitCommitHashApp `echo $searchOpsApp`" "${INFO_PLIST}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment