diff options
-rw-r--r-- | Documentation/git-branch.txt | 6 | ||||
-rw-r--r-- | builtin/branch.c | 3 | ||||
-rwxr-xr-x | t/t3201-branch-contains.sh | 35 |
3 files changed, 41 insertions, 3 deletions
diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index 2635dee41..597d64ec1 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -195,15 +195,15 @@ start-point is either a local or remote-tracking branch. --contains [<commit>]:: Only list branches which contain the specified commit (HEAD - if not specified). + if not specified). Implies `--list`. --merged [<commit>]:: Only list branches whose tips are reachable from the - specified commit (HEAD if not specified). + specified commit (HEAD if not specified). Implies `--list`. --no-merged [<commit>]:: Only list branches whose tips are not reachable from the - specified commit (HEAD if not specified). + specified commit (HEAD if not specified). Implies `--list`. <branchname>:: The name of the branch to create or delete. diff --git a/builtin/branch.c b/builtin/branch.c index 597b578e1..bd2c36b70 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -825,6 +825,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix) if (!delete && !rename && !edit_description && !new_upstream && !unset_upstream && argc == 0) list = 1; + if (with_commit || merge_filter != NO_FILTER) + list = 1; + if (!!delete + !!rename + !!force_create + !!list + !!new_upstream + !!unset_upstream > 1) usage_with_options(builtin_branch_usage, options); diff --git a/t/t3201-branch-contains.sh b/t/t3201-branch-contains.sh index f86f4bc5e..141b0611e 100755 --- a/t/t3201-branch-contains.sh +++ b/t/t3201-branch-contains.sh @@ -55,6 +55,16 @@ test_expect_success 'branch --contains=side' ' ' +test_expect_success 'branch --contains with pattern implies --list' ' + + git branch --contains=master master >actual && + { + echo " master" + } >expect && + test_cmp expect actual + +' + test_expect_success 'side: branch --merged' ' git branch --merged >actual && @@ -66,6 +76,16 @@ test_expect_success 'side: branch --merged' ' ' +test_expect_success 'branch --merged with pattern implies --list' ' + + git branch --merged=side master >actual && + { + echo " master" + } >expect && + test_cmp expect actual + +' + test_expect_success 'side: branch --no-merged' ' git branch --no-merged >actual && @@ -95,4 +115,19 @@ test_expect_success 'master: branch --no-merged' ' ' +test_expect_success 'branch --no-merged with pattern implies --list' ' + + git branch --no-merged=master master >actual && + >expect && + test_cmp expect actual + +' + +test_expect_success 'implicit --list conflicts with modification options' ' + + test_must_fail git branch --contains=master -d && + test_must_fail git branch --contains=master -m foo + +' + test_done |