I want to add version information to a file that is compiled into my executable. Based on here and here, I've used git describe
to update the build process to add a version number and I can detect if there are uncommitted sources.
What I want to add is an indication if the current branch is out of sync with the upstream repository. That is, it's great that the developer has committed to their local repo, but a build from sources that haven't been pushed should be marked as such.
Basically, I want the equivalent to --dirty
with respect to the remote.
Add a git fetch
and test whether git rev-parse HEAD HEAD@{upstream}
spits the same word twice:
git fetch
read mine theirs <<<`git rev-parse HEAD HEAD@{upstream}`
test $mine = $theirs || echo 'not synced'