{"thread":{"id":"16278","subject":"[PATCH v2] git push: Interpret $GIT_DIR/branches in a Cogito compatible way","startedAt":"2008-11-11T21:51:00Z","lastAt":"2008-11-12T00:52:01Z","messageCount":2,"participants":["Martin Koegler","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"95496","messageId":"1226440260-26943-1-git-send-email-mkoegler@auto.tuwien.ac.at","threadId":"16278","inReplyTo":null,"subject":"[PATCH v2] git push: Interpret $GIT_DIR/branches in a Cogito compatible way","fromName":"Martin Koegler","fromEmail":"mkoegler@auto.tuwien.ac.at","sentAt":"2008-11-11T21:51:00Z","receivedAt":"2008-11-11T21:51:00Z","isPatch":true,"sender":{"key":"mkoegler@auto.tuwien.ac.at","avatar":null},"body":"Current git versions ignore everything after # (called <head> in the\nfollowing) when pushing. Older versions (before cf818348f1ab57),\ninterpret #<head> as part of the URL, which make git bail out.\n\nAs branches origin from Cogito, it is the best to correct this by\nusing the behaviour of cg-push:\n\npush HEAD to remote refs/heads/<head>\n\nSigned-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>\n---\nRebased to maint. One line dropped from commit message. Fixed typo,\nreported by Mike Ralphson. \n\nurls-remote.txt is unchanged between maint and next.\nremote.c contains no changes in read_branches_file.\nt5516 needed a manual invention.\n\nApart from merge problems (test ordering) in t5516, it should apply \nto master or next too.\n\n Documentation/urls-remotes.txt |   19 +++++++++++----\n remote.c                       |   11 ++++++++\n t/t5516-fetch-push.sh          |   50 ++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 75 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/urls-remotes.txt b/Documentation/urls-remotes.txt\nindex 504ae8a..41ec777 100644\n--- a/Documentation/urls-remotes.txt\n+++ b/Documentation/urls-remotes.txt\n@@ -68,13 +68,22 @@ This file should have the following format:\n ------------\n \n `<url>` is required; `#<head>` is optional.\n-When you do not provide a refspec on the command line,\n-git will use the following refspec, where `<head>` defaults to `master`,\n-and `<repository>` is the name of this file\n-you provided in the command line.\n+\n+Depending on the operation, git will use one of the following\n+refspecs, if you don't provide one on the command line.\n+`<branch>` is the name of this file in `$GIT_DIR/branches` and\n+`<head>` defaults to `master`.\n+\n+git fetch uses:\n+\n+------------\n+\trefs/heads/<head>:refs/heads/<branch>\n+------------\n+\n+git push uses:\n \n ------------\n-\trefs/heads/<head>:<repository>\n+\tHEAD:refs/heads/<head>\n ------------\n \n \ndiff --git a/remote.c b/remote.c\nindex 7688f3b..91f1b7c 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -298,6 +298,17 @@ static void read_branches_file(struct remote *remote)\n \t}\n \tadd_url_alias(remote, p);\n \tadd_fetch_refspec(remote, strbuf_detach(&branch, 0));\n+\t/*\n+\t * Cogito compatible push: push current HEAD to remote #branch\n+\t * (master if missing)\n+\t */\n+\tstrbuf_init(&branch, 0);\n+\tstrbuf_addstr(&branch, \"HEAD\");\n+\tif (frag)\n+\t\tstrbuf_addf(&branch, \":refs/heads/%s\", frag);\n+\telse\n+\t\tstrbuf_addstr(&branch, \":refs/heads/master\");\n+\tadd_push_refspec(remote, strbuf_detach(&branch, 0));\n \tremote->fetch_tags = 1; /* always auto-follow */\n }\n \ndiff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh\nindex 598664c..f9e8780 100755\n--- a/t/t5516-fetch-push.sh\n+++ b/t/t5516-fetch-push.sh\n@@ -494,4 +494,54 @@ test_expect_success 'allow deleting an invalid remote ref' '\n \n '\n \n+test_expect_success 'fetch with branches' '\n+\tmk_empty &&\n+\tgit branch second $the_first_commit &&\n+\tgit checkout second &&\n+\techo \"..\" > testrepo/.git/branches/branch1 &&\n+\t(cd testrepo &&\n+\t\tgit fetch branch1 &&\n+\t\tr=$(git show-ref -s --verify refs/heads/branch1) &&\n+\t\ttest \"z$r\" = \"z$the_commit\" &&\n+\t\ttest 1 = $(git for-each-ref refs/heads | wc -l)\n+\t) &&\n+\tgit checkout master\n+'\n+\n+test_expect_success 'fetch with branches containing #' '\n+\tmk_empty &&\n+\techo \"..#second\" > testrepo/.git/branches/branch2 &&\n+\t(cd testrepo &&\n+\t\tgit fetch branch2 &&\n+\t\tr=$(git show-ref -s --verify refs/heads/branch2) &&\n+\t\ttest \"z$r\" = \"z$the_first_commit\" &&\n+\t\ttest 1 = $(git for-each-ref refs/heads | wc -l)\n+\t) &&\n+\tgit checkout master\n+'\n+\n+test_expect_success 'push with branches' '\n+\tmk_empty &&\n+\tgit checkout second &&\n+\techo \"testrepo\" > .git/branches/branch1 &&\n+\tgit push branch1 &&\n+\t(cd testrepo &&\n+\t\tr=$(git show-ref -s --verify refs/heads/master) &&\n+\t\ttest \"z$r\" = \"z$the_first_commit\" &&\n+\t\ttest 1 = $(git for-each-ref refs/heads | wc -l)\n+\t)\n+'\n+\n+test_expect_success 'push with branches containing #' '\n+\tmk_empty &&\n+\techo \"testrepo#branch3\" > .git/branches/branch2 &&\n+\tgit push branch2 &&\n+\t(cd testrepo &&\n+\t\tr=$(git show-ref -s --verify refs/heads/branch3) &&\n+\t\ttest \"z$r\" = \"z$the_first_commit\" &&\n+\t\ttest 1 = $(git for-each-ref refs/heads | wc -l)\n+\t) &&\n+\tgit checkout master\n+'\n+\n test_done\n-- \n1.5.6.5\n"},{"id":"95520","messageId":"7vd4h1u5ou.fsf@gitster.siamese.dyndns.org","threadId":"16278","inReplyTo":"1226440260-26943-1-git-send-email-mkoegler@auto.tuwien.ac.at","subject":"Re: [PATCH v2] git push: Interpret $GIT_DIR/branches in a Cogito compatible way","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-11-12T00:52:01Z","receivedAt":"2008-11-12T00:52:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks, will start cooking in 'next'.\n"}]}