All of lore.kernel.org
 help / color / mirror / Atom feed
From: Per Cederqvist <cederp@opera.com>
To: git@vger.kernel.org
Subject: "git branch --contains x y" creates a branch instead of checking containment
Date: Thu, 21 Feb 2013 14:00:27 +0100	[thread overview]
Message-ID: <51261A6B.5020909@opera.com> (raw)

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.

             reply	other threads:[~2013-02-21 13:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-21 13:00 Per Cederqvist [this message]
2013-02-21 15:58 ` "git branch --contains x y" creates a branch instead of checking containment Jeff King
2013-02-21 16:05   ` Per Cederqvist
2013-02-21 17:48     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51261A6B.5020909@opera.com \
    --to=cederp@opera.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.