summaryrefslogtreecommitdiff
path: root/branch.c
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2011-02-17 00:12:20 +0100
committerJunio C Hamano <gitster@pobox.com>2011-02-16 16:55:56 -0800
commit21b5b1e8dc9bed2b518defe29d69ebc27da4b68f (patch)
tree7b56cf9df74614e1e71592cf1222f992a0eaf5b5 /branch.c
parentc6d059bbccb8460959b9aedfeefbb4d6aac6e842 (diff)
downloadgit-21b5b1e8dc9bed2b518defe29d69ebc27da4b68f.tar.gz
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>
Diffstat (limited to 'branch.c')
-rw-r--r--branch.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/branch.c b/branch.c
index 93dc866f8c..da5c03e565 100644
--- a/branch.c
+++ b/branch.c
@@ -175,9 +175,14 @@ void create_branch(const char *head,
die("Cannot setup tracking information; starting point is not a branch.");
break;
case 1:
- /* Unique completion -- good, only if it is a real ref */
- if (explicit_tracking && !strcmp(real_ref, "HEAD"))
- die("Cannot setup tracking information; starting point is not a branch.");
+ /* Unique completion -- good, only if it is a real branch */
+ if (prefixcmp(real_ref, "refs/heads/") &&
+ prefixcmp(real_ref, "refs/remotes/")) {
+ if (explicit_tracking)
+ die("Cannot setup tracking information; starting point is not a branch.");
+ else
+ real_ref = NULL;
+ }
break;
default:
die("Ambiguous object name: '%s'.", start_name);