path: root/branch.c
diff options
authorJunio C Hamano <>2013-06-27 21:37:21 (GMT)
committerJunio C Hamano <>2013-06-27 21:37:21 (GMT)
commit11fbc0b1e1d5435f482af7bf391fd0d679955ba6 (patch)
tree7c4beeb7d7095f2fd3c30b012b6d8872e9db27ab /branch.c
parentc0add3073a5bd0e295cdaea76e5c9b7805f8a047 (diff)
parent229177aaea295a3f804f98494d7bcde9c088fc0a (diff)
Merge branch 'jh/checkout-auto-tracking' into maint
* jh/checkout-auto-tracking: glossary: Update and rephrase the definition of a remote-tracking branch branch.c: Validate tracking branches with refspecs instead of refs/remotes/* t9114.2: Don't use --track option against "svn-remote"-tracking branches t7201.24: Add refspec to keep --track working t3200.39: tracking setup should fail if there is no matching refspec. checkout: Use remote refspecs when DWIMming tracking branches t2024: Show failure to use refspec when DWIMming remote branch names t2024: Add tests verifying current DWIM behavior of 'git checkout <branch>'
Diffstat (limited to 'branch.c')
1 files changed, 16 insertions, 1 deletions
diff --git a/branch.c b/branch.c
index 97c72bf..c5c6984 100644
--- a/branch.c
+++ b/branch.c
@@ -197,6 +197,21 @@ int validate_new_branchname(const char *name, struct strbuf *ref,
return 1;
+static int check_tracking_branch(struct remote *remote, void *cb_data)
+ char *tracking_branch = cb_data;
+ struct refspec query;
+ memset(&query, 0, sizeof(struct refspec));
+ query.dst = tracking_branch;
+ return !(remote_find_tracking(remote, &query) ||
+ prefixcmp(query.src, "refs/heads/"));
+static int validate_remote_tracking_branch(char *ref)
+ return !for_each_remote(check_tracking_branch, ref);
static const char upstream_not_branch[] =
N_("Cannot setup tracking information; starting point '%s' is not a branch.");
static const char upstream_missing[] =
@@ -259,7 +274,7 @@ void create_branch(const char *head,
case 1:
/* Unique completion -- good, only if it is a real branch */
if (prefixcmp(real_ref, "refs/heads/") &&
- prefixcmp(real_ref, "refs/remotes/")) {
+ validate_remote_tracking_branch(real_ref)) {
if (explicit_tracking)
die(_(upstream_not_branch), start_name);