Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-07-28 01:26:37 +0300
committerJunio C Hamano <gitster@pobox.com>2023-07-28 01:26:37 +0300
commitd6966f6fffc69e38dc78f3b2b199e4c8def69b3e (patch)
treec202966598876de8f6b983d1c197beb013fb636d
parent9562f19026f1dcdfcfda86c2c9b7cff21c8b0642 (diff)
parent68cbb20e737218bcd067bb5b5be658378095d0ed (diff)
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
-rw-r--r--builtin/show-branch.c22
-rwxr-xr-xt/t3202-show-branch.sh25
2 files changed, 36 insertions, 11 deletions
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index a86b3c7677..b01ec761d2 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -649,7 +649,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
int with_current_branch = 0;
int head_at = -1;
int topics = 0;
- int dense = 1;
+ int sparse = 0;
const char *reflog_base = NULL;
struct option builtin_show_branch_options[] = {
OPT_BOOL('a', "all", &all_heads,
@@ -671,17 +671,17 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
N_("show possible merge bases")),
OPT_BOOL(0, "independent", &independent,
N_("show refs unreachable from any other ref")),
- OPT_SET_INT(0, "topo-order", &sort_order,
- N_("show commits in topological order"),
- REV_SORT_IN_GRAPH_ORDER),
+ OPT_SET_INT_F(0, "topo-order", &sort_order,
+ N_("show commits in topological order"),
+ REV_SORT_IN_GRAPH_ORDER, PARSE_OPT_NONEG),
OPT_BOOL(0, "topics", &topics,
N_("show only commits not on the first branch")),
- OPT_SET_INT(0, "sparse", &dense,
- N_("show merges reachable from only one tip"), 0),
- OPT_SET_INT(0, "date-order", &sort_order,
- N_("topologically sort, maintaining date order "
- "where possible"),
- REV_SORT_BY_COMMIT_DATE),
+ OPT_SET_INT(0, "sparse", &sparse,
+ N_("show merges reachable from only one tip"), 1),
+ OPT_SET_INT_F(0, "date-order", &sort_order,
+ N_("topologically sort, maintaining date order "
+ "where possible"),
+ REV_SORT_BY_COMMIT_DATE, PARSE_OPT_NONEG),
OPT_CALLBACK_F('g', "reflog", &reflog_base, N_("<n>[,<base>]"),
N_("show <n> most recent ref-log entries starting at "
"base"),
@@ -940,7 +940,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
!is_merge_point &&
(this_flag & (1u << REV_SHIFT)))
continue;
- if (dense && is_merge &&
+ if (!sparse && is_merge &&
omit_in_dense(commit, rev, num_rev))
continue;
for (i = 0; i < num_rev; i++) {
diff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh
index be20ebe1d5..b17f388f56 100755
--- a/t/t3202-show-branch.sh
+++ b/t/t3202-show-branch.sh
@@ -119,6 +119,22 @@ test_expect_success 'show branch --remotes' '
test_must_be_empty actual.out
'
+test_expect_success 'show-branch --sparse' '
+ test_when_finished "git checkout branch10 && git branch -D branchA" &&
+ git checkout -b branchA branch10 &&
+ git merge -s ours -m "merge 1 and 10 to make A" branch1 &&
+ git commit --allow-empty -m "another" &&
+
+ git show-branch --sparse >out &&
+ grep "merge 1 and 10 to make A" out &&
+
+ git show-branch >out &&
+ ! grep "merge 1 and 10 to make A" out &&
+
+ git show-branch --no-sparse >out &&
+ ! grep "merge 1 and 10 to make A" out
+'
+
test_expect_success 'setup show branch --list' '
sed "s/^> //" >expect <<-\EOF
> [branch1] branch1
@@ -197,6 +213,15 @@ done <<\EOF
--reflog --current
EOF
+# unnegatable options
+for opt in topo-order date-order reflog
+do
+ test_expect_success "show-branch --no-$opt (should fail)" '
+ test_must_fail git show-branch --no-$opt 2>err &&
+ grep "unknown option .no-$opt." err
+ '
+done
+
test_expect_success 'error descriptions on non-existent branch' '
cat >expect <<-EOF &&
error: No branch named '\''non-existent'\'.'