git@vger.kernel.org mailing list mirror (one of many)
 help / Atom feed
* [RFC PATCH] remote: add --fetch option to git remote set-url
@ 2018-10-27  8:09 Denton Liu
  2018-10-29  5:57 ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Denton Liu @ 2018-10-27  8:09 UTC (permalink / raw)
  To: git; +Cc: liu.denton, anmolmago, briankyho, david.lu97, shirui.wang, f.francet

This adds the --fetch option to `git remote set-url` such that when
executed we move the remote.*.url to remote.*.pushurl and set
remote.*.url to the given url argument.

For example, if we have the following config:

	[remote "origin"]
		url = git@github.com:git/git.git

`git remote set-url --fetch origin https://github.com/git/git.git`
would change the config to the following:

	[remote "origin"]
		url = https://github.com/git/git.git
		pushurl = git@github.com:git/git.git

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Filip Francetic <f.francet@hotmail.com>
---
 builtin/remote.c | 42 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/builtin/remote.c b/builtin/remote.c
index f7edf7f2c..fcf1220c6 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -23,9 +23,9 @@ static const char * const builtin_remote_usage[] = {
 	N_("git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]"),
 	N_("git remote set-branches [--add] <name> <branch>..."),
 	N_("git remote get-url [--push] [--all] <name>"),
-	N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
-	N_("git remote set-url --add <name> <newurl>"),
-	N_("git remote set-url --delete <name> <url>"),
+	N_("git remote set-url [--push|--fetch] <name> <newurl> [<oldurl>]"),
+	N_("git remote set-url --add [--push|--fetch] <name> <newurl>"),
+	N_("git remote set-url --delete [--push|--fetch] <name> <url>"),
 	NULL
 };
 
@@ -76,9 +76,9 @@ static const char * const builtin_remote_geturl_usage[] = {
 };
 
 static const char * const builtin_remote_seturl_usage[] = {
-	N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
-	N_("git remote set-url --add <name> <newurl>"),
-	N_("git remote set-url --delete <name> <url>"),
+	N_("git remote set-url [--push|--fetch] <name> <newurl> [<oldurl>]"),
+	N_("git remote set-url --add [--push|--fetch] <name> <newurl>"),
+	N_("git remote set-url --delete [--push|--fetch] <name> <url>"),
 	NULL
 };
 
