Skip to content

Instantly share code, notes, and snippets.

@timd
Created August 28, 2012 14:24
Show Gist options
  • Save timd/3498466 to your computer and use it in GitHub Desktop.
Save timd/3498466 to your computer and use it in GitHub Desktop.
Provide build number for source code
# build data file that is included in the source
# so we can automatically report Git repo information
# in the application.
cd ${PROJECT_DIR}
gitDataFile="gitDataAutoGenerated.h"
buildDate=`date "+%F %H:%M:%S"`
currentBranch=`git rev-parse --abbrev-ref HEAD`
lastCommitHash=`git log --pretty=format:"%h" -1`
lastCommitDate=`git log --pretty=format:"%ad" --date=short -1`
lastCommitComment=`git log --pretty=format:"%s" -1`
lastRepoTag=`git describe --abbrev=0 --tags`
echo -e "//-----------------------------------------" > $gitDataFile
echo -e "// Auto generated file" >> $gitDataFile
echo -e "// Created $buildDate" >> $gitDataFile
echo -e "//-----------------------------------------" >> $gitDataFile
echo -e "" >> $gitDataFile
echo -e "#define BUILD_DATE @\"$buildDate\"" >> $gitDataFile
echo -e "#define GIT_CURRENT_BRANCH @\"$currentBranch\"" >> $gitDataFile
echo -e "#define GIT_LAST_COMMIT_HASH @\"$lastCommitHash\"" >> $gitDataFile
echo -e "#define GIT_LAST_COMMIT_DATE @\"$lastCommitDate\"" >> $gitDataFile
echo -e "#define GIT_LAST_COMMIT_COMMENT @\"$lastCommitComment\"" >> $gitDataFile
echo -e "#define GIT_LAST_REPO_TAG @\"$lastRepoTag\"" >> $gitDataFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment