Created
April 22, 2011 09:14
-
-
Save peritus/936326 to your computer and use it in GitHub Desktop.
git-describe doesn't update the index, so the dirty flag is not accurate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# BOTTOM LINE: | |
# | |
# You have to call `git update-index --refresh` before calling | |
# `git describe` or the dirty flag might be inaccurate. | |
# Discussion: | |
# https://twitter.com/peritus/status/61361229876314112 | |
# https://twitter.com/artagnon/status/61471028567752704 | |
# https://twitter.com/peritus/status/61472057115942912 | |
# https://twitter.com/artagnon/status/61483605901312000 | |
# https://twitter.com/artagnon/status/61484006314745856 | |
# Original problem: | |
# | |
# git-diff-index fails to detect that a file didn't change when only the file's | |
# ctime changed (e.g. chmod does that) | |
# | |
# This leads to git-describe declaring dirty workspaces where there are none. | |
# | |
# Couldn't reproduce this on Mac OS X, but on Ubuntu Maverick with ext3 fs | |
# | |
# Test case: | |
echo Preparing .. | |
git --version | |
git init change-time-test | |
cd change-time-test | |
echo File system used: | |
stat -f --format=%T . | |
touch file | |
# we'll use the same command later | |
# (so chmod doesn't change the permissions but only the ctime) | |
chmod 755 file | |
git add file | |
git commit -m test | |
git tag v1 | |
echo === The following should be empty because file did not change | |
git diff-index HEAD -- | |
echo === | |
echo | |
echo "git describe --tags --dirty (should be 'v1')" | |
git describe --tags --dirty | |
echo | |
echo ctime of file: | |
stat file | grep Change | |
echo | |
sleep 1 | |
chmod 755 file | |
echo ctime of file: | |
stat file | grep Change | |
echo === The following should be empty because file did not change | |
git diff-index HEAD -- | |
echo === | |
echo | |
echo "git describe --tags --dirty (should be 'v1')" | |
git describe --tags --dirty | |
echo | |
echo "git status (or some plumbing) clears this up" | |
git status | |
echo === The following should be empty because file did not change | |
git diff-index HEAD -- | |
echo === | |
echo | |
echo "git describe --tags --dirty (should be 'v1')" | |
git describe --tags --dirty | |
echo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vagrantup:~$ ./test.sh | |
Preparing .. | |
git version 1.7.4.5 | |
Initialized empty Git repository in /home/vagrant/change-time-test/.git/ | |
File system used: | |
ext2/ext3 | |
[master (root-commit) bdd92ac] test | |
Committer: vagrant <[email protected]> | |
Your name and email address were configured automatically based | |
on your username and hostname. Please check that they are accurate. | |
You can suppress this message by setting them explicitly: | |
git config --global user.name "Your Name" | |
git config --global user.email [email protected] | |
After doing this, you may fix the identity used for this commit with: | |
git commit --amend --reset-author | |
0 files changed, 0 insertions(+), 0 deletions(-) | |
create mode 100755 file | |
=== The following should be empty because file did not change | |
=== | |
git describe --tags --dirty (should be 'v1') | |
v1 | |
ctime of file: | |
Change: 2011-04-22 02:21:00.743091137 -0700 | |
ctime of file: | |
Change: 2011-04-22 02:21:01.754745281 -0700 | |
=== The following should be empty because file did not change | |
:100755 100755 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M file | |
=== | |
git describe --tags --dirty (should be 'v1') | |
v1-dirty | |
git status (or some plumbing) clears this up | |
# On branch master | |
nothing to commit (working directory clean) | |
=== The following should be empty because file did not change | |
=== | |
git describe --tags --dirty (should be 'v1') | |
v1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This behavior has been fixed in git 1.7.7. The fix: git/git@bb571486 And see stackoverflow discussion: http://stackoverflow.com/questions/16035240/why-is-git-describe-dirty-adding-a-dirty-suffix-when-describing-a-clean-ch