Skip to content

Commit 68cbb20

Browse files
committed
show-branch: reject --[no-](topo|date)-order
"git show-branch --no-topo-order" behaved exactly the same way as "git show-branch --topo-order" did, which was nonsense. This was because we choose between topo- and date- by setting a variable to either REV_SORT_IN_GRAPH_ORDER or REV_SORT_BY_COMMIT_DATE with OPT_SET_INT() and REV_SORT_IN_GRAPH_ORDER happens to be 0. The OPT_SET_INT() macro assigns 0 to the target variable in respose to the negated form of its option. "--no-date-order" by luck behaves identically to "--topo-order" exactly for the same reason, and it sort-of makes sense right now, but the "sort-of makes sense" will quickly break down once we add a third way to sort. Not-A may be B when there are only two choices between A and B, but once your choices become among A, B, and C, not-A does not mean B. Just mark these two ordering options to reject negation, and add a test, which was missing. "git show-branch --no-reflog" is also unnegatable, so throw in a test for that while we are at it. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 83bb8e5 commit 68cbb20

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

builtin/show-branch.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,17 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
667667
N_("show possible merge bases")),
668668
OPT_BOOL(0, "independent", &independent,
669669
N_("show refs unreachable from any other ref")),
670-
OPT_SET_INT(0, "topo-order", &sort_order,
671-
N_("show commits in topological order"),
672-
REV_SORT_IN_GRAPH_ORDER),
670+
OPT_SET_INT_F(0, "topo-order", &sort_order,
671+
N_("show commits in topological order"),
672+
REV_SORT_IN_GRAPH_ORDER, PARSE_OPT_NONEG),
673673
OPT_BOOL(0, "topics", &topics,
674674
N_("show only commits not on the first branch")),
675675
OPT_SET_INT(0, "sparse", &sparse,
676676
N_("show merges reachable from only one tip"), 1),
677-
OPT_SET_INT(0, "date-order", &sort_order,
678-
N_("topologically sort, maintaining date order "
679-
"where possible"),
680-
REV_SORT_BY_COMMIT_DATE),
677+
OPT_SET_INT_F(0, "date-order", &sort_order,
678+
N_("topologically sort, maintaining date order "
679+
"where possible"),
680+
REV_SORT_BY_COMMIT_DATE, PARSE_OPT_NONEG),
681681
OPT_CALLBACK_F('g', "reflog", &reflog_base, N_("<n>[,<base>]"),
682682
N_("show <n> most recent ref-log entries starting at "
683683
"base"),

t/t3202-show-branch.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ done <<\EOF
213213
--reflog --current
214214
EOF
215215

216+
# unnegatable options
217+
for opt in topo-order date-order reflog
218+
do
219+
test_expect_success "show-branch --no-$opt (should fail)" '
220+
test_must_fail git show-branch --no-$opt 2>err &&
221+
grep "unknown option .no-$opt." err
222+
'
223+
done
224+
216225
test_expect_success 'error descriptions on non-existent branch' '
217226
cat >expect <<-EOF &&
218227
error: No branch named '\''non-existent'\'.'

0 commit comments

Comments
 (0)