diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-05-29 14:23:10 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-05-29 14:23:10 -0700 |
commit | 77eb44b8ed601a17a5ec9b1fb8c4c53ba10aaa56 (patch) | |
tree | 9f4d26a64befc377a299f2b98ac551cc824e28a9 /branch.c | |
parent | Merge branch 'jc/prune-all' (diff) | |
parent | glossary: Update and rephrase the definition of a remote-tracking branch (diff) | |
download | tgif-77eb44b8ed601a17a5ec9b1fb8c4c53ba10aaa56.tar.xz |
Merge branch 'jh/checkout-auto-tracking'
Update "git checkout foo" that DWIMs the intended "upstream" and
turns it into "git checkout -t -b foo remotes/origin/foo" to
correctly take existing remote definitions into account.
The remote "origin" may be what uniquely map its own branch to
remotes/some/where/foo but that some/where may not be "origin".
* 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')
-rw-r--r-- | branch.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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); else |