Git Version numbering with a centralized workflow
We are using Git with a central server, and our code needs to include a version number in a file. The way this is currently done is like this:
- A new developer does a “git clone”
- In his local copy, he edits .git/hooks/pre-commit to call version.sh
version.sh (which is included in the project root) takes a version number from “git describe” and stores it in a file.
- Git Deployment: How to rollback to previous stable version of my app?
- How do you use git in “solo-development” (without team)?
- Proper workflow using git and github
- Basic version control for web development questions - Single developer. (SVN/GIT)
- How to update a production server without overwriting user files?
- Mirroring a HG project from Bitbucket to Github
While this works, I would like to make sure that the version number is updated even if a developer forgot to edit his pre-commit hook.
Since the server has no working copy, simply calling the (pre|post)-receive hooks there does not work, so I am wondering if there is a way to do this.
2 Solutions collect form web for “Git Version numbering with a centralized workflow”
How about a
hooks/update on the central repo that rejects commits without changes to the version file (named
VERSION in the example below)?
#! /bin/bash refname="$1" oldrev="$2" newrev="$3" if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then echo "Usage: $0 <ref> <oldrev> <newrev>" >&2 exit 1 fi if [ "$refname" != "refs/heads/master" ]; then exit 0 fi if diff -bq <(git show $oldrev:VERSION) \ <(git show $newrev:VERSION) >/dev/null then echo "$0: VERSION unchanged; rejecting update" >&2 exit 1 fi
The x264 project automatically generates a version number by counting git commits in the history. It migrated from svn, where versions were actually called r678, for example, but someone cooked up a script to generate numbers from git.