git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* "git branch --contains x y" creates a branch instead of checking containment
@ 2013-02-21 13:00 Per Cederqvist
  2013-02-21 15:58 ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Per Cederqvist @ 2013-02-21 13:00 UTC (permalink / raw
  To: git

The "git branch --list --contains x y" command lists
all branches that contains commit x and matches the
pattern y. Reading the git-branch(1) manual page gives
the impression that "--list" is redundant, and that
you can instead write

    git branch --contains x y

That command does something completely different,
though. The "--contains x" part is silently ignored,
so it creates a branch named "y" pointing at HEAD.

Tested in git 1.8.1.1 and 1.8.1.4.

In my opinion, there are two ways to fix this:

  - change the "git branch" implementation so
    that --contains implies --list.

  - change the manual page synopsis so that
    it is clear that --contains can only be
    used if --list is also used.  Also add an
    error check to the "git branch" implementation
    so that using --contains without specifying
    --list produces a fatal error message.

Personally I would prefer the first solution.

Repeat by running these commands:

# Set up a repo with two commits.
# Branch a points to the oldest one, and
# b and master to the newest one.
mkdir contains || exit 1
cd contains
git init
touch a; git add a; git commit -m"Added a".
git branch a
touch b; git add b; git commit -m"Added b".
git branch b

git branch --list --contains a
# Prints "a", "b" and "master, as expected.

git branch --contains a
# Prints "a", "b" and "master, as expected.
# In this case, the --list option can be removed.

git branch --list --contains a b
# Prints "b", as expected.  "b" is a <pattern>.

git branch --list --contains a c
# Prints nothing, as expected, as the "c" pattern doesn't match any of
# the existing branches.

git for-each-ref
# Prints three lines: refs/heads/a, refs/heads/b and
# refs/heads/master, as expected.

git branch --contains a c
# Prints nothing, as expected, but...

git for-each-ref
# Prints four lines!  Apparently, the command above created
# refs/heads/c.

     /ceder

P.S. What I really wanted to do was "git merge-base
--is-ancestor a b", but I keep forgetting its name.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: "git branch --contains x y" creates a branch instead of checking containment
  2013-02-21 13:00 "git branch --contains x y" creates a branch instead of checking containment Per Cederqvist
@ 2013-02-21 15:58 ` Jeff King
  2013-02-21 16:05   ` Per Cederqvist
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2013-02-21 15:58 UTC (permalink / raw
  To: Per Cederqvist; +Cc: git

On Thu, Feb 21, 2013 at 02:00:27PM +0100, Per Cederqvist wrote:

> That command does something completely different,
> though. The "--contains x" part is silently ignored,
> so it creates a branch named "y" pointing at HEAD.
> 
> Tested in git 1.8.1.1 and 1.8.1.4.
> 
> In my opinion, there are two ways to fix this:
> 
>  - change the "git branch" implementation so
>    that --contains implies --list.

I think that is the best option, too. In fact, I even wrote a patch. :)

It's d040350 (branch: let branch filters imply --list, 2013-01-31), and
it's already in v1.8.2-rc0.

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: "git branch --contains x y" creates a branch instead of checking containment
  2013-02-21 15:58 ` Jeff King
@ 2013-02-21 16:05   ` Per Cederqvist
  2013-02-21 17:48     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Per Cederqvist @ 2013-02-21 16:05 UTC (permalink / raw
  To: Jeff King; +Cc: git

On 02/21/13 16:58, Jeff King wrote:
> On Thu, Feb 21, 2013 at 02:00:27PM +0100, Per Cederqvist wrote:
>
>> That command does something completely different,
>> though. The "--contains x" part is silently ignored,
>> so it creates a branch named "y" pointing at HEAD.
>>
>> Tested in git 1.8.1.1 and 1.8.1.4.
>>
>> In my opinion, there are two ways to fix this:
>>
>>   - change the "git branch" implementation so
>>     that --contains implies --list.
>
> I think that is the best option, too. In fact, I even wrote a patch. :)
>
> It's d040350 (branch: let branch filters imply --list, 2013-01-31), and
> it's already in v1.8.2-rc0.
>
> -Peff

Great! Thanks for the quick fix of my bug report. Negative response
time... not bad. Not bad at all. :-)

     /ceder

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: "git branch --contains x y" creates a branch instead of checking containment
  2013-02-21 16:05   ` Per Cederqvist
@ 2013-02-21 17:48     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2013-02-21 17:48 UTC (permalink / raw
  To: Per Cederqvist; +Cc: Jeff King, git

Per Cederqvist <cederp@opera.com> writes:

> On 02/21/13 16:58, Jeff King wrote:
>> On Thu, Feb 21, 2013 at 02:00:27PM +0100, Per Cederqvist wrote:
>>
>>> That command does something completely different,
>>> though. The "--contains x" part is silently ignored,
>>> so it creates a branch named "y" pointing at HEAD.
>>>
>>> Tested in git 1.8.1.1 and 1.8.1.4.
>>>
>>> In my opinion, there are two ways to fix this:
>>>
>>>   - change the "git branch" implementation so
>>>     that --contains implies --list.
>>
>> I think that is the best option, too. In fact, I even wrote a patch. :)
>>
>> It's d040350 (branch: let branch filters imply --list, 2013-01-31), and
>> it's already in v1.8.2-rc0.
>>
>> -Peff
>
> Great! Thanks for the quick fix of my bug report. Negative response
> time... not bad. Not bad at all. :-)

Yeah, Jeff has a time machine ;-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-02-21 17:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-21 13:00 "git branch --contains x y" creates a branch instead of checking containment Per Cederqvist
2013-02-21 15:58 ` Jeff King
2013-02-21 16:05   ` Per Cederqvist
2013-02-21 17:48     ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).