]> git.ipfire.org Git - thirdparty/git.git/commit - branch.c
branch/checkout --track: Ensure that upstream branch is indeed a branch
authorJohan Herland <johan@herland.net>
Wed, 16 Feb 2011 23:12:20 +0000 (00:12 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Feb 2011 00:55:56 +0000 (16:55 -0800)
commit21b5b1e8dc9bed2b518defe29d69ebc27da4b68f
tree7b56cf9df74614e1e71592cf1222f992a0eaf5b5
parentc6d059bbccb8460959b9aedfeefbb4d6aac6e842
branch/checkout --track: Ensure that upstream branch is indeed a branch

When creating a new branch using the --track option, we must make sure that
we don't try to set an upstream that does not make sense to follow (using
'git pull') or update (using 'git push'). The current code checks against
using HEAD as upstream (since tracking a symref doesn't make sense). However,
tracking a tag doesn't make sense either. Indeed, tracking _any_ ref that is
not a (local or remote) branch doesn't make sense, and should be disallowed.

This patch achieves this by checking that the ref we're trying to --track
resides within refs/heads/* or refs/remotes/*. This new check replaces the
previous check against HEAD.

A couple of testcases are also added, verifying that we cannot create
branches with tags as upstreams.

Finally, some selftests relying on using a non-branch as an upstream have
been reworked or removed:

- t6040: Reverse the meaning of two tests that depend on the ability to
use (lightweight and annotated) tags as upstreams. These two tests were
originally added in commits 1be570f and 57ffc5f, and this patch reverts the
intention of those two commits.

- t7201: Remove part of a test (introduced in 9188ed8) relying on a
non-branch as upstream.

Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
branch.c
t/t3200-branch.sh
t/t6040-tracking-info.sh
t/t7201-co.sh