I have just discovered the --dirty
option to git describe
and it looks like it should do something very useful, i.e. append a suffix to the output of <
If you are running git 1.7.6 or earlier, you need to run git update-index --refresh
before using git describe --dirty
, because the index may be stale. Your workaround of using git diff --quiet HEAD
works because "git diff" is a porcelain command, and probably updates the index itself.
The git commit that fixes this for git 1.7.7 describes the problem:
When running git describe --dirty the index should be refreshed. Previously the cached index would cause describe to think that the index was dirty when, in reality, it was just stale.
Note that the exact sequence of steps you describe shouldn't have this problem, because git status
updates the index. But I still think you are seeing this same issue because the workaround you describe matches. Here is how I demonstrate the issue:
% git describe --tags --dirty
v1.0.0
% touch pom.xml
% git describe --tags --dirty
v1.0.0-dirty
% git status
# On branch dev
nothing to commit (working directory clean)
% git describe --tags --dirty
v1.0.0
Here running "git status" updates the index as a side effect and fixes "git describe" output, just as with your workaround. The proper plumbing fix for git 1.7.6 and earlier would be:
% touch pom.xml
% git describe --tags --dirty
v1.0.0-dirty
% git update-index --refresh
% git describe --tags --dirty
v1.0.0