Skip to content

Commit d6966f6

Browse files
committed
Merge branch 'jc/parse-options-show-branch'
Command line parser fixes. * jc/parse-options-show-branch: show-branch: reject --[no-](topo|date)-order show-branch: --no-sparse should give dense output
2 parents 9562f19 + 68cbb20 commit d6966f6

File tree

2 files changed

+36
-11
lines changed

2 files changed

+36
-11
lines changed

builtin/show-branch.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
649649
int with_current_branch = 0;
650650
int head_at = -1;
651651
int topics = 0;
652-
int dense = 1;
652+
int sparse = 0;
653653
const char *reflog_base = NULL;
654654
struct option builtin_show_branch_options[] = {
655655
OPT_BOOL('a', "all", &all_heads,
@@ -671,17 +671,17 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
671671
N_("show possible merge bases")),
672672
OPT_BOOL(0, "independent", &independent,
673673
N_("show refs unreachable from any other ref")),
674-
OPT_SET_INT(0, "topo-order", &sort_order,
675-
N_("show commits in topological order"),
676-
REV_SORT_IN_GRAPH_ORDER),
674+
OPT_SET_INT_F(0, "topo-order", &sort_order,
675+
N_("show commits in topological order"),
676+
REV_SORT_IN_GRAPH_ORDER, PARSE_OPT_NONEG),
677677
OPT_BOOL(0, "topics", &topics,
678678
N_("show only commits not on the first branch")),
679-
OPT_SET_INT(0, "sparse", &dense,
680-
N_("show merges reachable from only one tip"), 0),
681-
OPT_SET_INT(0, "date-order", &sort_order,
682-
N_("topologically sort, maintaining date order "
683-
"where possible"),
684-
REV_SORT_BY_COMMIT_DATE),
679+
OPT_SET_INT(0, "sparse", &sparse,
680+
N_("show merges reachable from only one tip"), 1),
681+
OPT_SET_INT_F(0, "date-order", &sort_order,
682+
N_("topologically sort, maintaining date order "
683+
"where possible"),
684+
REV_SORT_BY_COMMIT_DATE, PARSE_OPT_NONEG),
685685
OPT_CALLBACK_F('g', "reflog", &reflog_base, N_("<n>[,<base>]"),
686686
N_("show <n> most recent ref-log entries starting at "
687687
"base"),
@@ -940,7 +940,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
940940
!is_merge_point &&
941941
(this_flag & (1u << REV_SHIFT)))
942942
continue;
943-
if (dense && is_merge &&
943+
if (!sparse && is_merge &&
944944
omit_in_dense(commit, rev, num_rev))
945945
continue;
946946
for (i = 0; i < num_rev; i++) {

t/t3202-show-branch.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ test_expect_success 'show branch --remotes' '
119119
test_must_be_empty actual.out
120120
'
121121

122+
test_expect_success 'show-branch --sparse' '
123+
test_when_finished "git checkout branch10 && git branch -D branchA" &&
124+
git checkout -b branchA branch10 &&
125+
git merge -s ours -m "merge 1 and 10 to make A" branch1 &&
126+
git commit --allow-empty -m "another" &&
127+
128+
git show-branch --sparse >out &&
129+
grep "merge 1 and 10 to make A" out &&
130+
131+
git show-branch >out &&
132+
! grep "merge 1 and 10 to make A" out &&
133+
134+
git show-branch --no-sparse >out &&
135+
! grep "merge 1 and 10 to make A" out
136+
'
137+
122138
test_expect_success 'setup show branch --list' '
123139
sed "s/^> //" >expect <<-\EOF
124140
> [branch1] branch1
@@ -197,6 +213,15 @@ done <<\EOF
197213
--reflog --current
198214
EOF
199215

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+
200225
test_expect_success 'error descriptions on non-existent branch' '
201226
cat >expect <<-EOF &&
202227
error: No branch named '\''non-existent'\'.'

0 commit comments

Comments
 (0)