{"thread":{"id":"49698","subject":"[RFC PATCH] remote: add --fetch option to git remote set-url","startedAt":"2018-10-27T08:09:14Z","lastAt":"2018-12-10T14:15:16Z","messageCount":9,"participants":["Denton Liu","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"361774","messageId":"1d1b0fe85ddd89cf8172e730e8886d5b4a9ea7eb.1540627720.git.liu.denton@gmail.com","threadId":"49698","inReplyTo":null,"subject":"[RFC PATCH] remote: add --fetch option to git remote set-url","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2018-10-27T08:09:07Z","receivedAt":"2018-10-27T08:09:14Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"This adds the --fetch option to `git remote set-url` such that when\nexecuted we move the remote.*.url to remote.*.pushurl and set\nremote.*.url to the given url argument.\n\nFor example, if we have the following config:\n\n\t[remote \"origin\"]\n\t\turl = git@github.com:git/git.git\n\n`git remote set-url --fetch origin https://github.com/git/git.git`\nwould change the config to the following:\n\n\t[remote \"origin\"]\n\t\turl = https://github.com/git/git.git\n\t\tpushurl = git@github.com:git/git.git\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\nSigned-off-by: Filip Francetic <f.francet@hotmail.com>\n---\n builtin/remote.c | 42 ++++++++++++++++++++++++++++++++++--------\n 1 file changed, 34 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex f7edf7f2c..fcf1220c6 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -23,9 +23,9 @@ static const char * const builtin_remote_usage[] = {\n \tN_(\"git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]\"),\n \tN_(\"git remote set-branches [--add] <name> <branch>...\"),\n \tN_(\"git remote get-url [--push] [--all] <name>\"),\n-\tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n-\tN_(\"git remote set-url --add <name> <newurl>\"),\n-\tN_(\"git remote set-url --delete <name> <url>\"),\n+\tN_(\"git remote set-url [--push|--fetch] <name> <newurl> [<oldurl>]\"),\n+\tN_(\"git remote set-url --add [--push|--fetch] <name> <newurl>\"),\n+\tN_(\"git remote set-url --delete [--push|--fetch] <name> <url>\"),\n \tNULL\n };\n \n@@ -76,9 +76,9 @@ static const char * const builtin_remote_geturl_usage[] = {\n };\n \n static const char * const builtin_remote_seturl_usage[] = {\n-\tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n-\tN_(\"git remote set-url --add <name> <newurl>\"),\n-\tN_(\"git remote set-url --delete <name> <url>\"),\n+\tN_(\"git remote set-url [--push|--fetch] <name> <newurl> [<oldurl>]\"),\n+\tN_(\"git remote set-url --add [--push|--fetch] <name> <newurl>\"),\n+\tN_(\"git remote set-url --delete [--push|--fetch] <name> <url>\"),\n \tNULL\n };\n \n@@ -1519,7 +1519,7 @@ static int get_url(int argc, const char **argv)\n \n static int set_url(int argc, const char **argv)\n {\n-\tint i, push_mode = 0, add_mode = 0, delete_mode = 0;\n+\tint i, push_mode = 0, fetch_mode = 0, add_mode = 0, delete_mode = 0, move_fetch_to_push = 0;\n \tint matches = 0, negative_matches = 0;\n \tconst char *remotename = NULL;\n \tconst char *newurl = NULL;\n@@ -1532,6 +1532,8 @@ static int set_url(int argc, const char **argv)\n \tstruct option options[] = {\n \t\tOPT_BOOL('\\0', \"push\", &push_mode,\n \t\t\t N_(\"manipulate push URLs\")),\n+\t\tOPT_BOOL('\\0', \"fetch\", &fetch_mode,\n+\t\t\t N_(\"manipulate fetch URLs\")),\n \t\tOPT_BOOL('\\0', \"add\", &add_mode,\n \t\t\t N_(\"add URL\")),\n \t\tOPT_BOOL('\\0', \"delete\", &delete_mode,\n@@ -1543,6 +1545,8 @@ static int set_url(int argc, const char **argv)\n \n \tif (add_mode && delete_mode)\n \t\tdie(_(\"--add --delete doesn't make sense\"));\n+\tif (push_mode && fetch_mode)\n+\t\tdie(_(\"--push --fetch doesn't make sense\"));\n \n \tif (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))\n \t\tusage_with_options(builtin_remote_seturl_usage, options);\n@@ -1559,18 +1563,40 @@ static int set_url(int argc, const char **argv)\n \tif (!remote_is_configured(remote, 1))\n \t\tdie(_(\"No such remote '%s'\"), remotename);\n \n+\t/*\n+\t * If add_mode, we will be appending to remote.*.url so we shouldn't move the urls over.\n+\t * If pushurls exist, we don't need to move the urls over to pushurl.\n+\t */\n+\tmove_fetch_to_push = fetch_mode && !add_mode && !remote->pushurl_nr;\n+\n \tif (push_mode) {\n \t\tstrbuf_addf(&name_buf, \"remote.%s.pushurl\", remotename);\n \t\turlset = remote->pushurl;\n \t\turlset_nr = remote->pushurl_nr;\n \t} else {\n+\t\tif (move_fetch_to_push) {\n+\t\t\tstrbuf_addf(&name_buf, \"remote.%s.pushurl\", remotename);\n+\t\t\tfor (i = 0; i < remote->url_nr; i++) {\n+\t\t\t\tgit_config_set_multivar(name_buf.buf, remote->url[i],\n+\t\t\t\t\t\t\"^$\", 0);\n+\t\t\t}\n+\t\t\tstrbuf_reset(&name_buf);\n+\t\t}\n+\n \t\tstrbuf_addf(&name_buf, \"remote.%s.url\", remotename);\n \t\turlset = remote->url;\n \t\turlset_nr = remote->url_nr;\n \t}\n \n+\t/* Empty fetch URLs if they are being replaced */\n+\tif (move_fetch_to_push) {\n+\t\tfor (i = 0; i < remote->url_nr; i++) {\n+\t\t\tgit_config_set_multivar(name_buf.buf, NULL, remote->url[i], 1);\n+\t\t}\n+\t}\n+\n \t/* Special cases that add new entry. */\n-\tif ((!oldurl && !delete_mode) || add_mode) {\n+\tif ((!oldurl && !delete_mode) || move_fetch_to_push || add_mode) {\n \t\tif (add_mode)\n \t\t\tgit_config_set_multivar(name_buf.buf, newurl,\n \t\t\t\t\t\t       \"^$\", 0);\n-- \n2.19.1.542.gc4df23f79.dirty\n\n"},{"id":"361878","messageId":"xmqqftwp47nb.fsf@gitster-ct.c.googlers.com","threadId":"49698","inReplyTo":"1d1b0fe85ddd89cf8172e730e8886d5b4a9ea7eb.1540627720.git.liu.denton@gmail.com","subject":"Re: [RFC PATCH] remote: add --fetch option to git remote set-url","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-10-29T05:57:28Z","receivedAt":"2018-10-29T05:57:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Denton Liu <liu.denton@gmail.com> writes:\n\n> This adds the --fetch option to `git remote set-url` such that when\n> executed we move the remote.*.url to remote.*.pushurl and set\n> remote.*.url to the given url argument.\n>\n\nI suspect this is a horrible idea from end-user's point of view.\n\"set-url --push\" is used to SET pushURL instead of setting URL and\ndoes not MOVE anything.  Why should the end user expect and remember\n\"set-url --fetch\" works very differently?  \n\nIf there is a need for a \"--move-URL-to-pushURL-and-set-pushURL\"\nshort-hand to avoid having to use two commands\n\n\tgit remote set-url --push $(git remote --get-url origin) origin\n\tgit remote set-url $there origin\n\nit should not be called \"--fetch\", which has a strong connotation of\nbeing an opposite of existing \"--push\", but something else.  And\nthen we need to ask ourselves if we also need such a short-hand to\n\"--move-pushURL-to-URL-and-set-URL\" operation.  The answer to the\nlast question would help us decide if (1) this combined operation is\na good idea to begin with and (2) what is the good name for such an\noperation.\n\nAssuming that the short-hand operation is a good idea in the first\nplace, without deciding what the externally visible good name for it\nis, let's read on.\n\n> +\t/*\n> +\t * If add_mode, we will be appending to remote.*.url so we shouldn't move the urls over.\n> +\t * If pushurls exist, we don't need to move the urls over to pushurl.\n> +\t */\n> +\tmove_fetch_to_push = fetch_mode && !add_mode && !remote->pushurl_nr;\n\nShould this kind of \"the user asked for --fetch, but sometimes it is\nnot appropriate to honor that request\" be done silently like this?\n\nEarlier you had a check like this:\n\n> +\tif (push_mode && fetch_mode)\n> +\t\tdie(_(\"--push --fetch doesn't make sense\"));\n\nIf a request to \"--fetch\" is ignored when \"--add\" is given, for\nexample, shouldn't the combination also be diagnosed as \"not making\nsense, we'd ignore your wish to use the --fetch option\"?  Similarly\nfor the case where there already is pushurl defined for the remote.\n\nThis is a different tangent on the same line, but it could be that\nthe user wants to have two (or more) pushURLs because the user wants\nto push to two remotes at the same time with \"git push this-remote\",\nso silently ignoring \"--force\" may not be the right thing in the\nfirst place.  We may instead need to make the value of URL to an\nextra pushURL entry (if we had one, we now have two).\n\n"},{"id":"361970","messageId":"20181030075653.GA4114@archbookpro.localdomain","threadId":"49698","inReplyTo":"xmqqftwp47nb.fsf@gitster-ct.c.googlers.com","subject":"Re: [RFC PATCH] remote: add --fetch option to git remote set-url","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2018-10-30T07:56:53Z","receivedAt":"2018-10-30T07:56:58Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"On Mon, Oct 29, 2018 at 02:57:28PM +0900, Junio C Hamano wrote:\n> Denton Liu <liu.denton@gmail.com> writes:\n> \n> > This adds the --fetch option to `git remote set-url` such that when\n> > executed we move the remote.*.url to remote.*.pushurl and set\n> > remote.*.url to the given url argument.\n> >\n> \n> I suspect this is a horrible idea from end-user's point of view.\n> \"set-url --push\" is used to SET pushURL instead of setting URL and\n> does not MOVE anything.  Why should the end user expect and remember\n> \"set-url --fetch\" works very differently?  \n>\n\nI agree, `--fetch` is a terrible name for this. Perhaps a better name\nwould be something like `--fetch-behavior` or `--keep-push` so that the\nbehaviour is more transparent for the end-user. Either way, I think we\ncan decide on the name later.\n\n> If there is a need for a \"--move-URL-to-pushURL-and-set-pushURL\"\n> short-hand to avoid having to use two commands\n> \n> \tgit remote set-url --push $(git remote --get-url origin) origin\n> \tgit remote set-url $there origin\n> \n> it should not be called \"--fetch\", which has a strong connotation of\n> being an opposite of existing \"--push\", but something else.  And\n> then we need to ask ourselves if we also need such a short-hand to\n> \"--move-pushURL-to-URL-and-set-URL\" operation.  The answer to the\n> last question would help us decide if (1) this combined operation is\n> a good idea to begin with and (2) what is the good name for such an\n> operation.\n> \n> Assuming that the short-hand operation is a good idea in the first\n> place, without deciding what the externally visible good name for it\n> is, let's read on.\n> \n> > +\t/*\n> > +\t * If add_mode, we will be appending to remote.*.url so we shouldn't move the urls over.\n> > +\t * If pushurls exist, we don't need to move the urls over to pushurl.\n> > +\t */\n> > +\tmove_fetch_to_push = fetch_mode && !add_mode && !remote->pushurl_nr;\n> \n> Should this kind of \"the user asked for --fetch, but sometimes it is\n> not appropriate to honor that request\" be done silently like this?\n> \n> Earlier you had a check like this:\n> \n> > +\tif (push_mode && fetch_mode)\n> > +\t\tdie(_(\"--push --fetch doesn't make sense\"));\n> \n> If a request to \"--fetch\" is ignored when \"--add\" is given, for\n> example, shouldn't the combination also be diagnosed as \"not making\n> sense, we'd ignore your wish to use the --fetch option\"?  Similarly\n> for the case where there already is pushurl defined for the remote.\n> \n> This is a different tangent on the same line, but it could be that\n> the user wants to have two (or more) pushURLs because the user wants\n> to push to two remotes at the same time with \"git push this-remote\",\n> so silently ignoring \"--force\" may not be the right thing in the\n> first place.  We may instead need to make the value of URL to an\n> extra pushURL entry (if we had one, we now have two).\n>\n\nPerhaps I should motivate the use-case for this option. There have been\ntimes when I've had the URL set to something but no pushURL. I've\nwanted to only change the fetching URL and keep the pushing URL the same\nbut unfortunately, there's no way to do that because of the url/pushurl\nsplit is set up.\n\nMy implementation of --fetch is supposed to emulate what would happen if\ngit were implemented with fetchurl/pushurl instead. Does the patch make\nmore sense in this context?\n\nPlease let me know if you think that the concept behind this patch is a\ngood idea. Thanks!\n"},{"id":"361977","messageId":"xmqq8t2f218l.fsf@gitster-ct.c.googlers.com","threadId":"49698","inReplyTo":"20181030075653.GA4114@archbookpro.localdomain","subject":"Re: [RFC PATCH] remote: add --fetch option to git remote set-url","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-10-30T10:11:06Z","receivedAt":"2018-10-30T10:11:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Denton Liu <liu.denton@gmail.com> writes:\n\n> On Mon, Oct 29, 2018 at 02:57:28PM +0900, Junio C Hamano wrote:\n> ...\n>> Earlier you had a check like this:\n>> \n>> > +\tif (push_mode && fetch_mode)\n>> > +\t\tdie(_(\"--push --fetch doesn't make sense\"));\n>> \n>> If a request to \"--fetch\" is ignored when \"--add\" is given, for\n>> example, shouldn't the combination also be diagnosed as \"not making\n>> sense, we'd ignore your wish to use the --fetch option\"?  Similarly\n>> for the case where there already is pushurl defined for the remote.\n\nClarification.  Here I am suggesting that a part of the logic in the\nearlier assignment to move_fetch_to_push should become a similar\ncall to die(), detecting a competing and unsatisfiable wish, rather\nthan getting silently ignored.\n\n>> This is a different tangent on the same line, but it could be that\n>> the user wants to have two (or more) pushURLs because the user wants\n>> to push to two remotes at the same time with \"git push this-remote\",\n>> so silently ignoring \"--force\" may not be the right thing in the\n\nCorrection.  s/--force/--fetch/ was what I meant here.\n\n>> first place.  We may instead need to make the value of URL to an\n>> extra pushURL entry (if we had one, we now have two).\n\nAlso, additionally, since there is no use to have two or more URL,\nbecause unlike \"git push $there\" that can push to two places,\nfetching from two places into the same set of remote-tracking\nbranches would not make sense, --move-pushURL-to-URL-and-set-pushURL\noperation that is the symmetry of what the patch under discussion\nproposes should fail instead of creating an extra URL entry, breaking\nan apparent symmetry.\n\n> Perhaps I should motivate the use-case for this option. There have been\n> times when I've had the URL set to something but no pushURL. I've\n> wanted to only change the fetching URL and keep the pushing URL the same\n\nURL (plus optionally pushURL) split was done because most everybody\nwere fetching from and pushing to the same place; it would not have\nmade any sense to have fetchURL and pushURL that are separate, as\nthat would have forced everybody to have both, when majority of the\nusers would have to set them to the same value.\n\nQuite honestly, tweaking URL and/or pushURL is not something you'd\ndo every three months or more frequently, so I do not particularly\nfeel sympathetic to the cause of this patch, which would allow\nsetting one to the value that happens to be set to the other one\nwhile setting an arbitrary new value to the other one.  Once the\nuser's need deviates from that single niche pattern, the user needs\nto update both, and setting these two independently is quite simple\nand straight-forward in the first place.  And that same simple pattern\nto set two independently can be used without learning this new option.\n\n> My implementation of --fetch is supposed to emulate what would happen if\n> git were implemented with fetchurl/pushurl instead. Does the patch make\n> more sense in this context?\n\nHmph.  As a system that has fetchURL and pushURL independently and\nforces everybody to set both does not make much sense in the first\nplace, the patch making sense in that context is not a very strong\nreason to support it.\n\n> Please let me know if you think that the concept behind this patch is a\n> good idea. Thanks!\n\nIf I don't then I do not have to let you know, then ;-) \n\nI do not particularly think it is a horrible idea, but I do not see\nthat it would be a feature that helps particuarly wide audience.\n"},{"id":"362766","messageId":"b910987d3aa778b39b6e27a75fe685a4797b8422.1541730538.git.liu.denton@gmail.com","threadId":"49698","inReplyTo":"xmqq8t2f218l.fsf@gitster-ct.c.googlers.com","subject":"[RFC PATCH v2] remote: add --save-push option to git remote set-url","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2018-11-09T02:37:45Z","receivedAt":"2018-11-09T02:37:51Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"This adds the --save-push option to `git remote set-url` such that when\nexecuted, we move the remote.*.url to remote.*.pushurl and set\nremote.*.url to the given url argument.\n\nFor example, if we have the following config:\n\n\t[remote \"origin\"]\n\t\turl = git@github.com:git/git.git\n\n`git remote set-url --save-push origin https://github.com/git/git.git`\nwould change the config to the following:\n\n\t[remote \"origin\"]\n\t\turl = https://github.com/git/git.git\n\t\tpushurl = git@github.com:git/git.git\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\nI decided to address your comments and reroll the patch one more time. \n\nEven though the option isn't _that_ commonly used, I've managed to use\nit a couple of times since I've implemented so I believe that this\noption should be included.\n\n---\n Documentation/git-remote.txt |  5 +++++\n builtin/remote.c             | 25 ++++++++++++++++++++-----\n 2 files changed, 25 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt\nindex 0cad37fb81..8ce85fe2f2 100644\n--- a/Documentation/git-remote.txt\n+++ b/Documentation/git-remote.txt\n@@ -19,6 +19,7 @@ SYNOPSIS\n 'git remote set-url' [--push] <name> <newurl> [<oldurl>]\n 'git remote set-url --add' [--push] <name> <newurl>\n 'git remote set-url --delete' [--push] <name> <url>\n+'git remote set-url --save-push' <name> <url>\n 'git remote' [-v | --verbose] 'show' [-n] <name>...\n 'git remote prune' [-n | --dry-run] <name>...\n 'git remote' [-v | --verbose] 'update' [-p | --prune] [(<group> | <remote>)...]\n@@ -155,6 +156,10 @@ With `--delete`, instead of changing existing URLs, all URLs matching\n regex <url> are deleted for remote <name>.  Trying to delete all\n non-push URLs is an error.\n +\n+With `--save-push`, the current URL is saved into the push URL before setting\n+the URL to <url>. Note that this command will not work if more than one URL is\n+defined or if any push URLs are defined because behavior would be ambiguous.\n++\n Note that the push URL and the fetch URL, even though they can\n be set differently, must still refer to the same place.  What you\n pushed to the push URL should be what you would see if you\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex f7edf7f2cb..0eaec7ef38 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -24,8 +24,9 @@ static const char * const builtin_remote_usage[] = {\n \tN_(\"git remote set-branches [--add] <name> <branch>...\"),\n \tN_(\"git remote get-url [--push] [--all] <name>\"),\n \tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n-\tN_(\"git remote set-url --add <name> <newurl>\"),\n-\tN_(\"git remote set-url --delete <name> <url>\"),\n+\tN_(\"git remote set-url --add [--push] <name> <newurl>\"),\n+\tN_(\"git remote set-url --delete [--push] <name> <url>\"),\n+\tN_(\"git remote set-url --save-push <name> <url>\"),\n \tNULL\n };\n \n@@ -77,8 +78,9 @@ static const char * const builtin_remote_geturl_usage[] = {\n \n static const char * const builtin_remote_seturl_usage[] = {\n \tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n-\tN_(\"git remote set-url --add <name> <newurl>\"),\n-\tN_(\"git remote set-url --delete <name> <url>\"),\n+\tN_(\"git remote set-url --add [--push] <name> <newurl>\"),\n+\tN_(\"git remote set-url --delete [--push] <name> <url>\"),\n+\tN_(\"git remote set-url --save-push <name> <url>\"),\n \tNULL\n };\n \n@@ -1519,7 +1521,7 @@ static int get_url(int argc, const char **argv)\n \n static int set_url(int argc, const char **argv)\n {\n-\tint i, push_mode = 0, add_mode = 0, delete_mode = 0;\n+\tint i, push_mode = 0, save_push = 0, add_mode = 0, delete_mode = 0;\n \tint matches = 0, negative_matches = 0;\n \tconst char *remotename = NULL;\n \tconst char *newurl = NULL;\n@@ -1532,6 +1534,8 @@ static int set_url(int argc, const char **argv)\n \tstruct option options[] = {\n \t\tOPT_BOOL('\\0', \"push\", &push_mode,\n \t\t\t N_(\"manipulate push URLs\")),\n+\t\tOPT_BOOL('\\0', \"save-push\", &save_push,\n+\t\t\t N_(\"change fetching URL behavior\")),\n \t\tOPT_BOOL('\\0', \"add\", &add_mode,\n \t\t\t N_(\"add URL\")),\n \t\tOPT_BOOL('\\0', \"delete\", &delete_mode,\n@@ -1543,6 +1547,8 @@ static int set_url(int argc, const char **argv)\n \n \tif (add_mode && delete_mode)\n \t\tdie(_(\"--add --delete doesn't make sense\"));\n+\tif (save_push && (push_mode || add_mode || delete_mode))\n+\t\tdie(_(\"--save-push cannot be used with other options\"));\n \n \tif (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))\n \t\tusage_with_options(builtin_remote_seturl_usage, options);\n@@ -1564,6 +1570,15 @@ static int set_url(int argc, const char **argv)\n \t\turlset = remote->pushurl;\n \t\turlset_nr = remote->pushurl_nr;\n \t} else {\n+\t\tif (save_push) {\n+\t\t\tif (remote->url_nr != 1 || remote->pushurl_nr != 0)\n+\t\t\t\tdie(_(\"--save-push can only be used when one url and no pushurl is defined\"), remotename);\n+\n+\t\t\tstrbuf_addf(&name_buf, \"remote.%s.pushurl\", remotename);\n+\t\t\tgit_config_set(name_buf.buf, remote->url[0]);\n+\t\t\tstrbuf_reset(&name_buf);\n+\t\t}\n+\n \t\tstrbuf_addf(&name_buf, \"remote.%s.url\", remotename);\n \t\turlset = remote->url;\n \t\turlset_nr = remote->url_nr;\n-- \n2.19.1\n\n"},{"id":"362771","messageId":"xmqqin1754c5.fsf@gitster-ct.c.googlers.com","threadId":"49698","inReplyTo":"b910987d3aa778b39b6e27a75fe685a4797b8422.1541730538.git.liu.denton@gmail.com","subject":"Re: [RFC PATCH v2] remote: add --save-push option to git remote set-url","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-11-09T03:15:22Z","receivedAt":"2018-11-09T03:15:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Denton Liu <liu.denton@gmail.com> writes:\n\n> This adds the --save-push option to `git remote set-url` such that when\n> executed, we move the remote.*.url to remote.*.pushurl and set\n> remote.*.url to the given url argument.\n>\n> For example, if we have the following config:\n>\n> \t[remote \"origin\"]\n> \t\turl = git@github.com:git/git.git\n>\n> `git remote set-url --save-push origin https://github.com/git/git.git`\n> would change the config to the following:\n>\n> \t[remote \"origin\"]\n> \t\turl = https://github.com/git/git.git\n> \t\tpushurl = git@github.com:git/git.git\n\nThis sounds more like \"saving to push\" (i.e. what you are saving is\nthe existing \"url\" and the \"push\" is a shorthand for \"pushURL\",\nwhich is the location the old value of \"url\" is aved to), not \"save\n(the) push(URL)\".  So if adding this option makes sense, I would say\n\"--save-to-push\" (or even \"--save-to-pushURL\") may be a more\nappropriate name for it.\n\n> +With `--save-push`, the current URL is saved into the push URL before setting\n> +the URL to <url>. Note that this command will not work if more than one URL is\n> +defined or if any push URLs are defined because behavior would be ambiguous.\n\nAmbigous in what way?  You asked the current URL to be saved as a\npushURL, so existing pushURL destinations should not come into play,\nI would think.  If there are more than one URL (not pushURL), on the\nother hand, I think you have a bigger problem (where would \"git fetch\"\nfetch from, and how would these multiple URLs are prevented from\ntrashing refs/remotes/$remote/* with each other's refs?), so\nstopping the operation before \"set-url\" makes the problem worse is\nprobably a good idea, but I think that is true with or without this\nnew option.\n\n> diff --git a/builtin/remote.c b/builtin/remote.c\n> index f7edf7f2cb..0eaec7ef38 100644\n> --- a/builtin/remote.c\n> +++ b/builtin/remote.c\n> @@ -24,8 +24,9 @@ static const char * const builtin_remote_usage[] = {\n>  \tN_(\"git remote set-branches [--add] <name> <branch>...\"),\n>  \tN_(\"git remote get-url [--push] [--all] <name>\"),\n>  \tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n> -\tN_(\"git remote set-url --add <name> <newurl>\"),\n> -\tN_(\"git remote set-url --delete <name> <url>\"),\n> +\tN_(\"git remote set-url --add [--push] <name> <newurl>\"),\n> +\tN_(\"git remote set-url --delete [--push] <name> <url>\"),\n> +\tN_(\"git remote set-url --save-push <name> <url>\"),\n>  \tNULL\n>  };\n\nNeeds update?\n\n> @@ -77,8 +78,9 @@ static const char * const builtin_remote_geturl_usage[] = {\n>  \n>  static const char * const builtin_remote_seturl_usage[] = {\n>  \tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n> -\tN_(\"git remote set-url --add <name> <newurl>\"),\n> -\tN_(\"git remote set-url --delete <name> <url>\"),\n> +\tN_(\"git remote set-url --add [--push] <name> <newurl>\"),\n> +\tN_(\"git remote set-url --delete [--push] <name> <url>\"),\n> +\tN_(\"git remote set-url --save-push <name> <url>\"),\n>  \tNULL\n>  };\n\nNeeds update?\n\n> +\t\tif (save_push) {\n> +\t\t\tif (remote->url_nr != 1 || remote->pushurl_nr != 0)\n> +\t\t\t\tdie(_(\"--save-push can only be used when one url and no pushurl is defined\"), remotename);\n\nI _think_ in the future (if this option turns out to be widely used)\npeople may ask for this condition to be loosened somewhat, but it is\nrelatively easy to start restrictive and then to loosen later, so I\nthink this is OK for now.\n\n"},{"id":"362777","messageId":"8fded8b84b593497177de740f80b3499c4269758.1541740174.git.liu.denton@gmail.com","threadId":"49698","inReplyTo":"xmqqin1754c5.fsf@gitster-ct.c.googlers.com","subject":"[PATCH v3] remote: add --save-to-push option to git remote set-url","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2018-11-09T05:20:02Z","receivedAt":"2018-11-09T05:20:08Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"This adds the --save-to-push option to `git remote set-url` such that\nwhen executed, we move the remote.*.url to remote.*.pushurl and set\nremote.*.url to the given url argument.\n\nFor example, if we have the following config:\n\n\t[remote \"origin\"]\n\t\turl = git@github.com:git/git.git\n\n`git remote set-url --save-to-push origin https://github.com/git/git.git`\nwould change the config to the following:\n\n\t[remote \"origin\"]\n\t\turl = https://github.com/git/git.git\n\t\tpushurl = git@github.com:git/git.git\n\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\nOn Fri, Nov 09, 2018 at 12:15:22PM +0900, Junio C Hamano wrote:\n> This sounds more like \"saving to push\" (i.e. what you are saving is\n> the existing \"url\" and the \"push\" is a shorthand for \"pushURL\",\n> which is the location the old value of \"url\" is aved to), not \"save\n> (the) push(URL)\".  So if adding this option makes sense, I would say\n> \"--save-to-push\" (or even \"--save-to-pushURL\") may be a more\n> appropriate name for it.\n> \n\nMy original intention was for it to mean \"save push behavior\" but I\nagree with you that it's unclear so I'm changing it to --save-to-push.\n\n> Ambigous in what way?  You asked the current URL to be saved as a\n> pushURL, so existing pushURL destinations should not come into play,\n> I would think.  If there are more than one URL (not pushURL), on the\n> other hand, I think you have a bigger problem (where would \"git fetch\"\n> fetch from, and how would these multiple URLs are prevented from\n> trashing refs/remotes/$remote/* with each other's refs?), so\n> stopping the operation before \"set-url\" makes the problem worse is\n> probably a good idea, but I think that is true with or without this\n> new option.\n> \n\n> I _think_ in the future (if this option turns out to be widely used)\n> people may ask for this condition to be loosened somewhat, but it is\n> relatively easy to start restrictive and then to loosen later, so I\n> think this is OK for now.\n> \n\nI agree, there's no reason why we shouldn't allow appending to the push\nURLs if one already exists so I removed that removed that restriction.\n---\n Documentation/git-remote.txt |  5 +++++\n builtin/remote.c             | 26 +++++++++++++++++++++-----\n t/t5505-remote.sh            | 11 +++++++++++\n 3 files changed, 37 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt\nindex 0cad37fb81..8f9d700252 100644\n--- a/Documentation/git-remote.txt\n+++ b/Documentation/git-remote.txt\n@@ -19,6 +19,7 @@ SYNOPSIS\n 'git remote set-url' [--push] <name> <newurl> [<oldurl>]\n 'git remote set-url --add' [--push] <name> <newurl>\n 'git remote set-url --delete' [--push] <name> <url>\n+'git remote set-url --save-to-push' <name> <url>\n 'git remote' [-v | --verbose] 'show' [-n] <name>...\n 'git remote prune' [-n | --dry-run] <name>...\n 'git remote' [-v | --verbose] 'update' [-p | --prune] [(<group> | <remote>)...]\n@@ -155,6 +156,10 @@ With `--delete`, instead of changing existing URLs, all URLs matching\n regex <url> are deleted for remote <name>.  Trying to delete all\n non-push URLs is an error.\n +\n+With `--save-to-push`, the current URL is saved into the push URL before\n+setting the URL to <url>. Note that this command will not work if more than one\n+URL is defined because the behavior would be ambiguous.\n++\n Note that the push URL and the fetch URL, even though they can\n be set differently, must still refer to the same place.  What you\n pushed to the push URL should be what you would see if you\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex f7edf7f2cb..3249c3face 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -24,8 +24,9 @@ static const char * const builtin_remote_usage[] = {\n \tN_(\"git remote set-branches [--add] <name> <branch>...\"),\n \tN_(\"git remote get-url [--push] [--all] <name>\"),\n \tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n-\tN_(\"git remote set-url --add <name> <newurl>\"),\n-\tN_(\"git remote set-url --delete <name> <url>\"),\n+\tN_(\"git remote set-url --add [--push] <name> <newurl>\"),\n+\tN_(\"git remote set-url --delete [--push] <name> <url>\"),\n+\tN_(\"git remote set-url --save-to-push <name> <url>\"),\n \tNULL\n };\n \n@@ -77,8 +78,9 @@ static const char * const builtin_remote_geturl_usage[] = {\n \n static const char * const builtin_remote_seturl_usage[] = {\n \tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n-\tN_(\"git remote set-url --add <name> <newurl>\"),\n-\tN_(\"git remote set-url --delete <name> <url>\"),\n+\tN_(\"git remote set-url --add [--push] <name> <newurl>\"),\n+\tN_(\"git remote set-url --delete [--push] <name> <url>\"),\n+\tN_(\"git remote set-url --save-to-push <name> <url>\"),\n \tNULL\n };\n \n@@ -1519,7 +1521,7 @@ static int get_url(int argc, const char **argv)\n \n static int set_url(int argc, const char **argv)\n {\n-\tint i, push_mode = 0, add_mode = 0, delete_mode = 0;\n+\tint i, push_mode = 0, save_to_push = 0, add_mode = 0, delete_mode = 0;\n \tint matches = 0, negative_matches = 0;\n \tconst char *remotename = NULL;\n \tconst char *newurl = NULL;\n@@ -1532,6 +1534,8 @@ static int set_url(int argc, const char **argv)\n \tstruct option options[] = {\n \t\tOPT_BOOL('\\0', \"push\", &push_mode,\n \t\t\t N_(\"manipulate push URLs\")),\n+\t\tOPT_BOOL('\\0', \"save-to-push\", &save_to_push,\n+\t\t\t N_(\"change fetching URL behavior\")),\n \t\tOPT_BOOL('\\0', \"add\", &add_mode,\n \t\t\t N_(\"add URL\")),\n \t\tOPT_BOOL('\\0', \"delete\", &delete_mode,\n@@ -1543,6 +1547,8 @@ static int set_url(int argc, const char **argv)\n \n \tif (add_mode && delete_mode)\n \t\tdie(_(\"--add --delete doesn't make sense\"));\n+\tif (save_to_push && (push_mode || add_mode || delete_mode))\n+\t\tdie(_(\"--save-to-push cannot be used with other options\"));\n \n \tif (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))\n \t\tusage_with_options(builtin_remote_seturl_usage, options);\n@@ -1564,6 +1570,16 @@ static int set_url(int argc, const char **argv)\n \t\turlset = remote->pushurl;\n \t\turlset_nr = remote->pushurl_nr;\n \t} else {\n+\t\tif (save_to_push) {\n+\t\t\tif (remote->url_nr != 1)\n+\t\t\t\tdie(_(\"--save-to-push can only be used when only one url is defined\"), remotename);\n+\n+\t\t\tstrbuf_addf(&name_buf, \"remote.%s.pushurl\", remotename);\n+\t\t\tgit_config_set_multivar(name_buf.buf,\n+\t\t\t      remote->url[0], \"^$\", 0);\n+\t\t\tstrbuf_reset(&name_buf);\n+\t\t}\n+\n \t\tstrbuf_addf(&name_buf, \"remote.%s.url\", remotename);\n \t\turlset = remote->url;\n \t\turlset_nr = remote->url_nr;\ndiff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\nindex d2a2cdd453..434c1f828a 100755\n--- a/t/t5505-remote.sh\n+++ b/t/t5505-remote.sh\n@@ -1194,6 +1194,17 @@ test_expect_success 'remote set-url --delete baz' '\n \tcmp expect actual\n '\n \n+test_expect_success 'remote set-url --save-to-push bbb' '\n+\tgit remote set-url --save-to-push someremote bbb &&\n+\techo bbb >expect &&\n+\techo \"YYY\" >>expect &&\n+\techo ccc >>expect &&\n+\tgit config --get-all remote.someremote.url >actual &&\n+\techo \"YYY\" >>actual &&\n+\tgit config --get-all remote.someremote.pushurl >>actual &&\n+\tcmp expect actual\n+'\n+\n test_expect_success 'extra args: setup' '\n \t# add a dummy origin so that this does not trigger failure\n \tgit remote add origin .\n-- \n2.19.1\n\n"},{"id":"363139","messageId":"xmqqy39xux6n.fsf@gitster-ct.c.googlers.com","threadId":"49698","inReplyTo":"8fded8b84b593497177de740f80b3499c4269758.1541740174.git.liu.denton@gmail.com","subject":"Re: [PATCH v3] remote: add --save-to-push option to git remote set-url","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-11-13T09:46:40Z","receivedAt":"2018-11-13T09:46:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Denton Liu <liu.denton@gmail.com> writes:\n\n> This adds the --save-to-push option to `git remote set-url` such that\n> when executed, we move the remote.*.url to remote.*.pushurl and set\n> remote.*.url to the given url argument.\n>\n> For example, if we have the following config:\n>\n> \t[remote \"origin\"]\n> \t\turl = git@github.com:git/git.git\n>\n> `git remote set-url --save-to-push origin https://github.com/git/git.git`\n> would change the config to the following:\n>\n> \t[remote \"origin\"]\n> \t\turl = https://github.com/git/git.git\n> \t\tpushurl = git@github.com:git/git.git\n>\n> Signed-off-by: Denton Liu <liu.denton@gmail.com>\n> ---\n> On Fri, Nov 09, 2018 at 12:15:22PM +0900, Junio C Hamano wrote:\n>> This sounds more like \"saving to push\" (i.e. what you are saving is\n>> the existing \"url\" and the \"push\" is a shorthand for \"pushURL\",\n>> which is the location the old value of \"url\" is aved to), not \"save\n>> (the) push(URL)\".  So if adding this option makes sense, I would say\n>> \"--save-to-push\" (or even \"--save-to-pushURL\") may be a more\n>> appropriate name for it.\n>> \n>\n> My original intention was for it to mean \"save push behavior\" but I\n> agree with you that it's unclear so I'm changing it to --save-to-push.\n>\n>> Ambigous in what way?  You asked the current URL to be saved as a\n>> pushURL, so existing pushURL destinations should not come into play,\n>> I would think.  If there are more than one URL (not pushURL), on the\n>> other hand, I think you have a bigger problem (where would \"git fetch\"\n>> fetch from, and how would these multiple URLs are prevented from\n>> trashing refs/remotes/$remote/* with each other's refs?), so\n>> stopping the operation before \"set-url\" makes the problem worse is\n>> probably a good idea, but I think that is true with or without this\n>> new option.\n>> \n>\n>> I _think_ in the future (if this option turns out to be widely used)\n>> people may ask for this condition to be loosened somewhat, but it is\n>> relatively easy to start restrictive and then to loosen later, so I\n>> think this is OK for now.\n>> \n>\n> I agree, there's no reason why we shouldn't allow appending to the push\n> URLs if one already exists so I removed that removed that restriction.\n> ---\n>  Documentation/git-remote.txt |  5 +++++\n>  builtin/remote.c             | 26 +++++++++++++++++++++-----\n>  t/t5505-remote.sh            | 11 +++++++++++\n>  3 files changed, 37 insertions(+), 5 deletions(-)\n>\n> diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt\n> index 0cad37fb81..8f9d700252 100644\n> --- a/Documentation/git-remote.txt\n> +++ b/Documentation/git-remote.txt\n> @@ -19,6 +19,7 @@ SYNOPSIS\n>  'git remote set-url' [--push] <name> <newurl> [<oldurl>]\n>  'git remote set-url --add' [--push] <name> <newurl>\n>  'git remote set-url --delete' [--push] <name> <url>\n> +'git remote set-url --save-to-push' <name> <url>\n>  'git remote' [-v | --verbose] 'show' [-n] <name>...\n>  'git remote prune' [-n | --dry-run] <name>...\n>  'git remote' [-v | --verbose] 'update' [-p | --prune] [(<group> | <remote>)...]\n> @@ -155,6 +156,10 @@ With `--delete`, instead of changing existing URLs, all URLs matching\n>  regex <url> are deleted for remote <name>.  Trying to delete all\n>  non-push URLs is an error.\n>  +\n> +With `--save-to-push`, the current URL is saved into the push URL before\n> +setting the URL to <url>. Note that this command will not work if more than one\n> +URL is defined because the behavior would be ambiguous.\n> ++\n>  Note that the push URL and the fetch URL, even though they can\n>  be set differently, must still refer to the same place.  What you\n>  pushed to the push URL should be what you would see if you\n> diff --git a/builtin/remote.c b/builtin/remote.c\n> index f7edf7f2cb..3249c3face 100644\n> --- a/builtin/remote.c\n> +++ b/builtin/remote.c\n> @@ -24,8 +24,9 @@ static const char * const builtin_remote_usage[] = {\n>  \tN_(\"git remote set-branches [--add] <name> <branch>...\"),\n>  \tN_(\"git remote get-url [--push] [--all] <name>\"),\n>  \tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n> -\tN_(\"git remote set-url --add <name> <newurl>\"),\n> -\tN_(\"git remote set-url --delete <name> <url>\"),\n> +\tN_(\"git remote set-url --add [--push] <name> <newurl>\"),\n> +\tN_(\"git remote set-url --delete [--push] <name> <url>\"),\n> +\tN_(\"git remote set-url --save-to-push <name> <url>\"),\n>  \tNULL\n>  };\n>  \n> @@ -77,8 +78,9 @@ static const char * const builtin_remote_geturl_usage[] = {\n>  \n>  static const char * const builtin_remote_seturl_usage[] = {\n>  \tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n> -\tN_(\"git remote set-url --add <name> <newurl>\"),\n> -\tN_(\"git remote set-url --delete <name> <url>\"),\n> +\tN_(\"git remote set-url --add [--push] <name> <newurl>\"),\n> +\tN_(\"git remote set-url --delete [--push] <name> <url>\"),\n> +\tN_(\"git remote set-url --save-to-push <name> <url>\"),\n>  \tNULL\n>  };\n>  \n> @@ -1519,7 +1521,7 @@ static int get_url(int argc, const char **argv)\n>  \n>  static int set_url(int argc, const char **argv)\n>  {\n> -\tint i, push_mode = 0, add_mode = 0, delete_mode = 0;\n> +\tint i, push_mode = 0, save_to_push = 0, add_mode = 0, delete_mode = 0;\n>  \tint matches = 0, negative_matches = 0;\n>  \tconst char *remotename = NULL;\n>  \tconst char *newurl = NULL;\n> @@ -1532,6 +1534,8 @@ static int set_url(int argc, const char **argv)\n>  \tstruct option options[] = {\n>  \t\tOPT_BOOL('\\0', \"push\", &push_mode,\n>  \t\t\t N_(\"manipulate push URLs\")),\n> +\t\tOPT_BOOL('\\0', \"save-to-push\", &save_to_push,\n> +\t\t\t N_(\"change fetching URL behavior\")),\n>  \t\tOPT_BOOL('\\0', \"add\", &add_mode,\n>  \t\t\t N_(\"add URL\")),\n>  \t\tOPT_BOOL('\\0', \"delete\", &delete_mode,\n> @@ -1543,6 +1547,8 @@ static int set_url(int argc, const char **argv)\n>  \n>  \tif (add_mode && delete_mode)\n>  \t\tdie(_(\"--add --delete doesn't make sense\"));\n> +\tif (save_to_push && (push_mode || add_mode || delete_mode))\n> +\t\tdie(_(\"--save-to-push cannot be used with other options\"));\n>  \n>  \tif (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))\n>  \t\tusage_with_options(builtin_remote_seturl_usage, options);\n> @@ -1564,6 +1570,16 @@ static int set_url(int argc, const char **argv)\n>  \t\turlset = remote->pushurl;\n>  \t\turlset_nr = remote->pushurl_nr;\n>  \t} else {\n> +\t\tif (save_to_push) {\n> +\t\t\tif (remote->url_nr != 1)\n> +\t\t\t\tdie(_(\"--save-to-push can only be used when only one url is defined\"), remotename);\n\nUnused parameter \"remotename\" is fed to die().  I'll drop this.\n\n> +\n> +\t\t\tstrbuf_addf(&name_buf, \"remote.%s.pushurl\", remotename);\n> +\t\t\tgit_config_set_multivar(name_buf.buf,\n> +\t\t\t      remote->url[0], \"^$\", 0);\n> +\t\t\tstrbuf_reset(&name_buf);\n> +\t\t}\n> +\n>  \t\tstrbuf_addf(&name_buf, \"remote.%s.url\", remotename);\n>  \t\turlset = remote->url;\n>  \t\turlset_nr = remote->url_nr;\n> diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\n> index d2a2cdd453..434c1f828a 100755\n> --- a/t/t5505-remote.sh\n> +++ b/t/t5505-remote.sh\n> @@ -1194,6 +1194,17 @@ test_expect_success 'remote set-url --delete baz' '\n>  \tcmp expect actual\n>  '\n>  \n> +test_expect_success 'remote set-url --save-to-push bbb' '\n> +\tgit remote set-url --save-to-push someremote bbb &&\n> +\techo bbb >expect &&\n> +\techo \"YYY\" >>expect &&\n> +\techo ccc >>expect &&\n> +\tgit config --get-all remote.someremote.url >actual &&\n> +\techo \"YYY\" >>actual &&\n> +\tgit config --get-all remote.someremote.pushurl >>actual &&\n> +\tcmp expect actual\n> +'\n> +\n>  test_expect_success 'extra args: setup' '\n>  \t# add a dummy origin so that this does not trigger failure\n>  \tgit remote add origin .\n"},{"id":"364920","messageId":"27cba756d792797a0d1145dd507497d9b64d7535.1544451081.git.liu.denton@gmail.com","threadId":"49698","inReplyTo":"8fded8b84b593497177de740f80b3499c4269758.1541740174.git.liu.denton@gmail.com","subject":"[PATCH v4] remote: add --save-to-push option to git remote set-url","fromName":"Denton Liu","fromEmail":"liu.denton@gmail.com","sentAt":"2018-12-10T14:15:10Z","receivedAt":"2018-12-10T14:15:16Z","isPatch":true,"sender":{"key":"liu.denton@gmail.com","avatar":"https://avatars.githubusercontent.com/u/9620836?v=4"},"body":"This adds the --save-to-push option to `git remote set-url` such that\nwhen executed, we move the remote.*.url to remote.*.pushurl and set\nremote.*.url to the given url argument.\n\nFor example, if we have the following config:\n\n\t[remote \"origin\"]\n\t\turl = git@github.com:git/git.git\n\n`git remote set-url --save-to-push origin https://github.com/git/git.git`\nwould change the config to the following:\n\n\t[remote \"origin\"]\n\t\turl = https://github.com/git/git.git\n\t\tpushurl = git@github.com:git/git.git\n\nHelped-by: Junio C Hamano <gitster@pobox.com>\nSigned-off-by: Denton Liu <liu.denton@gmail.com>\n---\n\nThis patch improves upon v3 by adding the use-case for the new option,\nas discussed here[1].\n\n[1]: https://public-inbox.org/git/xmqqtvjlisnu.fsf@gitster-ct.c.googlers.com/\n---\n Documentation/git-remote.txt | 12 ++++++++++++\n builtin/remote.c             | 26 +++++++++++++++++++++-----\n t/t5505-remote.sh            | 11 +++++++++++\n 3 files changed, 44 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt\nindex 0cad37fb81..47aaae22c1 100644\n--- a/Documentation/git-remote.txt\n+++ b/Documentation/git-remote.txt\n@@ -19,6 +19,7 @@ SYNOPSIS\n 'git remote set-url' [--push] <name> <newurl> [<oldurl>]\n 'git remote set-url --add' [--push] <name> <newurl>\n 'git remote set-url --delete' [--push] <name> <url>\n+'git remote set-url --save-to-push' <name> <url>\n 'git remote' [-v | --verbose] 'show' [-n] <name>...\n 'git remote prune' [-n | --dry-run] <name>...\n 'git remote' [-v | --verbose] 'update' [-p | --prune] [(<group> | <remote>)...]\n@@ -155,6 +156,17 @@ With `--delete`, instead of changing existing URLs, all URLs matching\n regex <url> are deleted for remote <name>.  Trying to delete all\n non-push URLs is an error.\n +\n+With `--save-to-push`, the current URL is saved into the push URL before\n+setting the URL to <url>. Note that this command will not work if more than one\n+URL is defined because the behavior would be ambiguous. A use-case for this\n+feature is that you may have started your interaction with the repository with\n+a single authenticated URL that can be used for both fetching and pushing, but\n+over time you may have become sick of having to authenticate only to fetch.  In\n+such a case, you can feed an unauthenticated/anonymous fetch URL to set-url\n+with this option, so that the authenticated URL that you have been using for\n+pushing becomes the pushURL, and the new, unauthenticated/anonymous URL will be\n+used for fetching.\n++\n Note that the push URL and the fetch URL, even though they can\n be set differently, must still refer to the same place.  What you\n pushed to the push URL should be what you would see if you\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex f7edf7f2cb..d683e67ba6 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -24,8 +24,9 @@ static const char * const builtin_remote_usage[] = {\n \tN_(\"git remote set-branches [--add] <name> <branch>...\"),\n \tN_(\"git remote get-url [--push] [--all] <name>\"),\n \tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n-\tN_(\"git remote set-url --add <name> <newurl>\"),\n-\tN_(\"git remote set-url --delete <name> <url>\"),\n+\tN_(\"git remote set-url --add [--push] <name> <newurl>\"),\n+\tN_(\"git remote set-url --delete [--push] <name> <url>\"),\n+\tN_(\"git remote set-url --save-to-push <name> <url>\"),\n \tNULL\n };\n \n@@ -77,8 +78,9 @@ static const char * const builtin_remote_geturl_usage[] = {\n \n static const char * const builtin_remote_seturl_usage[] = {\n \tN_(\"git remote set-url [--push] <name> <newurl> [<oldurl>]\"),\n-\tN_(\"git remote set-url --add <name> <newurl>\"),\n-\tN_(\"git remote set-url --delete <name> <url>\"),\n+\tN_(\"git remote set-url --add [--push] <name> <newurl>\"),\n+\tN_(\"git remote set-url --delete [--push] <name> <url>\"),\n+\tN_(\"git remote set-url --save-to-push <name> <url>\"),\n \tNULL\n };\n \n@@ -1519,7 +1521,7 @@ static int get_url(int argc, const char **argv)\n \n static int set_url(int argc, const char **argv)\n {\n-\tint i, push_mode = 0, add_mode = 0, delete_mode = 0;\n+\tint i, push_mode = 0, save_to_push = 0, add_mode = 0, delete_mode = 0;\n \tint matches = 0, negative_matches = 0;\n \tconst char *remotename = NULL;\n \tconst char *newurl = NULL;\n@@ -1532,6 +1534,8 @@ static int set_url(int argc, const char **argv)\n \tstruct option options[] = {\n \t\tOPT_BOOL('\\0', \"push\", &push_mode,\n \t\t\t N_(\"manipulate push URLs\")),\n+\t\tOPT_BOOL('\\0', \"save-to-push\", &save_to_push,\n+\t\t\t N_(\"change fetching URL behavior\")),\n \t\tOPT_BOOL('\\0', \"add\", &add_mode,\n \t\t\t N_(\"add URL\")),\n \t\tOPT_BOOL('\\0', \"delete\", &delete_mode,\n@@ -1543,6 +1547,8 @@ static int set_url(int argc, const char **argv)\n \n \tif (add_mode && delete_mode)\n \t\tdie(_(\"--add --delete doesn't make sense\"));\n+\tif (save_to_push && (push_mode || add_mode || delete_mode))\n+\t\tdie(_(\"--save-to-push cannot be used with other options\"));\n \n \tif (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))\n \t\tusage_with_options(builtin_remote_seturl_usage, options);\n@@ -1564,6 +1570,16 @@ static int set_url(int argc, const char **argv)\n \t\turlset = remote->pushurl;\n \t\turlset_nr = remote->pushurl_nr;\n \t} else {\n+\t\tif (save_to_push) {\n+\t\t\tif (remote->url_nr != 1)\n+\t\t\t\tdie(_(\"--save-to-push can only be used when only one url is defined\"));\n+\n+\t\t\tstrbuf_addf(&name_buf, \"remote.%s.pushurl\", remotename);\n+\t\t\tgit_config_set_multivar(name_buf.buf,\n+\t\t\t      remote->url[0], \"^$\", 0);\n+\t\t\tstrbuf_reset(&name_buf);\n+\t\t}\n+\n \t\tstrbuf_addf(&name_buf, \"remote.%s.url\", remotename);\n \t\turlset = remote->url;\n \t\turlset_nr = remote->url_nr;\ndiff --git a/t/t5505-remote.sh b/t/t5505-remote.sh\nindex d2a2cdd453..434c1f828a 100755\n--- a/t/t5505-remote.sh\n+++ b/t/t5505-remote.sh\n@@ -1194,6 +1194,17 @@ test_expect_success 'remote set-url --delete baz' '\n \tcmp expect actual\n '\n \n+test_expect_success 'remote set-url --save-to-push bbb' '\n+\tgit remote set-url --save-to-push someremote bbb &&\n+\techo bbb >expect &&\n+\techo \"YYY\" >>expect &&\n+\techo ccc >>expect &&\n+\tgit config --get-all remote.someremote.url >actual &&\n+\techo \"YYY\" >>actual &&\n+\tgit config --get-all remote.someremote.pushurl >>actual &&\n+\tcmp expect actual\n+'\n+\n test_expect_success 'extra args: setup' '\n \t# add a dummy origin so that this does not trigger failure\n \tgit remote add origin .\n-- \n2.19.2\n\n"}]}