{"thread":{"id":"19667","subject":"Using different protocols for \"pull\" and \"push\".","startedAt":"2009-06-04T23:16:44Z","lastAt":"2009-06-07T09:00:15Z","messageCount":8,"participants":["Nikos Chantziaras","Junio C Hamano","Mike Gaffney","Michael J Gruber","Tay Ray Chuan","Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"115458","messageId":"h09kk8$rb4$1@ger.gmane.org","threadId":"19667","inReplyTo":null,"subject":"Using different protocols for \"pull\" and \"push\".","fromName":"Nikos Chantziaras","fromEmail":"realnc@arcor.de","sentAt":"2009-06-04T23:16:44Z","receivedAt":"2009-06-04T23:16:44Z","isPatch":false,"sender":{"key":"realnc@arcor.de","avatar":null},"body":"Hi.\n\nI wonder if it's possible to setup Git (probably in .git/config) to use \nSSH only for \"git push\" and use the git protocol for \"git pull\".  My \ncurrent configuration is:\n\n[remote \"origin\"]\n         url = ssh://user@project.someserver.net/gitroot/project\n         fetch = +refs/heads/*:refs/remotes/origin/*\n\nIssuing a \"git pull\" command results in pulling using SSH (along with \nasking for a password).  Is there a way to alter the configuration so \nthat a \"pull\" will use git:// instead of ssh:// ?\n"},{"id":"115464","messageId":"7v1vpztsci.fsf@alter.siamese.dyndns.org","threadId":"19667","inReplyTo":"h09kk8$rb4$1@ger.gmane.org","subject":"Re: Using different protocols for \"pull\" and \"push\".","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-06-05T00:52:13Z","receivedAt":"2009-06-05T00:52:13Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nikos Chantziaras <realnc@arcor.de> writes:\n\n> I wonder if it's possible to setup Git (probably in .git/config) to\n> use SSH only for \"git push\" and use the git protocol for \"git pull\".\n\nThe configuration format does not allow it, unfortunately.  We should be\nable to introduce remote.$name.pushurl that is used only for push if\npresent (and fall back to remote.$name.url if there isn't) reasonably\neasily, though.\n"},{"id":"115510","messageId":"4A2933B4.1060209@gmail.com","threadId":"19667","inReplyTo":"h09kk8$rb4$1@ger.gmane.org","subject":"Re: Using different protocols for \"pull\" and \"push\".","fromName":"Mike Gaffney","fromEmail":"mr.gaffo@gmail.com","sentAt":"2009-06-05T15:03:16Z","receivedAt":"2009-06-05T15:03:16Z","isPatch":false,"sender":{"key":"mr.gaffo@gmail.com","avatar":"https://gravatar.com/avatar/5af46a60cbd83f2ddb0c2cf4d02b91db42fd25e2ac568ff0d71f699d852ee79d?d=mp&s=160"},"body":"I typically set up a \"push\" remote when I need to do things like this. \nI've got a few projects where I get confused of which one is origin so I \nprotect myself from pushing accidentally (I have to think for a second \nwhen pushing).\n\n-Mike\n\nNikos Chantziaras wrote:\n> Hi.\n>\n> I wonder if it's possible to setup Git (probably in .git/config) to \n> use SSH only for \"git push\" and use the git protocol for \"git pull\".  \n> My current configuration is:\n>\n> [remote \"origin\"]\n>         url = ssh://user@project.someserver.net/gitroot/project\n>         fetch = +refs/heads/*:refs/remotes/origin/*\n>\n> Issuing a \"git pull\" command results in pulling using SSH (along with \n> asking for a password).  Is there a way to alter the configuration so \n> that a \"pull\" will use git:// instead of ssh:// ?\n>\n> -- \n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"115650","messageId":"1244299395-6605-1-git-send-email-git@drmicha.warpmail.net","threadId":"19667","inReplyTo":"7v1vpztsci.fsf@alter.siamese.dyndns.org","subject":"[WIP/RFC] Allow push and fetch urls to be different","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-06-06T14:43:15Z","receivedAt":"2009-06-06T14:43:15Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"This introduces a config setting remote.$remotename.pushurl which is\nused for pushes only. If absent remote.$remotename.url is used for\npushes and fetches as before.\nThis is useful, for example, in order to to do passwordless fetches\n(remote update) over git: but pushes over ssh.\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\nThis is a working prototype, but I'd like to rfc about the approach before\ncoding further. Do I need to do anything in http-push.c? I don't think so.\n\nThings that would go in a full series:\n* documentation (man pages, maybe manual)\n* tests\n* teach builtin-remote about pushurl\n\n builtin-push.c |   17 +++++++++++++----\n remote.c       |   14 ++++++++++++++\n remote.h       |    4 ++++\n 3 files changed, 31 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-push.c b/builtin-push.c\nindex c869974..7be1239 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -117,6 +117,8 @@ static int do_push(const char *repo, int flags)\n {\n \tint i, errs;\n \tstruct remote *remote = remote_get(repo);\n+\tconst char **url;\n+\tint url_nr;\n \n \tif (!remote) {\n \t\tif (repo)\n@@ -152,9 +154,16 @@ static int do_push(const char *repo, int flags)\n \t\t\tsetup_default_push_refspecs();\n \t}\n \terrs = 0;\n-\tfor (i = 0; i < remote->url_nr; i++) {\n+\tif (remote->pushurl_nr) {\n+\t\turl = remote->pushurl;\n+\t\turl_nr = remote->pushurl_nr;\n+\t} else {\n+\t\turl = remote->url;\n+\t\turl_nr = remote->url_nr;\n+\t}\n+\tfor (i = 0; i < url_nr; i++) {\n \t\tstruct transport *transport =\n-\t\t\ttransport_get(remote, remote->url[i]);\n+\t\t\ttransport_get(remote, url[i]);\n \t\tint err;\n \t\tif (receivepack)\n \t\t\ttransport_set_option(transport,\n@@ -163,14 +172,14 @@ static int do_push(const char *repo, int flags)\n \t\t\ttransport_set_option(transport, TRANS_OPT_THIN, \"yes\");\n \n \t\tif (flags & TRANSPORT_PUSH_VERBOSE)\n-\t\t\tfprintf(stderr, \"Pushing to %s\\n\", remote->url[i]);\n+\t\t\tfprintf(stderr, \"Pushing to %s\\n\", url[i]);\n \t\terr = transport_push(transport, refspec_nr, refspec, flags);\n \t\terr |= transport_disconnect(transport);\n \n \t\tif (!err)\n \t\t\tcontinue;\n \n-\t\terror(\"failed to push some refs to '%s'\", remote->url[i]);\n+\t\terror(\"failed to push some refs to '%s'\", url[i]);\n \t\terrs++;\n \t}\n \treturn !!errs;\ndiff --git a/remote.c b/remote.c\nindex 08a5964..9a0397e 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -106,6 +106,12 @@ static void add_url_alias(struct remote *remote, const char *url)\n \tadd_url(remote, alias_url(url));\n }\n \n+static void add_pushurl(struct remote *remote, const char *pushurl)\n+{\n+\tALLOC_GROW(remote->pushurl, remote->pushurl_nr + 1, remote->pushurl_alloc);\n+\tremote->pushurl[remote->pushurl_nr++] = pushurl;\n+}\n+\n static struct remote *make_remote(const char *name, int len)\n {\n \tstruct remote *ret;\n@@ -379,6 +385,11 @@ static int handle_config(const char *key, const char *value, void *cb)\n \t\tif (git_config_string(&v, key, value))\n \t\t\treturn -1;\n \t\tadd_url(remote, v);\n+\t} else if (!strcmp(subkey, \".pushurl\")) {\n+\t\tconst char *v;\n+\t\tif (git_config_string(&v, key, value))\n+\t\t\treturn -1;\n+\t\tadd_pushurl(remote, v);\n \t} else if (!strcmp(subkey, \".push\")) {\n \t\tconst char *v;\n \t\tif (git_config_string(&v, key, value))\n@@ -424,6 +435,9 @@ static void alias_all_urls(void)\n \t\tfor (j = 0; j < remotes[i]->url_nr; j++) {\n \t\t\tremotes[i]->url[j] = alias_url(remotes[i]->url[j]);\n \t\t}\n+\t\tfor (j = 0; j < remotes[i]->pushurl_nr; j++) {\n+\t\t\tremotes[i]->pushurl[j] = alias_url(remotes[i]->pushurl[j]);\n+\t\t}\n \t}\n }\n \ndiff --git a/remote.h b/remote.h\nindex 257a555..5db8420 100644\n--- a/remote.h\n+++ b/remote.h\n@@ -15,6 +15,10 @@ struct remote {\n \tint url_nr;\n \tint url_alloc;\n \n+\tconst char **pushurl;\n+\tint pushurl_nr;\n+\tint pushurl_alloc;\n+\n \tconst char **push_refspec;\n \tstruct refspec *push;\n \tint push_refspec_nr;\n-- \n1.6.3.2.277.gd10543\n"},{"id":"115655","messageId":"be6fef0d0906060750u2da77229p59f21b59d0aef4d2@mail.gmail.com","threadId":"19667","inReplyTo":"1244299395-6605-1-git-send-email-git@drmicha.warpmail.net","subject":"Re: [WIP/RFC] Allow push and fetch urls to be different","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2009-06-06T14:50:15Z","receivedAt":"2009-06-06T14:50:15Z","isPatch":false,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Sat, Jun 6, 2009 at 10:43 PM, Michael J\nGruber<git@drmicha.warpmail.net> wrote:\n> This is a working prototype, but I'd like to rfc about the approach before\n> coding further. Do I need to do anything in http-push.c? I don't think so.\n\nAs long as you're \"controlling\" the url before it gets used (like\nyou're doing now in builtin-push.c), you don't have to bother about\nhttp-push.c.\n\n-- \nCheers,\nRay Chuan\n"},{"id":"115660","messageId":"alpine.LFD.2.01.0906061057160.6847@localhost.localdomain","threadId":"19667","inReplyTo":"1244299395-6605-1-git-send-email-git@drmicha.warpmail.net","subject":"Re: [WIP/RFC] Allow push and fetch urls to be different","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-06-06T17:57:55Z","receivedAt":"2009-06-06T17:57:55Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Sat, 6 Jun 2009, Michael J Gruber wrote:\n>\n> This introduces a config setting remote.$remotename.pushurl which is\n> used for pushes only. If absent remote.$remotename.url is used for\n> pushes and fetches as before.\n\nAck, looks sane to me. \n\n\t\t\tLinus\n"},{"id":"115685","messageId":"7vtz2sbrqh.fsf@alter.siamese.dyndns.org","threadId":"19667","inReplyTo":"1244299395-6605-1-git-send-email-git@drmicha.warpmail.net","subject":"Re: [WIP/RFC] Allow push and fetch urls to be different","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-06-07T04:19:34Z","receivedAt":"2009-06-07T04:19:34Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> This introduces a config setting remote.$remotename.pushurl which is\n> used for pushes only. If absent remote.$remotename.url is used for\n> pushes and fetches as before.\n> This is useful, for example, in order to to do passwordless fetches\n> (remote update) over git: but pushes over ssh.\n>\n> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n> ---\n> This is a working prototype, but I'd like to rfc about the approach before\n> coding further.\n\nAs I am guilty for suggesting this, obviously I do not have a problem with\nwhat the patch wants to achieve.\n\nAnd the change looks simple, straightforward and correct.\n\n> Things that would go in a full series:\n> * documentation (man pages, maybe manual)\n> * tests\n\nSurely.\n\n> * teach builtin-remote about pushurl\n\nHmm,...  my impression was that \"git remote\" does not have much support\nfor the push side.  What kind of things are you going to teach?\n"},{"id":"115690","messageId":"4A2B819F.8010907@drmicha.warpmail.net","threadId":"19667","inReplyTo":"7vtz2sbrqh.fsf@alter.siamese.dyndns.org","subject":"Re: [WIP/RFC] Allow push and fetch urls to be different","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2009-06-07T09:00:15Z","receivedAt":"2009-06-07T09:00:15Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Junio C Hamano venit, vidit, dixit 07.06.2009 06:19:\n> Michael J Gruber <git@drmicha.warpmail.net> writes:\n> \n>> This introduces a config setting remote.$remotename.pushurl which is\n>> used for pushes only. If absent remote.$remotename.url is used for\n>> pushes and fetches as before.\n>> This is useful, for example, in order to to do passwordless fetches\n>> (remote update) over git: but pushes over ssh.\n>>\n>> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n>> ---\n>> This is a working prototype, but I'd like to rfc about the approach before\n>> coding further.\n> \n> As I am guilty for suggesting this, obviously I do not have a problem with\n> what the patch wants to achieve.\n> \n> And the change looks simple, straightforward and correct.\n> \n>> Things that would go in a full series:\n>> * documentation (man pages, maybe manual)\n>> * tests\n> \n> Surely.\n> \n>> * teach builtin-remote about pushurl\n> \n> Hmm,...  my impression was that \"git remote\" does not have much support\n> for the push side.  What kind of things are you going to teach?\n\nFirst I was thinking about rm and mv, but that's being taken care of\nautomatically by removing/renaming a config section. This leaves \"remote\nshow $remote\" which should list the pushurls along with the urls.\n\"remote -v\" should probably list urls but not pushurls. I don't plan on\nadding pushurl support to \"remote add\", I think using git config is OK\nfor this setting.\n\nMichael\n"}]}