@matheusbsbs / matheus-bagliano / commits / 18afe101eb
Fork 0

git push: Interpret $GIT_DIR/branches in a Cogito compatible way

Current git versions ignore everything after # (called <head> in the following) when pushing. Older versions (before cf818348f1ab57), interpret #<head> as part of the URL, which make git bail out. As branches origin from Cogito, it is the best to correct this by using the behaviour of cg-push, that is to push HEAD to remote refs/heads/<head>. Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Koegler committed Nov 10, 2008 at 22:47 UTC 18afe101eb2c2f68ba58085515f592148128fba3
3 files changed +75 -5
Documentation/urls-remotes.txt
+14 -5
@@ -68,13 +68,22 @@ This file should have the following format:
68 ------------
69
70 `<url>` is required; `#<head>` is optional.
71 -When you do not provide a refspec on the command line,
72 -git will use the following refspec, where `<head>` defaults to `master`,
73 -and `<repository>` is the name of this file
74 -you provided in the command line.
71 +
72 +Depending on the operation, git will use one of the following
73 +refspecs, if you don't provide one on the command line.
74 +`<branch>` is the name of this file in `$GIT_DIR/branches` and
75 +`<head>` defaults to `master`.
76 +
77 +git fetch uses:
78 +
79 +------------
80 + refs/heads/<head>:refs/heads/<branch>
81 +------------
82 +
83 +git push uses:
84
85 ------------
77 - refs/heads/<head>:<repository>
86 + HEAD:refs/heads/<head>
87 ------------
88
89
remote.c
+11
@@ -298,6 +298,17 @@ static void read_branches_file(struct remote *remote)
298 }
299 add_url_alias(remote, p);
300 add_fetch_refspec(remote, strbuf_detach(&branch, 0));
301 + /*
302 + * Cogito compatible push: push current HEAD to remote #branch
303 + * (master if missing)
304 + */
305 + strbuf_init(&branch, 0);
306 + strbuf_addstr(&branch, "HEAD");
307 + if (frag)
308 + strbuf_addf(&branch, ":refs/heads/%s", frag);
309 + else
310 + strbuf_addstr(&branch, ":refs/heads/master");
311 + add_push_refspec(remote, strbuf_detach(&branch, 0));
312 remote->fetch_tags = 1; /* always auto-follow */
313 }
314
t/t5516-fetch-push.sh
+50
@@ -494,4 +494,54 @@ test_expect_success 'allow deleting an invalid remote ref' '
494
495 '
496
497 +test_expect_success 'fetch with branches' '
498 + mk_empty &&
499 + git branch second $the_first_commit &&
500 + git checkout second &&
501 + echo ".." > testrepo/.git/branches/branch1 &&
502 + (cd testrepo &&
503 + git fetch branch1 &&
504 + r=$(git show-ref -s --verify refs/heads/branch1) &&
505 + test "z$r" = "z$the_commit" &&
506 + test 1 = $(git for-each-ref refs/heads | wc -l)
507 + ) &&
508 + git checkout master
509 +'
510 +
511 +test_expect_success 'fetch with branches containing #' '
512 + mk_empty &&
513 + echo "..#second" > testrepo/.git/branches/branch2 &&
514 + (cd testrepo &&
515 + git fetch branch2 &&
516 + r=$(git show-ref -s --verify refs/heads/branch2) &&
517 + test "z$r" = "z$the_first_commit" &&
518 + test 1 = $(git for-each-ref refs/heads | wc -l)
519 + ) &&
520 + git checkout master
521 +'
522 +
523 +test_expect_success 'push with branches' '
524 + mk_empty &&
525 + git checkout second &&
526 + echo "testrepo" > .git/branches/branch1 &&
527 + git push branch1 &&
528 + (cd testrepo &&
529 + r=$(git show-ref -s --verify refs/heads/master) &&
530 + test "z$r" = "z$the_first_commit" &&
531 + test 1 = $(git for-each-ref refs/heads | wc -l)
532 + )
533 +'
534 +
535 +test_expect_success 'push with branches containing #' '
536 + mk_empty &&
537 + echo "testrepo#branch3" > .git/branches/branch2 &&
538 + git push branch2 &&
539 + (cd testrepo &&
540 + r=$(git show-ref -s --verify refs/heads/branch3) &&
541 + test "z$r" = "z$the_first_commit" &&
542 + test 1 = $(git for-each-ref refs/heads | wc -l)
543 + ) &&
544 + git checkout master
545 +'
546 +
547 test_done