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 commits1be570fand57ffc5f, and this patch reverts the intention of those two commits. - t7201: Remove part of a test (introduced in9188ed8) relying on a non-branch as upstream. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
c6d059bbcc
commit
21b5b1e8dc
11
branch.c
11
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);
|
||||
|
||||
Reference in New Issue
Block a user