@@ -447,11 +447,21 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)char*slash;if(!argc||!strcmp(argv[0],"--"))die("--track needs a branch name");-slash=strchr(argv[0],'/');-if(slash&&!prefixcmp(argv[0],"refs/"))-slash=strchr(slash+1,'/');-if(slash&&!prefixcmp(argv[0],"remotes/"))-slash=strchr(slash+1,'/');+if(!prefixcmp(argv[0],"remotes/"))+/* skip the name of a remote */+slash=strchr(argv[0]+8,'/');+elseif(!prefixcmp(argv[0],"refs/")){+/* skip namespaces, try use the names of their+*branches,butforthetargetnamespace+*(heads)demandanewname.Alsoskipthe+*firstelementin"remotes"namespace*/+constchar*ns=argv[0]+5;+slash=!prefixcmp(ns,"heads/")?NULL:+!prefixcmp(ns,"remotes/")?+strchr(ns+8,'/'):strchr(ns,'/');+}else+/* otherwise - just skip the first element */+slash=strchr(argv[0],'/');if(!slash||!slash[1])die("Missing branch name; try -b");opts.new_branch=slash+1;
@@ -340,9 +340,30 @@ test_expect_success \ test_expect_success\'checkout with --track fakes a sensible -b <name>''gitupdate-refrefs/remotes/origin/koala/bearrenamer&&+gitupdate-refrefs/new/koala/bearrenamer&&+gitcheckout--trackorigin/koala/bear&&test"refs/heads/koala/bear"="$(gitsymbolic-refHEAD)"&&-test"$(gitrev-parseHEAD)"="$(gitrev-parserenamer)"'+test"$(gitrev-parseHEAD)"="$(gitrev-parserenamer)"&&++gitcheckoutmaster&&gitbranch-Dkoala/bear&&++gitcheckout--trackrefs/remotes/origin/koala/bear&&+test"refs/heads/koala/bear"="$(gitsymbolic-refHEAD)"&&+test"$(gitrev-parseHEAD)"="$(gitrev-parserenamer)"&&++gitcheckoutmaster&&gitbranch-Dkoala/bear&&++gitcheckout--trackremotes/origin/koala/bear&&+test"refs/heads/koala/bear"="$(gitsymbolic-refHEAD)"&&+test"$(gitrev-parseHEAD)"="$(gitrev-parserenamer)"&&++gitcheckoutmaster&&gitbranch-Dkoala/bear&&++gitcheckout--trackrefs/new/koala/bear&&+test"refs/heads/koala/bear"="$(gitsymbolic-refHEAD)"&&+test"$(gitrev-parseHEAD)"="$(gitrev-parserenamer)"+' test_expect_success\'checkout with --track, but without -b, fails with too short tracked name''
Why is this not enough? It strips refs/ if there is one, and remotes/ if
there is one (possibly after stripping refs/). No?
No. It strips refs/ OR remotes/ (because of prefixcmp with argv[0]).
And I still wanted refs/<namespace>/something...
Yes, you are correct. However, to fix my thinko, I deem this preferable:
-- snipsnap --
builtin-checkout.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
From: Alex Riesen <hidden> Date: 2016-06-15 22:45:11
Johannes Schindelin, Wed, Aug 20, 2008 22:16:19 +0200:
quoted hunk
quoted
No. It strips refs/ OR remotes/ (because of prefixcmp with argv[0]).
And I still wanted refs/<namespace>/something...
Yes, you are correct. However, to fix my thinko, I deem this preferable:
-- snipsnap --
builtin-checkout.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)