@@ -1519,7 +1519,7 @@ static int get_url(int argc, const char **argv)
 
 static int set_url(int argc, const char **argv)
 {
-	int i, push_mode = 0, add_mode = 0, delete_mode = 0;
+	int i, push_mode = 0, fetch_mode = 0, add_mode = 0, delete_mode = 0, move_fetch_to_push = 0;
 	int matches = 0, negative_matches = 0;
 	const char *remotename = NULL;
 	const char *newurl = NULL;
@@ -1532,6 +1532,8 @@ static int set_url(int argc, const char **argv)
 	struct option options[] = {
 		OPT_BOOL('\0', "push", &push_mode,
 			 N_("manipulate push URLs")),
+		OPT_BOOL('\0', "fetch", &fetch_mode,
+			 N_("manipulate fetch URLs")),
 		OPT_BOOL('\0', "add", &add_mode,
 			 N_("add URL")),
 		OPT_BOOL('\0', "delete", &delete_mode,
@@ -1543,6 +1545,8 @@ static int set_url(int argc, const char **argv)
 
 	if (add_mode && delete_mode)
 		die(_("--add --delete doesn't make sense"));
+	if (push_mode && fetch_mode)
+		die(_("--push --fetch doesn't make sense"));
 
 	if (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))
 		usage_with_options(builtin_remote_seturl_usage, options);
@@ -1559,18 +1563,40 @@ static int set_url(int argc, const char **argv)
 	if (!remote_is_configured(remote, 1))
 		die(_("No such remote '%s'"), remotename);
 
+	/*
+	 * If add_mode, we will be appending to remote.*.url so we shouldn't move the urls over.
+	 * If pushurls exist, we don't need to move the urls over to pushurl.
+	 */
+	move_fetch_to_push = fetch_mode && !add_mode && !remote->pushurl_nr;
+
 	if (push_mode) {
 		strbuf_addf(&name_buf, "remote.%s.pushurl", remotename);
 		urlset = remote->pushurl;
 		urlset_nr = remote->pushurl_nr;
 	} else {
+		if (move_fetch_to_push) {
+			strbuf_addf(&name_buf, "remote.%s.pushurl", remotename);
+			for (i = 0; i < remote->url_nr; i++) {
+				git_config_set_multivar(name_buf.buf, remote->url[i],
+						"^$", 0);
+			}
+			strbuf_reset(&name_buf);
+		}
+
 		strbuf_addf(&name_buf, "remote.%s.url", remotename);
 		urlset = remote->url;
 		urlset_nr = remote->url_nr;
 	}
 
+	/* Empty fetch URLs if they are being replaced */
+	if (move_fetch_to_push) {
+		for (i = 0; i < remote->url_nr; i++) {
+			git_config_set_multivar(name_buf.buf, NULL, remote->url[i], 1);
+		}
+	}
+
 	/* Special cases that add new entry. */
-	if ((!oldurl && !delete_mode) || add_mode) {
+	if ((!oldurl && !delete_mode) || move_fetch_to_push || add_mode) {
 		if (add_mode)
 			git_config_set_multivar(name_buf.buf, newurl,
 						       "^$", 0);
-- 
2.19.1.542.gc4df23f79.dirty


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH] remote: add --fetch option to git remote set-url
  2018-10-27  8:09 [RFC PATCH] remote: add --fetch option to git remote set-url Denton Liu
@ 2018-10-29  5:57 ` Junio C Hamano
  2018-10-30  7:56   ` Denton Liu
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2018-10-29  5:57 UTC (permalink / raw)
  To: Denton Liu; +Cc: git, anmolmago, briankyho, david.lu97, shirui.wang, f.francet

Denton Liu <liu.denton@gmail.com> writes:

> This adds the --fetch option to `git remote set-url` such that when
> executed we move the remote.*.url to remote.*.pushurl and set
> remote.*.url to the given url argument.
>

I suspect this is a horrible idea from end-user's point of view.
"set-url --push" is used to SET pushURL instead of setting URL and
does not MOVE anything.  Why should the end user expect and remember
"set-url --fetch" works very differently?  

If there is a need for a "--move-URL-to-pushURL-and-set-pushURL"
short-hand to avoid having to use two commands

	git remote set-url --push $(git remote --get-url origin) origin
	git remote set-url $there origin

it should not be called "--fetch", which has a strong connotation of
being an opposite of existing "--push", but something else.  And
then we need to ask ourselves if we also need such a short-hand to
"--move-pushURL-to-URL-and-set-URL" operation.  The answer to the
last question would help us decide if (1) this combined operation is
a good idea to begin with and (2) what is the good name for such an
operation.

Assuming that the short-hand operation is a good idea in the first
place, without deciding what the externally visible good name for it
is, let's read on.

> +	/*
> +	 * If add_mode, we will be appending to remote.*.url so we shouldn't move the urls over.
> +	 * If pushurls exist, we don't need to move the urls over to pushurl.
> +	 */
> +	move_fetch_to_push = fetch_mode && !add_mode && !remote->pushurl_nr;

Should this kind of "the user asked for --fetch, but sometimes it is
not appropriate to honor that request" be done silently like this?

Earlier you had a check like this:

> +	if (push_mode && fetch_mode)
> +		die(_("--push --fetch doesn't make sense"));

If a request to "--fetch" is ignored when "--add" is given, for
example, shouldn't the combination also be diagnosed as "not making
sense, we'd ignore your wish to use the --fetch option"?  Similarly
for the case where there already is pushurl defined for the remote.

This is a different tangent on the same line, but it could be that
the user wants to have two (or more) pushURLs because the user wants
to push to two remotes at the same time with "git push this-remote",
so silently ignoring "--force" may not be the right thing in the
first place.  We may instead need to make the value of URL to an
extra pushURL entry (if we had one, we now have two).


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH] remote: add --fetch option to git remote set-url
  2018-10-29  5:57 ` Junio C Hamano
@ 2018-10-30  7:56   ` Denton Liu
  2018-10-30 10:11     ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Denton Liu @ 2018-10-30  7:56 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git, anmolmago, briankyho, david.lu97, shirui.wang, f.francet

On Mon, Oct 29, 2018 at 02:57:28PM +0900, Junio C Hamano wrote:
> Denton Liu <liu.denton@gmail.com> writes:
> 
> > This adds the --fetch option to `git remote set-url` such that when
> > executed we move the remote.*.url to remote.*.pushurl and set
> > remote.*.url to the given url argument.
> >
> 
> I suspect this is a horrible idea from end-user's point of view.
> "set-url --push" is used to SET pushURL instead of setting URL and
> does not MOVE anything.  Why should the end user expect and remember
> "set-url --fetch" works very differently?  
>

I agree, `--fetch` is a terrible name for this. Perhaps a better name
would be something like `--fetch-behavior` or `--keep-push` so that the
behaviour is more transparent for the end-user. Either way, I think we
can decide on the name later.

> If there is a need for a "--move-URL-to-pushURL-and-set-pushURL"
> short-hand to avoid having to use two commands
> 
> 	git remote set-url --push $(git remote --get-url origin) origin
> 	git remote set-url $there origin
> 
> it should not be called "--fetch", which has a strong connotation of
> being an opposite of existing "--push", but something else.  And
> then we need to ask ourselves if we also need such a short-hand to
> "--move-pushURL-to-URL-and-set-URL" operation.  The answer to the
> last question would help us decide if (1) this combined operation is
> a good idea to begin with and (2) what is the good name for such an
> operation.
> 
> Assuming that the short-hand operation is a good idea in the first
> place, without deciding what the externally visible good name for it
> is, let's read on.
> 
> > +	/*
> > +	 * If add_mode, we will be appending to remote.*.url so we shouldn't move the urls over.
> > +	 * If pushurls exist, we don't need to move the urls over to pushurl.
> > +	 */
> > +	move_fetch_to_push = fetch_mode && !add_mode && !remote->pushurl_nr;
> 
> Should this kind of "the user asked for --fetch, but sometimes it is
> not appropriate to honor that request" be done silently like this?
> 
> Earlier you had a check like this:
> 
> > +	if (push_mode && fetch_mode)
> > +		die(_("--push --fetch doesn't make sense"));
> 
> If a request to "--fetch" is ignored when "--add" is given, for
> example, shouldn't the combination also be diagnosed as "not making
> sense, we'd ignore your wish to use the --fetch option"?  Similarly
> for the case where there already is pushurl defined for the remote.
> 
> This is a different tangent on the same line, but it could be that
> the user wants to have two (or more) pushURLs because the user wants
> to push to two remotes at the same time with "git push this-remote",
> so silently ignoring "--force" may not be the right thing in the
> first place.  We may instead need to make the value of URL to an
> extra pushURL entry (if we had one, we now have two).
>

Perhaps I should motivate the use-case for this option. There have been
times when I've had the URL set to something but no pushURL. I've
wanted to only change the fetching URL and keep the pushing URL the same
but unfortunately, there's no way to do that because of the url/pushurl
split is set up.

My implementation of --fetch is supposed to emulate what would happen if
git were implemented with fetchurl/pushurl instead. Does the patch make
more sense in this context?

Please let me know if you think that the concept behind this patch is a
good idea. Thanks!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH] remote: add --fetch option to git remote set-url
  2018-10-30  7:56   ` Denton Liu
@ 2018-10-30 10:11     ` Junio C Hamano
  2018-11-09  2:37       ` [RFC PATCH v2] remote: add --save-push " Denton Liu
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2018-10-30 10:11 UTC (permalink / raw)
  To: Denton Liu; +Cc: git, anmolmago, briankyho, david.lu97, shirui.wang, f.francet

Denton Liu <liu.denton@gmail.com> writes:

> On Mon, Oct 29, 2018 at 02:57:28PM +0900, Junio C Hamano wrote:
> ...
>> Earlier you had a check like this:
>> 
>> > +	if (push_mode && fetch_mode)
>> > +		die(_("--push --fetch doesn't make sense"));
>> 
>> If a request to "--fetch" is ignored when "--add" is given, for
>> example, shouldn't the combination also be diagnosed as "not making
>> sense, we'd ignore your wish to use the --fetch option"?  Similarly
>> for the case where there already is pushurl defined for the remote.

Clarification.  Here I am suggesting that a part of the logic in the
earlier assignment to move_fetch_to_push should become a similar
call to die(), detecting a competing and unsatisfiable wish, rather
than getting silently ignored.

>> This is a different tangent on the same line, but it could be that
>> the user wants to have two (or more) pushURLs because the user wants
>> to push to two remotes at the same time with "git push this-remote",
>> so silently ignoring "--force" may not be the right thing in the

Correction.  s/--force/--fetch/ was what I meant here.

>> first place.  We may instead need to make the value of URL to an
>> extra pushURL entry (if we had one, we now have two).

Also, additionally, since there is no use to have two or more URL,
because unlike "git push $there" that can push to two places,
fetching from two places into the same set of remote-tracking
branches would not make sense, --move-pushURL-to-URL-and-set-pushURL
operation that is the symmetry of what the patch under discussion
proposes should fail instead of creating an extra URL entry, breaking
an apparent symmetry.

> Perhaps I should motivate the use-case for this option. There have been
> times when I've had the URL set to something but no pushURL. I've
> wanted to only change the fetching URL and keep the pushing URL the same

URL (plus optionally pushURL) split was done because most everybody
were fetching from and pushing to the same place; it would not have
made any sense to have fetchURL and pushURL that are separate, as
that would have forced everybody to have both, when majority of the
users would have to set them to the same value.

Quite honestly, tweaking URL and/or pushURL is not something you'd
do every three months or more frequently, so I do not particularly
feel sympathetic to the cause of this patch, which would allow
setting one to the value that happens to be set to the other one
while setting an arbitrary new value to the other one.  Once the
user's need deviates from that single niche pattern, the user needs
to update both, and setting these two independently is quite simple
and straight-forward in the first place.  And that same simple pattern
to set two independently can be used without learning this new option.

> My implementation of --fetch is supposed to emulate what would happen if
> git were implemented with fetchurl/pushurl instead. Does the patch make
> more sense in this context?

Hmph.  As a system that has fetchURL and pushURL independently and
forces everybody to set both does not make much sense in the first
place, the patch making sense in that context is not a very strong
reason to support it.

> Please let me know if you think that the concept behind this patch is a
> good idea. Thanks!

If I don't then I do not have to let you know, then ;-) 

I do not particularly think it is a horrible idea, but I do not see
that it would be a feature that helps particuarly wide audience.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RFC PATCH v2] remote: add --save-push option to git remote set-url
  2018-10-30 10:11     ` Junio C Hamano
@ 2018-11-09  2:37       ` " Denton Liu
  2018-11-09  3:15         ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Denton Liu @ 2018-11-09  2:37 UTC (permalink / raw)
  To: gitster; +Cc: git, liu.denton, anmolmago, briankyho, david.lu97, shirui.wang

This adds the --save-push option to `git remote set-url` such that when
executed, we move the remote.*.url to remote.*.pushurl and set
remote.*.url to the given url argument.

For example, if we have the following config:

	[remote "origin"]
		url = git@github.com:git/git.git

`git remote set-url --save-push origin https://github.com/git/git.git`
would change the config to the following:

	[remote "origin"]
		url = https://github.com/git/git.git
		pushurl = git@github.com:git/git.git

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
I decided to address your comments and reroll the patch one more time. 

Even though the option isn't _that_ commonly used, I've managed to use
it a couple of times since I've implemented so I believe that this
option should be included.

---
 Documentation/git-remote.txt |  5 +++++
 builtin/remote.c             | 25 ++++++++++++++++++++-----
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index 0cad37fb81..8ce85fe2f2 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -19,6 +19,7 @@ SYNOPSIS
 'git remote set-url' [--push] <name> <newurl> [<oldurl>]
 'git remote set-url --add' [--push] <name> <newurl>
 'git remote set-url --delete' [--push] <name> <url>
+'git remote set-url --save-push' <name> <url>
 'git remote' [-v | --verbose] 'show' [-n] <name>...
 'git remote prune' [-n | --dry-run] <name>...
 'git remote' [-v | --verbose] 'update' [-p | --prune] [(<group> | <remote>)...]
@@ -155,6 +156,10 @@ With `--delete`, instead of changing existing URLs, all URLs matching
 regex <url> are deleted for remote <name>.  Trying to delete all
 non-push URLs is an error.
 +
+With `--save-push`, the current URL is saved into the push URL before setting
+the URL to <url>. Note that this command will not work if more than one URL is
+defined or if any push URLs are defined because behavior would be ambiguous.
++
 Note that the push URL and the fetch URL, even though they can
 be set differently, must still refer to the same place.  What you
 pushed to the push URL should be what you would see if you
diff --git a/builtin/remote.c b/builtin/remote.c
index f7edf7f2cb..0eaec7ef38 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -24,8 +24,9 @@ static const char * const builtin_remote_usage[] = {
 	N_("git remote set-branches [--add] <name> <branch>..."),
 	N_("git remote get-url [--push] [--all] <name>"),
 	N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
-	N_("git remote set-url --add <name> <newurl>"),
-	N_("git remote set-url --delete <name> <url>"),
+	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>"),
 	NULL
 };
 
@@ -77,8 +78,9 @@ static const char * const builtin_remote_geturl_usage[] = {
 
 static const char * const builtin_remote_seturl_usage[] = {
 	N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
-	N_("git remote set-url --add <name> <newurl>"),
-	N_("git remote set-url --delete <name> <url>"),
+	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>"),
 	NULL
 };
 
@@ -1519,7 +1521,7 @@ static int get_url(int argc, const char **argv)
 
 static int set_url(int argc, const char **argv)
 {
-	int i, push_mode = 0, add_mode = 0, delete_mode = 0;
+	int i, push_mode = 0, save_push = 0, add_mode = 0, delete_mode = 0;
 	int matches = 0, negative_matches = 0;
 	const char *remotename = NULL;
 	const char *newurl = NULL;
@@ -1532,6 +1534,8 @@ static int set_url(int argc, const char **argv)
 	struct option options[] = {
 		OPT_BOOL('\0', "push", &push_mode,
 			 N_("manipulate push URLs")),
+		OPT_BOOL('\0', "save-push", &save_push,
+			 N_("change fetching URL behavior")),
 		OPT_BOOL('\0', "add", &add_mode,
 			 N_("add URL")),
 		OPT_BOOL('\0', "delete", &delete_mode,
@@ -1543,6 +1547,8 @@ static int set_url(int argc, const char **argv)
 
 	if (add_mode && delete_mode)
 		die(_("--add --delete doesn't make sense"));
+	if (save_push && (push_mode || add_mode || delete_mode))
+		die(_("--save-push cannot be used with other options"));
 
 	if (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))
 		usage_with_options(builtin_remote_seturl_usage, options);
@@ -1564,6 +1570,15 @@ static int set_url(int argc, const char **argv)
 		urlset = remote->pushurl;
 		urlset_nr = remote->pushurl_nr;
 	} else {
+		if (save_push) {
+			if (remote->url_nr != 1 || remote->pushurl_nr != 0)
+				die(_("--save-push can only be used when one url and no pushurl is defined"), remotename);
+
+			strbuf_addf(&name_buf, "remote.%s.pushurl", remotename);
+			git_config_set(name_buf.buf, remote->url[0]);
+			strbuf_reset(&name_buf);
+		}
+
 		strbuf_addf(&name_buf, "remote.%s.url", remotename);
 		urlset = remote->url;
 		urlset_nr = remote->url_nr;
-- 
2.19.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC PATCH v2] remote: add --save-push option to git remote set-url
  2018-11-09  2:37       ` [RFC PATCH v2] remote: add --save-push " Denton Liu
@ 2018-11-09  3:15         ` Junio C Hamano
  2018-11-09  5:20           ` [PATCH v3] remote: add --save-to-push " Denton Liu
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2018-11-09  3:15 UTC (permalink / raw)
  To: Denton Liu; +Cc: git, anmolmago, briankyho, david.lu97, shirui.wang

Denton Liu <liu.denton@gmail.com> writes:

> This adds the --save-push option to `git remote set-url` such that when
> executed, we move the remote.*.url to remote.*.pushurl and set
> remote.*.url to the given url argument.
>
> For example, if we have the following config:
>
> 	[remote "origin"]
> 		url = git@github.com:git/git.git
>
> `git remote set-url --save-push origin https://github.com/git/git.git`
> would change the config to the following:
>
> 	[remote "origin"]
> 		url = https://github.com/git/git.git
> 		pushurl = git@github.com:git/git.git

This sounds more like "saving to push" (i.e. what you are saving is
the existing "url" and the "push" is a shorthand for "pushURL",
which is the location the old value of "url" is aved to), not "save
(the) push(URL)".  So if adding this option makes sense, I would say
"--save-to-push" (or even "--save-to-pushURL") may be a more
appropriate name for it.

> +With `--save-push`, the current URL is saved into the push URL before setting
> +the URL to <url>. Note that this command will not work if more than one URL is
> +defined or if any push URLs are defined because behavior would be ambiguous.

Ambigous in what way?  You asked the current URL to be saved as a
pushURL, so existing pushURL destinations should not come into play,
I would think.  If there are more than one URL (not pushURL), on the
other hand, I think you have a bigger problem (where would "git fetch"
fetch from, and how would these multiple URLs are prevented from
trashing refs/remotes/$remote/* with each other's refs?), so
stopping the operation before "set-url" makes the problem worse is
probably a good idea, but I think that is true with or without this
new option.

> diff --git a/builtin/remote.c b/builtin/remote.c
> index f7edf7f2cb..0eaec7ef38 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -24,8 +24,9 @@ static const char * const builtin_remote_usage[] = {
>  	N_("git remote set-branches [--add] <name> <branch>..."),
>  	N_("git remote get-url [--push] [--all] <name>"),
>  	N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
> -	N_("git remote set-url --add <name> <newurl>"),
> -	N_("git remote set-url --delete <name> <url>"),
> +	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>"),
>  	NULL
>  };

Needs update?

> @@ -77,8 +78,9 @@ static const char * const builtin_remote_geturl_usage[] = {
>  
>  static const char * const builtin_remote_seturl_usage[] = {
>  	N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
> -	N_("git remote set-url --add <name> <newurl>"),
> -	N_("git remote set-url --delete <name> <url>"),
> +	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>"),
>  	NULL
>  };

Needs update?

> +		if (save_push) {
> +			if (remote->url_nr != 1 || remote->pushurl_nr != 0)
> +				die(_("--save-push can only be used when one url and no pushurl is defined"), remotename);

I _think_ in the future (if this option turns out to be widely used)
people may ask for this condition to be loosened somewhat, but it is
relatively easy to start restrictive and then to loosen later, so I
think this is OK for now.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3] remote: add --save-to-push option to git remote set-url
  2018-11-09  3:15         ` Junio C Hamano
@ 2018-11-09  5:20           ` " Denton Liu
  2018-11-13  9:46             ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Denton Liu @ 2018-11-09  5:20 UTC (permalink / raw)
  To: gitster; +Cc: git, liu.denton, anmolmago, briankyho, david.lu97, shirui.wang

This adds the --save-to-push option to `git remote set-url` such that
when executed, we move the remote.*.url to remote.*.pushurl and set
remote.*.url to the given url argument.

For example, if we have the following config:

	[remote "origin"]
		url = git@github.com:git/git.git

`git remote set-url --save-to-push origin https://github.com/git/git.git`
would change the config to the following:

	[remote "origin"]
		url = https://github.com/git/git.git
		pushurl = git@github.com:git/git.git

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
On Fri, Nov 09, 2018 at 12:15:22PM +0900, Junio C Hamano wrote:
> This sounds more like "saving to push" (i.e. what you are saving is
> the existing "url" and the "push" is a shorthand for "pushURL",
> which is the location the old value of "url" is aved to), not "save
> (the) push(URL)".  So if adding this option makes sense, I would say
> "--save-to-push" (or even "--save-to-pushURL") may be a more
> appropriate name for it.
> 

My original intention was for it to mean "save push behavior" but I
agree with you that it's unclear so I'm changing it to --save-to-push.

> Ambigous in what way?  You asked the current URL to be saved as a
> pushURL, so existing pushURL destinations should not come into play,
> I would think.  If there are more than one URL (not pushURL), on the
> other hand, I think you have a bigger problem (where would "git fetch"
> fetch from, and how would these multiple URLs are prevented from
> trashing refs/remotes/$remote/* with each other's refs?), so
> stopping the operation before "set-url" makes the problem worse is
> probably a good idea, but I think that is true with or without this
> new option.
> 

> I _think_ in the future (if this option turns out to be widely used)
> people may ask for this condition to be loosened somewhat, but it is
> relatively easy to start restrictive and then to loosen later, so I
> think this is OK for now.
> 

I agree, there's no reason why we shouldn't allow appending to the push
URLs if one already exists so I removed that removed that restriction.
---
 Documentation/git-remote.txt |  5 +++++
 builtin/remote.c             | 26 +++++++++++++++++++++-----
 t/t5505-remote.sh            | 11 +++++++++++
 3 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
index 0cad37fb81..8f9d700252 100644
--- a/Documentation/git-remote.txt
+++ b/Documentation/git-remote.txt
@@ -19,6 +19,7 @@ SYNOPSIS
 'git remote set-url' [--push] <name> <newurl> [<oldurl>]
 'git remote set-url --add' [--push] <name> <newurl>
 'git remote set-url --delete' [--push] <name> <url>
+'git remote set-url --save-to-push' <name> <url>
 'git remote' [-v | --verbose] 'show' [-n] <name>...
 'git remote prune' [-n | --dry-run] <name>...
 'git remote' [-v | --verbose] 'update' [-p | --prune] [(<group> | <remote>)...]
@@ -155,6 +156,10 @@ With `--delete`, instead of changing existing URLs, all URLs matching
 regex <url> are deleted for remote <name>.  Trying to delete all
 non-push URLs is an error.
 +
+With `--save-to-push`, the current URL is saved into the push URL before
+setting the URL to <url>. Note that this command will not work if more than one
+URL is defined because the behavior would be ambiguous.
++
 Note that the push URL and the fetch URL, even though they can
 be set differently, must still refer to the same place.  What you
 pushed to the push URL should be what you would see if you
diff --git a/builtin/remote.c b/builtin/remote.c
index f7edf7f2cb..3249c3face 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -24,8 +24,9 @@ static const char * const builtin_remote_usage[] = {
 	N_("git remote set-branches [--add] <name> <branch>..."),
 	N_("git remote get-url [--push] [--all] <name>"),
 	N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
-	N_("git remote set-url --add <name> <newurl>"),
-	N_("git remote set-url --delete <name> <url>"),
+	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>"),
 	NULL
 };
 
@@ -77,8 +78,9 @@ static const char * const builtin_remote_geturl_usage[] = {
 
 static const char * const builtin_remote_seturl_usage[] = {
 	N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
-	N_("git remote set-url --add <name> <newurl>"),
-	N_("git remote set-url --delete <name> <url>"),
+	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>"),
 	NULL
 };
 
@@ -1519,7 +1521,7 @@ static int get_url(int argc, const char **argv)
 
 static int set_url(int argc, const char **argv)
 {
-	int i, push_mode = 0, add_mode = 0, delete_mode = 0;
+	int i, push_mode = 0, save_to_push = 0, add_mode = 0, delete_mode = 0;
 	int matches = 0, negative_matches = 0;
 	const char *remotename = NULL;
 	const char *newurl = NULL;
@@ -1532,6 +1534,8 @@ static int set_url(int argc, const char **argv)
 	struct option options[] = {
 		OPT_BOOL('\0', "push", &push_mode,
 			 N_("manipulate push URLs")),
+		OPT_BOOL('\0', "save-to-push", &save_to_push,
+			 N_("change fetching URL behavior")),
 		OPT_BOOL('\0', "add", &add_mode,
 			 N_("add URL")),
 		OPT_BOOL('\0', "delete", &delete_mode,
@@ -1543,6 +1547,8 @@ static int set_url(int argc, const char **argv)
 
 	if (add_mode && delete_mode)
 		die(_("--add --delete doesn't make sense"));
+	if (save_to_push && (push_mode || add_mode || delete_mode))
+		die(_("--save-to-push cannot be used with other options"));
 
 	if (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))
 		usage_with_options(builtin_remote_seturl_usage, options);
@@ -1564,6 +1570,16 @@ static int set_url(int argc, const char **argv)
 		urlset = remote->pushurl;
 		urlset_nr = remote->pushurl_nr;
 	} else {
+		if (save_to_push) {
+			if (remote->url_nr != 1)
+				die(_("--save-to-push can only be used when only one url is defined"), remotename);
+
+			strbuf_addf(&name_buf, "remote.%s.pushurl", remotename);
+			git_config_set_multivar(name_buf.buf,
+			      remote->url[0], "^$", 0);
+			strbuf_reset(&name_buf);
+		}
+
 		strbuf_addf(&name_buf, "remote.%s.url", remotename);
 		urlset = remote->url;
 		urlset_nr = remote->url_nr;
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index d2a2cdd453..434c1f828a 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -1194,6 +1194,17 @@ test_expect_success 'remote set-url --delete baz' '
 	cmp expect actual
 '
 
+test_expect_success 'remote set-url --save-to-push bbb' '
+	git remote set-url --save-to-push someremote bbb &&
+	echo bbb >expect &&
+	echo "YYY" >>expect &&
+	echo ccc >>expect &&
+	git config --get-all remote.someremote.url >actual &&
+	echo "YYY" >>actual &&
+	git config --get-all remote.someremote.pushurl >>actual &&
+	cmp expect actual
+'
+
 test_expect_success 'extra args: setup' '
 	# add a dummy origin so that this does not trigger failure
 	git remote add origin .
-- 
2.19.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3] remote: add --save-to-push option to git remote set-url
  2018-11-09  5:20           ` [PATCH v3] remote: add --save-to-push " Denton Liu
@ 2018-11-13  9:46             ` Junio C Hamano
  0 siblings, 0 replies; 8+ messages in thread
From: Junio C Hamano @ 2018-11-13  9:46 UTC (permalink / raw)
  To: Denton Liu; +Cc: git, anmolmago, briankyho, david.lu97, shirui.wang

Denton Liu <liu.denton@gmail.com> writes:

> This adds the --save-to-push option to `git remote set-url` such that
> when executed, we move the remote.*.url to remote.*.pushurl and set
> remote.*.url to the given url argument.
>
> For example, if we have the following config:
>
> 	[remote "origin"]
> 		url = git@github.com:git/git.git
>
> `git remote set-url --save-to-push origin https://github.com/git/git.git`
> would change the config to the following:
>
> 	[remote "origin"]
> 		url = https://github.com/git/git.git
> 		pushurl = git@github.com:git/git.git
>
> Signed-off-by: Denton Liu <liu.denton@gmail.com>
> ---
> On Fri, Nov 09, 2018 at 12:15:22PM +0900, Junio C Hamano wrote:
>> This sounds more like "saving to push" (i.e. what you are saving is
>> the existing "url" and the "push" is a shorthand for "pushURL",
>> which is the location the old value of "url" is aved to), not "save
>> (the) push(URL)".  So if adding this option makes sense, I would say
>> "--save-to-push" (or even "--save-to-pushURL") may be a more
>> appropriate name for it.
>> 
>
> My original intention was for it to mean "save push behavior" but I
> agree with you that it's unclear so I'm changing it to --save-to-push.
>
>> Ambigous in what way?  You asked the current URL to be saved as a
>> pushURL, so existing pushURL destinations should not come into play,
>> I would think.  If there are more than one URL (not pushURL), on the
>> other hand, I think you have a bigger problem (where would "git fetch"
>> fetch from, and how would these multiple URLs are prevented from
>> trashing refs/remotes/$remote/* with each other's refs?), so
>> stopping the operation before "set-url" makes the problem worse is
>> probably a good idea, but I think that is true with or without this
>> new option.
>> 
>
>> I _think_ in the future (if this option turns out to be widely used)
>> people may ask for this condition to be loosened somewhat, but it is
>> relatively easy to start restrictive and then to loosen later, so I
>> think this is OK for now.
>> 
>
> I agree, there's no reason why we shouldn't allow appending to the push
> URLs if one already exists so I removed that removed that restriction.
> ---
>  Documentation/git-remote.txt |  5 +++++
>  builtin/remote.c             | 26 +++++++++++++++++++++-----
>  t/t5505-remote.sh            | 11 +++++++++++
>  3 files changed, 37 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt
> index 0cad37fb81..8f9d700252 100644
> --- a/Documentation/git-remote.txt
> +++ b/Documentation/git-remote.txt
> @@ -19,6 +19,7 @@ SYNOPSIS
>  'git remote set-url' [--push] <name> <newurl> [<oldurl>]
>  'git remote set-url --add' [--push] <name> <newurl>
>  'git remote set-url --delete' [--push] <name> <url>
> +'git remote set-url --save-to-push' <name> <url>
>  'git remote' [-v | --verbose] 'show' [-n] <name>...
>  'git remote prune' [-n | --dry-run] <name>...
>  'git remote' [-v | --verbose] 'update' [-p | --prune] [(<group> | <remote>)...]
> @@ -155,6 +156,10 @@ With `--delete`, instead of changing existing URLs, all URLs matching
>  regex <url> are deleted for remote <name>.  Trying to delete all
>  non-push URLs is an error.
>  +
> +With `--save-to-push`, the current URL is saved into the push URL before
> +setting the URL to <url>. Note that this command will not work if more than one
> +URL is defined because the behavior would be ambiguous.
> ++
>  Note that the push URL and the fetch URL, even though they can
>  be set differently, must still refer to the same place.  What you
>  pushed to the push URL should be what you would see if you
> diff --git a/builtin/remote.c b/builtin/remote.c
> index f7edf7f2cb..3249c3face 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -24,8 +24,9 @@ static const char * const builtin_remote_usage[] = {
>  	N_("git remote set-branches [--add] <name> <branch>..."),
>  	N_("git remote get-url [--push] [--all] <name>"),
>  	N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
> -	N_("git remote set-url --add <name> <newurl>"),
> -	N_("git remote set-url --delete <name> <url>"),
> +	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>"),
>  	NULL
>  };
>  
> @@ -77,8 +78,9 @@ static const char * const builtin_remote_geturl_usage[] = {
>  
>  static const char * const builtin_remote_seturl_usage[] = {
>  	N_("git remote set-url [--push] <name> <newurl> [<oldurl>]"),
> -	N_("git remote set-url --add <name> <newurl>"),
> -	N_("git remote set-url --delete <name> <url>"),
> +	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>"),
>  	NULL
>  };
>  
> @@ -1519,7 +1521,7 @@ static int get_url(int argc, const char **argv)
>  
>  static int set_url(int argc, const char **argv)
>  {
> -	int i, push_mode = 0, add_mode = 0, delete_mode = 0;
> +	int i, push_mode = 0, save_to_push = 0, add_mode = 0, delete_mode = 0;
>  	int matches = 0, negative_matches = 0;
>  	const char *remotename = NULL;
>  	const char *newurl = NULL;
> @@ -1532,6 +1534,8 @@ static int set_url(int argc, const char **argv)
>  	struct option options[] = {
>  		OPT_BOOL('\0', "push", &push_mode,
>  			 N_("manipulate push URLs")),
> +		OPT_BOOL('\0', "save-to-push", &save_to_push,
> +			 N_("change fetching URL behavior")),
>  		OPT_BOOL('\0', "add", &add_mode,
>  			 N_("add URL")),
>  		OPT_BOOL('\0', "delete", &delete_mode,
> @@ -1543,6 +1547,8 @@ static int set_url(int argc, const char **argv)
>  
>  	if (add_mode && delete_mode)
>  		die(_("--add --delete doesn't make sense"));
> +	if (save_to_push && (push_mode || add_mode || delete_mode))
> +		die(_("--save-to-push cannot be used with other options"));
>  
>  	if (argc < 3 || argc > 4 || ((add_mode || delete_mode) && argc != 3))
>  		usage_with_options(builtin_remote_seturl_usage, options);
> @@ -1564,6 +1570,16 @@ static int set_url(int argc, const char **argv)
>  		urlset = remote->pushurl;
>  		urlset_nr = remote->pushurl_nr;
>  	} else {
> +		if (save_to_push) {
> +			if (remote->url_nr != 1)
> +				die(_("--save-to-push can only be used when only one url is defined"), remotename);

Unused parameter "remotename" is fed to die().  I'll drop this.

> +
> +			strbuf_addf(&name_buf, "remote.%s.pushurl", remotename);
> +			git_config_set_multivar(name_buf.buf,
> +			      remote->url[0], "^$", 0);
> +			strbuf_reset(&name_buf);
> +		}
> +
>  		strbuf_addf(&name_buf, "remote.%s.url", remotename);
>  		urlset = remote->url;
>  		urlset_nr = remote->url_nr;
> diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
> index d2a2cdd453..434c1f828a 100755
> --- a/t/t5505-remote.sh
> +++ b/t/t5505-remote.sh
> @@ -1194,6 +1194,17 @@ test_expect_success 'remote set-url --delete baz' '
>  	cmp expect actual
>  '
>  
> +test_expect_success 'remote set-url --save-to-push bbb' '
> +	git remote set-url --save-to-push someremote bbb &&
> +	echo bbb >expect &&
> +	echo "YYY" >>expect &&
> +	echo ccc >>expect &&
> +	git config --get-all remote.someremote.url >actual &&
> +	echo "YYY" >>actual &&
> +	git config --get-all remote.someremote.pushurl >>actual &&
> +	cmp expect actual
> +'
> +
>  test_expect_success 'extra args: setup' '
>  	# add a dummy origin so that this does not trigger failure
>  	git remote add origin .

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, back to index

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-27  8:09 [RFC PATCH] remote: add --fetch option to git remote set-url Denton Liu
2018-10-29  5:57 ` Junio C Hamano
2018-10-30  7:56   ` Denton Liu
2018-10-30 10:11     ` Junio C Hamano
2018-11-09  2:37       ` [RFC PATCH v2] remote: add --save-push " Denton Liu
2018-11-09  3:15         ` Junio C Hamano
2018-11-09  5:20           ` [PATCH v3] remote: add --save-to-push " Denton Liu
2018-11-13  9:46             ` Junio C Hamano

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox