{"thread":{"id":"5007","subject":"[PATCH] Per branch properties for pull and fetch","startedAt":"2006-07-27T08:14:45Z","lastAt":"2006-07-27T20:26:43Z","messageCount":7,"participants":["Santi Béjar","Martin Waitz","Santi","Matthias Lederhofer"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"24183","messageId":"87lkqfcvm2.fsf@gmail.com","threadId":"5007","inReplyTo":null,"subject":"[PATCH] Per branch properties for pull and fetch","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2006-07-27T08:14:45Z","receivedAt":"2006-07-27T08:14:45Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"It allows to specify on a per branch basis the following:\n.- default repository to fetch\n.- default branches to merge on a per repository basis\n.- default pull.{octopus,twohead}\n\nSo if you have this in the config:\n[branch \"my\"]\n\tremote=yours\n\tmerge=master\n\tmerge=our from theirs\n\tmerge=mine from .\n\nand you are in the branch \"my\":\n\n\"git pull\": fetch the remote yours and merge the branch master.\n\"git pull theirs\": fetch the remote theirs and merge the branch our.\n\"git pull .\": merge the branch mine from the local repository.\n---\n Documentation/config.txt |   14 +++++++++++\n git-fetch.sh             |   13 ++++++----\n git-parse-remote.sh      |   57 ++++++++++++++++++++++++++++++++++++++++++++++\n git-pull.sh              |   29 ++++++++++++++++++++---\n 4 files changed, 104 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 465eb13..f12b595 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -116,6 +116,20 @@ apply.whitespace::\n \tTells `git-apply` how to handle whitespaces, in the same way\n \tas the '--whitespace' option. See gitlink:git-apply[1].\n \n+branch.<name>.remote::\n+\tWhen in branch <name>, it tells `git-fetch` which remote to fetch.\n+\n+branch.<name>.merge::\n+\tWhen in branch <name>, it tells `git-pull` to merge this remote\n+\tbranch of the repository branch.<name>.remote. To specify a different\n+\tremote repository use the from `<branch> from <repo>`.\n+\n+branch.<name>.octopus::\n+\tWhen in branch <name>, the same as pull.octopus.\n+\n+branch.<name>.twohead::\n+\tWhen in branch <name>, the same as pull.twohead.\n+\n diff.color::\n \tWhen true (or `always`), always use colors in patch.\n \tWhen false (or `never`), never.  When set to `auto`, use\ndiff --git a/git-fetch.sh b/git-fetch.sh\nindex c2eebee..8129d8a 100755\n--- a/git-fetch.sh\n+++ b/git-fetch.sh\n@@ -68,11 +68,13 @@ done\n \n case \"$#\" in\n 0)\n-\ttest -f \"$GIT_DIR/branches/origin\" ||\n-\t\ttest -f \"$GIT_DIR/remotes/origin\" ||\n-\t\t\tgit-repo-config --get remote.origin.url >/dev/null ||\n-\t\t\t\tdie \"Where do you want to fetch from today?\"\n-\tset origin ;;\n+\tcurr_branch=$(git-symbolic-ref HEAD)\n+\tcurr_branch=${curr_branch##refs/heads/}\n+\torigin=$(git-repo-config --get \"branch.$curr_branch.remote\")\n+\torigin=${origin:-origin}\n+\ttest -n \"$(get_remote_url $origin)\" ||\n+\t\tdie \"Where do you want to fetch from today?\"\n+\tset $origin ;;\n esac\n \n remote_nick=\"$1\"\n@@ -446,3 +448,4 @@ case \",$update_head_ok,$orig_head,\" in\n \tfi\n \t;;\n esac\n+echo $remote_nick >\"$GIT_DIR/FETCH_REMOTE\"\ndiff --git a/git-parse-remote.sh b/git-parse-remote.sh\nindex 187f088..fe6c713 100755\n--- a/git-parse-remote.sh\n+++ b/git-parse-remote.sh\n@@ -209,3 +209,60 @@ resolve_alternates () {\n \t\tesac\n \tdone\n }\n+\n+get_head_for_remote_branch () {\n+\tif [ \"$1\" == \".\" ];\n+\tthen\n+\t\tgit-rev-parse $2 2>/dev/null||\n+\t\t\tdie \"error: no such ref $2\"\n+\t\treturn\n+\tfi\n+\tdata_source=$(get_data_source \"$1\")\n+\tcase \"$data_source\" in\n+\tconfig)\n+\t\trefspec=$(git-repo-config --get \"remote.$1.fetch\" ^$2:) ;;\n+\tbranches)\n+\t\tremote_branch=$(sed -ne '/#/s/.*#//p' \"$GIT_DIR/branches/$1\")\n+\t\tcase \"$remote_branch\" in '') remote_branch=master ;; esac\n+\t\t[ $remote_branch == $2 ] &&\n+\t\trefspec=\"refs/heads/${remote_branch}:refs/heads/$1\"\n+\t\t;;\n+\tremotes)\n+\t\trefspec=$(grep \"^Pull: $2:\" $GIT_DIR/remotes/$1)\n+\t\trefspec=${refspec##Pull: }\n+\t\t;;\n+\t*)\n+\t\tdie \"internal error: get-head_for_remote_branch\" ;;\n+\tesac\n+\t[ \"$refspec\" ] || die \"Branch $2 does not exist in the repository: $1.\"\n+\tgit-rev-parse $(expr \"z$refspec\" : 'z[^:]*:\\(.*\\)')\n+}\n+\n+get_heads_to_merge_in_branch () {\n+ \tcase \"$#\" in\n+\t2)\n+\t\tdefault=$(git repo-config --get-all \"branch.$1.remote\")\n+\t\t: >\"$GIT_DIR/HEADS_TO_MERGE\"\n+\t\tgit repo-config --get-all \"branch.$1.merge\" |\n+\t\twhile read ref ; do\n+\t\t\tcase $ref in\n+\t\t\t?*' 'from' '?*)\n+\t\t\t\tremote=$(expr \"z$ref\" : 'z.* from \\(.*\\)')\n+\t\t\t\tbranch=$(expr \"z$ref\" : 'z\\(.*\\) from .*');;\n+\t\t\t*)\n+\t\t\t\tremote=$default\n+\t\t\t\tbranch=$ref;;\n+\t\t\tesac\n+\t\t\t[ \"$remote\" != \"$2\" ] && continue\n+\t\t\theadm=$(get_head_for_remote_branch $remote $branch) || exit 1\n+\t\t\techo $headm\n+\t\t\tremoteurl=$(get_remote_url $remote)\n+\t\t\tremoteurl_1=$(expr \"z$remoteurl\" : 'z\\(.*\\)\\.git/*$') &&\n+\t\t\t\tremoteurl=$remoteurl_1\n+\t\t\techo \"$headm\t\tbranch '$branch' of $remoteurl\" \\\n+\t\t\t\t>>\"$GIT_DIR/HEADS_TO_MERGE\"\n+\t\tdone\n+\t\t;;\n+\t*) exit 1\n+\tesac\n+}\ndiff --git a/git-pull.sh b/git-pull.sh\nindex f380437..467d9c0 100755\n--- a/git-pull.sh\n+++ b/git-pull.sh\n@@ -7,6 +7,7 @@ # Fetch one or more remote refs and merg\n USAGE='[-n | --no-summary] [--no-commit] [-s strategy]... [<fetch-options>] <repo> <head>...'\n LONG_USAGE='Fetch one or more remote refs and merge it/them into the current HEAD.'\n . git-sh-setup\n+. git-parse-remote\n \n strategy_args= no_summary= no_commit= squash=\n while case \"$#,$1\" in 0) break ;; *,-*) ;; *) break ;; esac\n@@ -47,6 +48,8 @@ done\n orig_head=$(git-rev-parse --verify HEAD) || die \"Pulling into a black hole?\"\n git-fetch --update-head-ok --reflog-action=pull \"$@\" || exit 1\n \n+curr_branch=$(git-symbolic-ref HEAD)\n+curr_branch=${curr_branch##refs/heads/}\n curr_head=$(git-rev-parse --verify HEAD)\n if test \"$curr_head\" != \"$orig_head\"\n then\n@@ -70,9 +73,18 @@ to recover.'\n \n fi\n \n-merge_head=$(sed -e '/\tnot-for-merge\t/d' \\\n-\t-e 's/\t.*//' \"$GIT_DIR\"/FETCH_HEAD | \\\n-\ttr '\\012' ' ')\n+remote=$(cat \"$GIT_DIR/FETCH_REMOTE\")\n+merge_head=$(get_heads_to_merge_in_branch \"$curr_branch\" \"$remote\" ) || exit\n+\n+if [ -n \"$merge_head\" ];\n+then\n+\tmerge_name=$(git-fmt-merge-msg <\"$GIT_DIR/HEADS_TO_MERGE\") || exit\n+else\n+\tmerge_head=$(sed -e '/\tnot-for-merge\t/d' \\\n+\t\t-e 's/\t.*//' \"$GIT_DIR\"/FETCH_HEAD | \\\n+\t\ttr '\\012' ' ')\n+\tmerge_name=$(git-fmt-merge-msg <\"$GIT_DIR/FETCH_HEAD\") || exit\n+fi\n \n case \"$merge_head\" in\n '')\n@@ -85,6 +97,11 @@ case \"$merge_head\" in\n \tthen\n \t\tstrategy_default_args=\"-s $var\"\n \tfi\n+\tvar=`git-repo-config --get branch.$curr_branch.octopus`\n+\tif test -n \"$var\"\n+\tthen\n+\t\tstrategy_default_args=\"-s $var\"\n+\tfi\n \t;;\n *)\n \tvar=`git-repo-config --get pull.twohead`\n@@ -92,6 +109,11 @@ case \"$merge_head\" in\n         then\n \t\tstrategy_default_args=\"-s $var\"\n \tfi\n+\tvar=`git-repo-config --get branch.$curr_branch.twohead`\n+\tif test -n \"$var\"\n+        then\n+\t\tstrategy_default_args=\"-s $var\"\n+\tfi\n \t;;\n esac\n \n@@ -101,7 +123,6 @@ case \"$strategy_args\" in\n \t;;\n esac\n \n-merge_name=$(git-fmt-merge-msg <\"$GIT_DIR/FETCH_HEAD\") || exit\n git-merge \"--reflog-action=pull $*\" \\\n \t$no_summary $no_commit $squash $strategy_args \\\n \t\"$merge_name\" HEAD $merge_head\n-- \n1.4.2.rc2.g1728\n"},{"id":"24186","messageId":"20060727085516.GC27593@admingilde.org","threadId":"5007","inReplyTo":"87lkqfcvm2.fsf@gmail.com","subject":"Re: [PATCH] Per branch properties for pull and fetch","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2006-07-27T08:55:16Z","receivedAt":"2006-07-27T08:55:16Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"hoi :)\n\nOn Thu, Jul 27, 2006 at 10:14:45AM +0200, Santi Béjar wrote:\n> It allows to specify on a per branch basis the following:\n> .- default repository to fetch\n> .- default branches to merge on a per repository basis\n> .- default pull.{octopus,twohead}\n> \n> So if you have this in the config:\n> [branch \"my\"]\n> \tremote=yours\n> \tmerge=master\n> \tmerge=our from theirs\n> \tmerge=mine from .\n\ncould we default the to-be-merged branch to \"remotes/$remote/$branch\" if\nthat exists?. That could make life a lot easier when using\nclone --use-separate-remote.\n\n-- \nMartin Waitz\n"},{"id":"24189","messageId":"8aa486160607270240h412b0dcek1d57eeb2b254fb2e@mail.gmail.com","threadId":"5007","inReplyTo":"20060727085516.GC27593@admingilde.org","subject":"Re: [PATCH] Per branch properties for pull and fetch","fromName":"Santi","fromEmail":"sbejar@gmail.com","sentAt":"2006-07-27T09:40:37Z","receivedAt":"2006-07-27T09:40:37Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2006/7/27, Martin Waitz <tali@admingilde.org>:\n> hoi :)\n>\n> On Thu, Jul 27, 2006 at 10:14:45AM +0200, Santi Béjar wrote:\n> > It allows to specify on a per branch basis the following:\n> > .- default repository to fetch\n> > .- default branches to merge on a per repository basis\n> > .- default pull.{octopus,twohead}\n> >\n> > So if you have this in the config:\n> > [branch \"my\"]\n> >       remote=yours\n> >       merge=master\n> >       merge=our from theirs\n> >       merge=mine from .\n>\n> could we default the to-be-merged branch to \"remotes/$remote/$branch\" if\n> that exists?. That could make life a lot easier when using\n> clone --use-separate-remote.\n\nI would prefer to change git-clone and git-branch to write the full\nconfig. And I'll do this if this or someting like this is accepted.\n\n  Santi\n"},{"id":"24191","messageId":"8aa486160607270306s3f49a01cq91ef61e2c9f005e@mail.gmail.com","threadId":"5007","inReplyTo":"8aa486160607270240h412b0dcek1d57eeb2b254fb2e@mail.gmail.com","subject":"Re: [PATCH] Per branch properties for pull and fetch","fromName":"Santi","fromEmail":"sbejar@gmail.com","sentAt":"2006-07-27T10:06:34Z","receivedAt":"2006-07-27T10:06:34Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"2006/7/27, Santi <sbejar@gmail.com>:\n> 2006/7/27, Martin Waitz <tali@admingilde.org>:\n> > hoi :)\n> >\n> > On Thu, Jul 27, 2006 at 10:14:45AM +0200, Santi Béjar wrote:\n> > > It allows to specify on a per branch basis the following:\n> > > .- default repository to fetch\n> > > .- default branches to merge on a per repository basis\n> > > .- default pull.{octopus,twohead}\n> > >\n> > > So if you have this in the config:\n> > > [branch \"my\"]\n> > >       remote=yours\n> > >       merge=master\n> > >       merge=our from theirs\n> > >       merge=mine from .\n> >\n> > could we default the to-be-merged branch to \"remotes/$remote/$branch\" if\n> > that exists?. That could make life a lot easier when using\n> > clone --use-separate-remote.\n>\n> I would prefer to change git-clone and git-branch to write the full\n> config. And I'll do this if this or someting like this is accepted.\n>\n\nOn the other hand, my patch changes the behaviour only when explicitly\nconfigured, and your proposed default would change the behaviour even\nwithout changes to the config.\n\nSanti\n"},{"id":"24196","messageId":"20060727120220.GD27593@admingilde.org","threadId":"5007","inReplyTo":"8aa486160607270306s3f49a01cq91ef61e2c9f005e@mail.gmail.com","subject":"Re: [PATCH] Per branch properties for pull and fetch","fromName":"Martin Waitz","fromEmail":"tali@admingilde.org","sentAt":"2006-07-27T12:02:20Z","receivedAt":"2006-07-27T12:02:20Z","isPatch":true,"sender":{"key":"tali@admingilde.org","avatar":"https://gravatar.com/avatar/3f89b03eee362187effabe257898735b475673a12265c398ea9161259ae91553?d=mp&s=160"},"body":"hoi :)\n\nOn Thu, Jul 27, 2006 at 12:06:34PM +0200, Santi wrote:\n> >> could we default the to-be-merged branch to \"remotes/$remote/$branch\" if\n> >> that exists?. That could make life a lot easier when using\n> >> clone --use-separate-remote.\n\n> On the other hand, my patch changes the behaviour only when explicitly\n> configured, and your proposed default would change the behaviour even\n> without changes to the config.\n\nthat is correct.\n\nThe current default is to always use the remote's master branch, right?\nWhat do others think: does it make sense to default to the same\nbranchname on the remote side?\n\nIt could make life a bit easier if you want to synchronize several topic\nbranches between different sites.\n\n-- \nMartin Waitz\n"},{"id":"24200","messageId":"8aa486160607270610q32093546uf28e9982d85edc1a@mail.gmail.com","threadId":"5007","inReplyTo":"20060727120220.GD27593@admingilde.org","subject":"Re: [PATCH] Per branch properties for pull and fetch","fromName":"Santi","fromEmail":"sbejar@gmail.com","sentAt":"2006-07-27T13:10:24Z","receivedAt":"2006-07-27T13:10:24Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"> The current default is to always use the remote's master branch, right?\n\nNo.\n\nFor .git/remotes/ remotes it defaults to the first Pull line.\nFor .git/branches/ remotes if defaults to master, but you can specify\nanother branch.\n\nSanti\n"},{"id":"24253","messageId":"E1G6CRP-0007y4-Jd@moooo.ath.cx","threadId":"5007","inReplyTo":"20060727120220.GD27593@admingilde.org","subject":"Re: [PATCH] Per branch properties for pull and fetch","fromName":"Matthias Lederhofer","fromEmail":"matled@gmx.net","sentAt":"2006-07-27T20:26:43Z","receivedAt":"2006-07-27T20:26:43Z","isPatch":true,"sender":{"key":"matled@gmx.net","avatar":null},"body":"Martin Waitz <tali@admingilde.org> wrote:\n> The current default is to always use the remote's master branch, right?\n> What do others think: does it make sense to default to the same\n> branchname on the remote side?\nI like the separate-remote option too and having one simple command\nthat pulls the changes from the correct remote branch would be nice.\nIt should do something like\n$ git pull ${1:-origin} $(git-symbolic-ref HEAD | cut -d / -f 3-)\n"}]}