Skip to content

Commit 2eda010

Browse files
peffgitster
authored andcommitted
check return value of verify_ref_format()
Users of the ref-filter code must call verify_ref_format() before formatting any refs, but most ignore its return value. This means we may print an error on a syntactically bogus pattern, but keep going anyway. In most cases this results in a fatal error when we actually try to format a ref. But if you have no refs to show at all, then the behavior is confusing: git prints the error from verify_ref_format(), then exits with code 0 without showing any output. Let's instead abort immediately if we know we have a bogus format. We'll output the usage information if we have it handy (just like the existing call in cmd_for_each_ref() does), and otherwise just die(). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80145b1 commit 2eda010

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

builtin/branch.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,9 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
409409

410410
if (!format)
411411
format = to_free = build_format(filter, maxwidth, remote_prefix);
412-
verify_ref_format(format);
412+
413+
if (verify_ref_format(format))
414+
die(_("unable to parse format string"));
413415

414416
ref_array_sort(sorting, &array);
415417

builtin/tag.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, con
5353
format = "%(refname:lstrip=2)";
5454
}
5555

56-
verify_ref_format(format);
56+
if (verify_ref_format(format))
57+
die(_("unable to parse format string"));
5758
filter->with_commit_tag_algo = 1;
5859
filter_refs(&array, filter, FILTER_REFS_TAGS);
5960
ref_array_sort(sorting, &array);
@@ -501,8 +502,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
501502
if (cmdmode == 'd')
502503
return for_each_tag_name(argv, delete_tag, NULL);
503504
if (cmdmode == 'v') {
504-
if (format)
505-
verify_ref_format(format);
505+
if (format && verify_ref_format(format))
506+
usage_with_options(git_tag_usage, options);
506507
return for_each_tag_name(argv, verify_tag, format);
507508
}
508509

builtin/verify-tag.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
5151
flags |= GPG_VERIFY_VERBOSE;
5252

5353
if (fmt_pretty) {
54-
verify_ref_format(fmt_pretty);
54+
if (verify_ref_format(fmt_pretty))
55+
usage_with_options(verify_tag_usage,
56+
verify_tag_options);
5557
flags |= GPG_VERIFY_OMIT_STATUS;
5658
}
5759

0 commit comments

Comments
 (0)