Skip to content

Commit 4d23660

Browse files
trastgitster
authored andcommitted
describe: when failing, tell the user about options that work
Users seem to call git-describe without reading the manpage, and then wonder why it doesn't work with unannotated tags by default. Make a minimal effort towards seeing if there would have been unannotated tags, and tell the user. Specifically, we say that --tags could work if we found any unannotated tags. If not, we say that --always would have given results. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent cd0f8e6 commit 4d23660

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

builtin-describe.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
9696
if (!all) {
9797
if (!prio)
9898
return 0;
99-
if (!tags && prio < 2)
100-
return 0;
10199
}
102100
add_to_known_names(all ? path + 5 : path + 10, commit, prio, sha1);
103101
return 0;
@@ -184,6 +182,7 @@ static void describe(const char *arg, int last_one)
184182
struct possible_tag all_matches[MAX_TAGS];
185183
unsigned int match_cnt = 0, annotated_cnt = 0, cur_match;
186184
unsigned long seen_commits = 0;
185+
unsigned int unannotated_cnt = 0;
187186

188187
if (get_sha1(arg, sha1))
189188
die("Not a valid object name %s", arg);
@@ -217,7 +216,9 @@ static void describe(const char *arg, int last_one)
217216
seen_commits++;
218217
n = c->util;
219218
if (n) {
220-
if (match_cnt < max_candidates) {
219+
if (!tags && !all && n->prio < 2) {
220+
unannotated_cnt++;
221+
} else if (match_cnt < max_candidates) {
221222
struct possible_tag *t = &all_matches[match_cnt++];
222223
t->name = n;
223224
t->depth = seen_commits - 1;
@@ -259,7 +260,14 @@ static void describe(const char *arg, int last_one)
259260
printf("%s\n", find_unique_abbrev(sha1, abbrev));
260261
return;
261262
}
262-
die("cannot describe '%s'", sha1_to_hex(sha1));
263+
if (unannotated_cnt)
264+
die("No annotated tags can describe '%s'.\n"
265+
"However, there were unannotated tags: try --tags.",
266+
sha1_to_hex(sha1));
267+
else
268+
die("No tags can describe '%s'.\n"
269+
"Try --always, or create some tags.",
270+
sha1_to_hex(sha1));
263271
}
264272

265273
qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);

0 commit comments

Comments
 (0)