Matheus Tavares <matheus.bernardino@xxxxxx> writes: >> > Another case that came to my mind is when the user runs `git describe >> > --abrev=0 HEAD` and v1.0-bob points to HEAD~. In this case, v1.0 will >> > be displayed without suffix,... >> >> In this case, v1.0-1- is followed by the full object name, I think. > > I might be doing something wrong, but this is how I tried to test this:... I only tried the commit exactly at the tag "describe --abbrev=0 v1.0-bob^0"; you're right---the "abbrev" option strips the suffix in a separate codepath. > Then we cannot directly use the output. I think we can fix this forcing the long > output for this case as well, which can be done with: Thanks for a quick fix on top. builtin/describe.c | 2 +- t/t6120-describe.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/builtin/describe.c b/builtin/describe.c index 5e8484f654..f71bddff4a 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -452,7 +452,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst) } append_name(all_matches[0].name, dst); - if (abbrev) + if (all_matches[0].name->misnamed || abbrev) append_suffix(all_matches[0].depth, &cmit->object.oid, dst); if (suffix) strbuf_addstr(dst, suffix); diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 16a261c45d..8f35f18c3f 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -144,6 +144,18 @@ test_expect_success 'misnamed annotated tag forces long output' ' test_cmp expect actual ' +test_expect_success 'abbrev=0 will not break misplaced tag (1)' ' + description=$(git describe --abbrev=0 Q^0) && + expr "$description" : "A-0-g[0-9a-f]*$" +' + +test_expect_success 'abbrev=0 will not break misplaced tag (2)' ' + description=$(git describe --abbrev=0 c^0) && + expr "$description" : "A-1-g[0-9a-f]*$" +' + +exit + test_expect_success 'rename tag Q back to A' ' mv .git/refs/tags/Q .git/refs/tags/A '