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 <gitster@pobox.com>

Allan Caffee committed Jul 31, 2011 at 21:52 UTC 85b3c75f4fd3aa4da976bac702827dc8d7d1bf15
1 file changed +15 -2
builtin/describe.c
+15 -2
@@ -462,8 +462,21 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
462 die(_("No names found, cannot describe anything."));
463
464 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 + }
480 describe("HEAD", 1);
481 } else if (dirty) {
482 die(_("--dirty is incompatible with committishes"));