Skip to content

Commit 85b3c75

Browse files
allancaffeegitster
authored andcommitted
describe: Refresh the index when run with --dirty
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. The issue was exposed by python setuptools which hardlinks files into another directory when building a distribution. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 84b0514 commit 85b3c75

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

builtin/describe.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,21 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
462462
die(_("No names found, cannot describe anything."));
463463

464464
if (argc == 0) {
465-
if (dirty && !cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1, diff_index_args, prefix))
466-
dirty = NULL;
465+
if (dirty) {
466+
static struct lock_file index_lock;
467+
int fd;
468+
469+
read_cache_preload(NULL);
470+
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED,
471+
NULL, NULL, NULL);
472+
fd = hold_locked_index(&index_lock, 0);
473+
if (0 <= fd)
474+
update_index_if_able(&the_index, &index_lock);
475+
476+
if (!cmd_diff_index(ARRAY_SIZE(diff_index_args) - 1,
477+
diff_index_args, prefix))
478+
dirty = NULL;
479+
}
467480
describe("HEAD", 1);
468481
} else if (dirty) {
469482
die(_("--dirty is incompatible with committishes"));

0 commit comments

Comments
 (0)