Skip to content

Instantly share code, notes, and snippets.

@peritus
Created April 22, 2011 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peritus/936326 to your computer and use it in GitHub Desktop.
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
#!/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
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 <vagrant@vagrantup.com>
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 you@example.com
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
@jbyler
Copy link

jbyler commented Jul 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment