Skip to content

Commit

Permalink
Merge branch 'jc/branch-parseopt-fix'
Browse files Browse the repository at this point in the history
Command line parser fixes.

* jc/branch-parseopt-fix:
  branch: reject "--no-all" and "--no-remotes" early
  • Loading branch information
gitster committed Jul 26, 2023
2 parents 914a353 + e12cb98 commit 9a5e3b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,17 +720,19 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
OPT_STRING('u', "set-upstream-to", &new_upstream, N_("upstream"), N_("change the upstream info")),
OPT_BOOL(0, "unset-upstream", &unset_upstream, N_("unset the upstream info")),
OPT__COLOR(&branch_use_color, N_("use colored output")),
OPT_SET_INT('r', "remotes", &filter.kind, N_("act on remote-tracking branches"),
FILTER_REFS_REMOTES),
OPT_SET_INT_F('r', "remotes", &filter.kind, N_("act on remote-tracking branches"),
FILTER_REFS_REMOTES,
PARSE_OPT_NONEG),
OPT_CONTAINS(&filter.with_commit, N_("print only branches that contain the commit")),
OPT_NO_CONTAINS(&filter.no_commit, N_("print only branches that don't contain the commit")),
OPT_WITH(&filter.with_commit, N_("print only branches that contain the commit")),
OPT_WITHOUT(&filter.no_commit, N_("print only branches that don't contain the commit")),
OPT__ABBREV(&filter.abbrev),

OPT_GROUP(N_("Specific git-branch actions:")),
OPT_SET_INT('a', "all", &filter.kind, N_("list both remote-tracking and local branches"),
FILTER_REFS_REMOTES | FILTER_REFS_BRANCHES),
OPT_SET_INT_F('a', "all", &filter.kind, N_("list both remote-tracking and local branches"),
FILTER_REFS_REMOTES | FILTER_REFS_BRANCHES,
PARSE_OPT_NONEG),
OPT_BIT('d', "delete", &delete, N_("delete fully merged branch"), 1),
OPT_BIT('D', NULL, &delete, N_("delete branch (even if not merged)"), 2),
OPT_BIT('m', "move", &rename, N_("move/rename a branch and its reflog"), 1),
Expand Down
16 changes: 16 additions & 0 deletions t/t3203-branch-output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,17 @@ cat >expect <<'EOF'
EOF
test_expect_success 'git branch -r shows remote branches' '
git branch -r >actual &&
test_cmp expect actual &&
git branch --remotes >actual &&
test_cmp expect actual
'

test_expect_success 'git branch --no-remotes is rejected' '
test_must_fail git branch --no-remotes 2>err &&
grep "unknown option .no-remotes." err
'

cat >expect <<'EOF'
branch-one
branch-two
Expand All @@ -68,9 +76,17 @@ cat >expect <<'EOF'
EOF
test_expect_success 'git branch -a shows local and remote branches' '
git branch -a >actual &&
test_cmp expect actual &&
git branch --all >actual &&
test_cmp expect actual
'

test_expect_success 'git branch --no-all is rejected' '
test_must_fail git branch --no-all 2>err &&
grep "unknown option .no-all." err
'

cat >expect <<'EOF'
two
one
Expand Down

0 comments on commit 9a5e3b5

Please sign in to comment.