Skip to content

Commit b227482

Browse files
committed
Merge branch 'as/describe-broken-refresh-index-fix'
"git describe --dirty --broken" forgot to refresh the index before seeing if there is any chang, ("git describe --dirty" correctly did so), which has been corrected. * as/describe-broken-refresh-index-fix: describe: refresh the index when 'broken' flag is used
2 parents d8b9b1f + b8ae42e commit b227482

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

builtin/describe.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ static const char *diff_index_args[] = {
5353
"diff-index", "--quiet", "HEAD", "--", NULL
5454
};
5555

56+
static const char *update_index_args[] = {
57+
"update-index", "--unmerged", "-q", "--refresh", NULL
58+
};
59+
5660
struct commit_name {
5761
struct hashmap_entry entry;
5862
struct object_id peeled;
@@ -645,6 +649,14 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
645649
if (argc == 0) {
646650
if (broken) {
647651
struct child_process cp = CHILD_PROCESS_INIT;
652+
653+
strvec_pushv(&cp.args, update_index_args);
654+
cp.git_cmd = 1;
655+
cp.no_stdin = 1;
656+
cp.no_stdout = 1;
657+
run_command(&cp);
658+
659+
child_process_init(&cp);
648660
strvec_pushv(&cp.args, diff_index_args);
649661
cp.git_cmd = 1;
650662
cp.no_stdin = 1;

t/t6120-describe.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,40 @@ test_expect_success 'setup misleading taggerdates' '
671671

672672
check_describe newer-tag-older-commit~1 --contains unique-file~2
673673

674+
test_expect_success 'describe --dirty with a file with changed stat' '
675+
test_when_finished "rm -fr stat-dirty" &&
676+
git init stat-dirty &&
677+
(
678+
cd stat-dirty &&
679+
680+
echo A >file &&
681+
git add file &&
682+
git commit -m A &&
683+
git tag A -a -m A &&
684+
echo "A" >expect &&
685+
686+
test-tool chmtime -10 file &&
687+
git describe --dirty >actual &&
688+
test_cmp expect actual
689+
)
690+
'
691+
692+
test_expect_success 'describe --broken --dirty with a file with changed stat' '
693+
test_when_finished "rm -fr stat-dirty" &&
694+
git init stat-dirty &&
695+
(
696+
cd stat-dirty &&
697+
698+
echo A >file &&
699+
git add file &&
700+
git commit -m A &&
701+
git tag A -a -m A &&
702+
echo "A" >expect &&
703+
704+
test-tool chmtime -10 file &&
705+
git describe --dirty --broken >actual &&
706+
test_cmp expect actual
707+
)
708+
'
709+
674710
test_done

0 commit comments

Comments
 (0)