{"thread":{"id":"32781","subject":"[BUG] `git branch --contains ID name` creates branch \"name\"","startedAt":"2013-01-30T18:57:03Z","lastAt":"2013-02-01T05:42:20Z","messageCount":11,"participants":["Peter Wu","Jeff King","Junio C Hamano","Eric Sunshine"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"208300","messageId":"679787987.uZRbjA7AMj@al","threadId":"32781","inReplyTo":null,"subject":"[BUG] `git branch --contains ID name` creates branch \"name\"","fromName":"Peter Wu","fromEmail":"lekensteyn@gmail.com","sentAt":"2013-01-30T18:57:03Z","receivedAt":"2013-01-30T18:57:03Z","isPatch":false,"sender":{"key":"lekensteyn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164530?v=4"},"body":"Hi,\n\nI was trying to check whether a certain branch contained a commit and ran:\n\n     git branch --contains ddc150f7a33ae0c9cb16eaac3641abc00f56316f master\n\nThis resulted in:\n\n    fatal: A branch named 'master' already exists.\nWhen \"name\" does not exist, this command creates a branch. I expect this \ncommand to search the mentioned branch, not trying to create it. The manual \npage of git-branch(1) does not mention such special behavior either.\n\nGit version 1.8.1.2\n\nRegards,\nPeter\n"},{"id":"208338","messageId":"20130131064357.GA24660@sigill.intra.peff.net","threadId":"32781","inReplyTo":"679787987.uZRbjA7AMj@al","subject":"[PATCH 0/2] improve \"git branch --contains=<commit> <pattern>\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-01-31T06:43:57Z","receivedAt":"2013-01-31T06:43:57Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jan 30, 2013 at 07:57:03PM +0100, Peter Wu wrote:\n\n> Hi,\n> \n> I was trying to check whether a certain branch contained a commit and ran:\n> \n>      git branch --contains ddc150f7a33ae0c9cb16eaac3641abc00f56316f master\n> \n> This resulted in:\n> \n>     fatal: A branch named 'master' already exists.\n> When \"name\" does not exist, this command creates a branch. I expect this \n> command to search the mentioned branch, not trying to create it. The manual \n> page of git-branch(1) does not mention such special behavior either.\n\nYeah, it's sort-of a bug. It is a syntactic ambiguity that an argument\nto git-branch could be a listing pattern or a new branch name. When\nusing a listing pattern, you need to explicitly specify that you want\nlist mode with `--list`. This is documented in git-branch under --list,\nbut it should be more prominent, in the section that covers the various\ninvocation modes. The first patch below fixes that.\n\nThat being said, we could be much more helpful. It seems like --contains\nshould imply listing mode, since it is nonsensical in other modes. The\nsecond patch below adjusts that, and makes the command above do what you\nexpect.\n\n  [1/2]: docs: clarify git-branch --list behavior\n  [2/2]: branch: let branch filters imply --list\n\n-Peff\n"},{"id":"208339","messageId":"20130131064545.GA25315@sigill.intra.peff.net","threadId":"32781","inReplyTo":"20130131064357.GA24660@sigill.intra.peff.net","subject":"[PATCH 1/2] docs: clarify git-branch --list behavior","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-01-31T06:45:46Z","receivedAt":"2013-01-31T06:45:46Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"It was not clear from the \"description\" section of\ngit-branch(1) that using a <pattern> meant that you _had_ to\nuse the --list option. Let's clarify that, and while we're\nat it, reword some clunky and ambiguous sentences.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Documentation/git-branch.txt | 16 +++++++++-------\n 1 file changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 45a225e..01aa87f 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -22,13 +22,15 @@ DESCRIPTION\n DESCRIPTION\n -----------\n \n-With no arguments, existing branches are listed and the current branch will\n-be highlighted with an asterisk.  Option `-r` causes the remote-tracking\n-branches to be listed, and option `-a` shows both. This list mode is also\n-activated by the `--list` option (see below).\n-<pattern> restricts the output to matching branches, the pattern is a shell\n-wildcard (i.e., matched using fnmatch(3)).\n-Multiple patterns may be given; if any of them matches, the branch is shown.\n+If `--list` is given, or if there are no non-option arguments, existing\n+branches are listed; the current branch will be highlighted with an\n+asterisk.  Option `-r` causes the remote-tracking branches to be listed,\n+and option `-a` shows both local and remote branches. If a `<pattern>`\n+is given, it is used as a shell wildcard to restrict the output to\n+matching branches. If multiple patterns are given, a branch is shown if\n+any it is matched by any of the patterns.  Note that when providing a\n+`<pattern>`, you must use `--list`; otherwise the command is interpreted\n+as branch creation.\n \n With `--contains`, shows only the branches that contain the named commit\n (in other words, the branches whose tip commits are descendants of the\n-- \n1.8.1.2.5.g1cb3f73\n"},{"id":"208340","messageId":"20130131064611.GB25315@sigill.intra.peff.net","threadId":"32781","inReplyTo":"20130131064357.GA24660@sigill.intra.peff.net","subject":"[PATCH 2/2] branch: let branch filters imply --list","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-01-31T06:46:11Z","receivedAt":"2013-01-31T06:46:11Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Currently, a branch filter like `--contains`, `--merged`, or\n`--no-merged` is ignored when we are not in listing mode.\nFor example:\n\n  git branch --contains=foo bar\n\nwill create the branch \"bar\" from the current HEAD, ignoring\nthe `--contains` argument entirely. This is not very\nhelpful. There are two reasonable behaviors for git here:\n\n  1. Flag an error; the arguments do not make sense.\n\n  2. Implicitly go into `--list` mode\n\nThis patch chooses the latter, as it is more convenient, and\nthere should not be any ambiguity with attempting to create\na branch; using `--contains` and not wanting to list is\nnonsensical.\n\nThat leaves the case where an explicit modification option\nlike `-d` is given.  We already catch the case where\n`--list` is given alongside `-d` and flag an error. With\nthis patch, we will also catch the use of `--contains` and\nother filter options alongside `-d`.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Documentation/git-branch.txt |  6 +++---\n builtin/branch.c             |  3 +++\n t/t3201-branch-contains.sh   | 35 +++++++++++++++++++++++++++++++++++\n 3 files changed, 41 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 01aa87f..07ef5af 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -195,15 +195,15 @@ start-point is either a local or remote-tracking branch.\n \n --contains [<commit>]::\n \tOnly list branches which contain the specified commit (HEAD\n-\tif not specified).\n+\tif not specified). Implies `--list`.\n \n --merged [<commit>]::\n \tOnly list branches whose tips are reachable from the\n-\tspecified commit (HEAD if not specified).\n+\tspecified commit (HEAD if not specified). Implies `--list`.\n \n --no-merged [<commit>]::\n \tOnly list branches whose tips are not reachable from the\n-\tspecified commit (HEAD if not specified).\n+\tspecified commit (HEAD if not specified). Implies `--list`.\n \n <branchname>::\n \tThe name of the branch to create or delete.\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 873f624..4aa3d4e 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -825,6 +825,9 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \tif (!delete && !rename && !edit_description && !new_upstream && !unset_upstream && argc == 0)\n \t\tlist = 1;\n \n+\tif (with_commit || merge_filter != NO_FILTER)\n+\t\tlist = 1;\n+\n \tif (!!delete + !!rename + !!force_create + !!list + !!new_upstream + !!unset_upstream > 1)\n \t\tusage_with_options(builtin_branch_usage, options);\n \ndiff --git a/t/t3201-branch-contains.sh b/t/t3201-branch-contains.sh\nindex f86f4bc..141b061 100755\n--- a/t/t3201-branch-contains.sh\n+++ b/t/t3201-branch-contains.sh\n@@ -55,6 +55,16 @@ test_expect_success 'branch --contains=side' '\n \n '\n \n+test_expect_success 'branch --contains with pattern implies --list' '\n+\n+\tgit branch --contains=master master >actual &&\n+\t{\n+\t\techo \"  master\"\n+\t} >expect &&\n+\ttest_cmp expect actual\n+\n+'\n+\n test_expect_success 'side: branch --merged' '\n \n \tgit branch --merged >actual &&\n@@ -66,6 +76,16 @@ test_expect_success 'side: branch --merged' '\n \n '\n \n+test_expect_success 'branch --merged with pattern implies --list' '\n+\n+\tgit branch --merged=side master >actual &&\n+\t{\n+\t\techo \"  master\"\n+\t} >expect &&\n+\ttest_cmp expect actual\n+\n+'\n+\n test_expect_success 'side: branch --no-merged' '\n \n \tgit branch --no-merged >actual &&\n@@ -95,4 +115,19 @@ test_expect_success 'master: branch --no-merged' '\n \n '\n \n+test_expect_success 'branch --no-merged with pattern implies --list' '\n+\n+\tgit branch --no-merged=master master >actual &&\n+\t>expect &&\n+\ttest_cmp expect actual\n+\n+'\n+\n+test_expect_success 'implicit --list conflicts with modification options' '\n+\n+\ttest_must_fail git branch --contains=master -d &&\n+\ttest_must_fail git branch --contains=master -m foo\n+\n+'\n+\n test_done\n-- \n1.8.1.2.5.g1cb3f73\n"},{"id":"208359","messageId":"7vpq0lic2r.fsf@alter.siamese.dyndns.org","threadId":"32781","inReplyTo":"20130131064357.GA24660@sigill.intra.peff.net","subject":"Re: [PATCH 0/2] improve \"git branch --contains=<commit> <pattern>\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-01-31T15:53:00Z","receivedAt":"2013-01-31T15:53:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> That being said, we could be much more helpful. It seems like --contains\n> should imply listing mode, since it is nonsensical in other modes. The\n> second patch below adjusts that, and makes the command above do what you\n> expect.\n>\n>   [1/2]: docs: clarify git-branch --list behavior\n>   [2/2]: branch: let branch filters imply --list\n\nThanks.  Looks good.\n"},{"id":"208361","messageId":"1504250.y8BAS4sG2O@al","threadId":"32781","inReplyTo":"20130131064611.GB25315@sigill.intra.peff.net","subject":"Re: [PATCH 2/2] branch: let branch filters imply --list","fromName":"Peter Wu","fromEmail":"lekensteyn@gmail.com","sentAt":"2013-01-31T16:13:15Z","receivedAt":"2013-01-31T16:13:15Z","isPatch":true,"sender":{"key":"lekensteyn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/164530?v=4"},"body":"On Thursday 31 January 2013 01:46:11 Jeff King wrote:\n> Currently, a branch filter like `--contains`, `--merged`, or\n> `--no-merged` is ignored when we are not in listing mode.\n> For example:\n> \n>   git branch --contains=foo bar\n> \n> will create the branch \"bar\" from the current HEAD, ignoring\n> the `--contains` argument entirely. This is not very\n> helpful. There are two reasonable behaviors for git here:\n> \n>   1. Flag an error; the arguments do not make sense.\n> \n>   2. Implicitly go into `--list` mode\n> \n> This patch chooses the latter, as it is more convenient, and\n> there should not be any ambiguity with attempting to create\n> a branch; using `--contains` and not wanting to list is\n> nonsensical.\n> \n> That leaves the case where an explicit modification option\n> like `-d` is given.  We already catch the case where\n> `--list` is given alongside `-d` and flag an error. With\n> this patch, we will also catch the use of `--contains` and\n> other filter options alongside `-d`.\n> \n> Signed-off-by: Jeff King <peff@peff.net>\nTested-by: Peter Wu <lekensteyn@gmail.com>\n\nI have tested this patch on top of 1.8.1.2 and it seems to work.\n\nOne note, the following command spits out master without complaining about the \nnon-existing branch name:\n\n    git branch --contains <id> master <non-existant branch name>\n\n(the order of branches doesn't affect the result.)\n\nRegards,\nPeter\n"},{"id":"208365","messageId":"7v4nhxi8vr.fsf@alter.siamese.dyndns.org","threadId":"32781","inReplyTo":"1504250.y8BAS4sG2O@al","subject":"Re: [PATCH 2/2] branch: let branch filters imply --list","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-01-31T17:02:00Z","receivedAt":"2013-01-31T17:02:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Peter Wu <lekensteyn@gmail.com> writes:\n\n> One note, the following command spits out master without complaining about the \n> non-existing branch name:\n>\n>     git branch --contains <id> master <non-existant branch name>\n>\n> (the order of branches doesn't affect the result.)\n\nThat is perfectly normal.\n\nWhat you gave after \"--contains <id>\" are *not* branch names.  They\nare patterns against branch names that fits the given criteria (in\nthis case \"--contains <id>\") are matched, and the branches that do\nnot match any of the patterns will not appear in the result.\n"},{"id":"208430","messageId":"CAPig+cT21Fx6BaD=1jT7KSBZSZkWu-A-0U+QsM2qO8g5gki=YQ@mail.gmail.com","threadId":"32781","inReplyTo":"20130131064545.GA25315@sigill.intra.peff.net","subject":"Re: [PATCH 1/2] docs: clarify git-branch --list behavior","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2013-02-01T00:20:45Z","receivedAt":"2013-02-01T00:20:45Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Jan 31, 2013 at 1:45 AM, Jeff King <peff@peff.net> wrote:\n> +If `--list` is given, or if there are no non-option arguments, existing\n> +branches are listed; the current branch will be highlighted with an\n> +asterisk.  Option `-r` causes the remote-tracking branches to be listed,\n> +and option `-a` shows both local and remote branches. If a `<pattern>`\n> +is given, it is used as a shell wildcard to restrict the output to\n> +matching branches. If multiple patterns are given, a branch is shown if\n> +any it is matched by any of the patterns.\n\ns/if any it is/if it is/\n\n-- ES\n"},{"id":"208431","messageId":"7v4nhweuoi.fsf@alter.siamese.dyndns.org","threadId":"32781","inReplyTo":"CAPig+cT21Fx6BaD=1jT7KSBZSZkWu-A-0U+QsM2qO8g5gki=YQ@mail.gmail.com","subject":"Re: [PATCH 1/2] docs: clarify git-branch --list behavior","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-01T00:37:01Z","receivedAt":"2013-02-01T00:37:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Sunshine <sunshine@sunshineco.com> writes:\n\n> On Thu, Jan 31, 2013 at 1:45 AM, Jeff King <peff@peff.net> wrote:\n>> +If `--list` is given, or if there are no non-option arguments, existing\n>> +branches are listed; the current branch will be highlighted with an\n>> +asterisk.  Option `-r` causes the remote-tracking branches to be listed,\n>> +and option `-a` shows both local and remote branches. If a `<pattern>`\n>> +is given, it is used as a shell wildcard to restrict the output to\n>> +matching branches. If multiple patterns are given, a branch is shown if\n>> +any it is matched by any of the patterns.\n>\n> s/if any it is/if it is/\n\nThanks; I'll squash this in.  Peff, no need to resend.\n\n Documentation/git-branch.txt | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt\nindex 01aa87f..2635dee 100644\n--- a/Documentation/git-branch.txt\n+++ b/Documentation/git-branch.txt\n@@ -28,7 +28,7 @@ asterisk.  Option `-r` causes the remote-tracking branches to be listed,\n and option `-a` shows both local and remote branches. If a `<pattern>`\n is given, it is used as a shell wildcard to restrict the output to\n matching branches. If multiple patterns are given, a branch is shown if\n-any it is matched by any of the patterns.  Note that when providing a\n+it matches any of the patterns.  Note that when providing a\n `<pattern>`, you must use `--list`; otherwise the command is interpreted\n as branch creation.\n \n"},{"id":"208443","messageId":"20130201050637.GC29973@sigill.intra.peff.net","threadId":"32781","inReplyTo":"7v4nhweuoi.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 1/2] docs: clarify git-branch --list behavior","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-02-01T05:06:37Z","receivedAt":"2013-02-01T05:06:37Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Jan 31, 2013 at 04:37:01PM -0800, Junio C Hamano wrote:\n\n> Eric Sunshine <sunshine@sunshineco.com> writes:\n> \n> > On Thu, Jan 31, 2013 at 1:45 AM, Jeff King <peff@peff.net> wrote:\n> >> +If `--list` is given, or if there are no non-option arguments, existing\n> >> +branches are listed; the current branch will be highlighted with an\n> >> +asterisk.  Option `-r` causes the remote-tracking branches to be listed,\n> >> +and option `-a` shows both local and remote branches. If a `<pattern>`\n> >> +is given, it is used as a shell wildcard to restrict the output to\n> >> +matching branches. If multiple patterns are given, a branch is shown if\n> >> +any it is matched by any of the patterns.\n> >\n> > s/if any it is/if it is/\n> \n> Thanks; I'll squash this in.  Peff, no need to resend.\n\nThanks. No matter how many times I proofread a doc change, I always\nmanage to slip an error into the final version. Hooray for many eyes.\n\n-Peff\n"},{"id":"208445","messageId":"7v38xgd1z7.fsf@alter.siamese.dyndns.org","threadId":"32781","inReplyTo":"20130201050637.GC29973@sigill.intra.peff.net","subject":"Re: [PATCH 1/2] docs: clarify git-branch --list behavior","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-02-01T05:42:20Z","receivedAt":"2013-02-01T05:42:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> Thanks. No matter how many times I proofread a doc change, I always\n> manage to slip an error into the final version.\n\nI think everybody shares that trait.\n\n> Hooray for many eyes.\n\nIndeed.\n"}]}