All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Mathew George <mathewegeorge@gmail.com>,  git@vger.kernel.org
Subject: Re: Cannot override `remote.origin.url` with `-c` option
Date: Tue, 11 Jun 2024 08:28:41 -0700	[thread overview]
Message-ID: <xmqq34pjxzva.fsf@gitster.g> (raw)
In-Reply-To: <20240611075137.GF3248245@coredump.intra.peff.net> (Jeff King's message of "Tue, 11 Jun 2024 03:51:37 -0400")

Jeff King <peff@peff.net> writes:

> Of course that leaves two questions:
>
>   1. What are multiple URLs actually good for? I have no idea. I

It came from days back when there weren't a separate push URL IIRC.
You may pull from a central place like everybody else, but you may
have other publishing points of your work.

Place to fetch must be a single known stable place for obvious
reasons.  "I have N, so I'll pull from one chosen at random among
these N" would lead to madness ;-).

>   2. Is there a way to override the list?
>
>      Sadly, no. For some config keys, we allow a value-less boolean
>      entry to reset the list.

Hmph, I somehow thought that a more widely used "clear" was an empty
string, but if we can make the convention around the "I exist and I
mean true" entries, that would be great.  It would not make much
sense to have multi-valued Boolean variable to begin with.

> Of course none of that helps your immediate case. I did think of one
> workaround, though, which is to use the "insteadOf" config to rewrite
> the URL. So:
>
>   git -c url.right-url.insteadOf=wrong-url ...
>
> will rewrite all instances of "wrong-url" to use "right-url" instead (in
> origin and elsewhere).

Yup, that is an excellent idea.

> diff --git a/remote.c b/remote.c
> index dcb5492c85..69b0f28637 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -63,6 +63,10 @@ static const char *alias_url(const char *url, struct rewrites *r)
>  
>  static void add_url(struct remote *remote, const char *url)
>  {
> +	if (!url) {
> +		remote->url_nr = 0;
> +		return;
> +	}
>  	ALLOC_GROW(remote->url, remote->url_nr + 1, remote->url_alloc);
>  	remote->url[remote->url_nr++] = url;
>  }
> @@ -430,10 +434,7 @@ static int handle_config(const char *key, const char *value,
>  	else if (!strcmp(subkey, "prunetags"))
>  		remote->prune_tags = git_config_bool(key, value);
>  	else if (!strcmp(subkey, "url")) {
> -		char *v;
> -		if (git_config_string(&v, key, value))
> -			return -1;
> -		add_url(remote, v);
> +		add_url(remote, xstrdup_or_null(value));
>  	} else if (!strcmp(subkey, "pushurl")) {
>  		char *v;
>  		if (git_config_string(&v, key, value))

I was expecting (with excitement) a mess, but the above is as clean
as we can make the idea, I would say.  Lack of documentation and
tests do count as incompleteness though of course.


  reply	other threads:[~2024-06-11 15:28 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-09  6:51 Cannot override `remote.origin.url` with `-c` option Mathew George
2024-06-11  7:51 ` Jeff King
2024-06-11 15:28   ` Junio C Hamano [this message]
2024-06-13 10:24     ` Jeff King
2024-06-14 10:24       ` [PATCH 0/11] allow overriding remote.*.url Jeff King
2024-06-14 10:25         ` [PATCH 01/11] archive: fix check for missing url Jeff King
2024-06-14 10:26         ` [PATCH 02/11] remote: refactor alias_url() memory ownership Jeff King
2024-06-14 17:05           ` Junio C Hamano
2024-06-14 10:27         ` [PATCH 03/11] remote: transfer ownership of memory in add_url(), etc Jeff King
2024-06-14 17:04           ` Junio C Hamano
2024-06-16  4:59             ` Jeff King
2024-06-17 17:42               ` Junio C Hamano
2024-06-25 17:30           ` Elijah Newren
2024-06-14 10:28         ` [PATCH 04/11] remote: use strvecs to store remote url/pushurl Jeff King
2024-06-25 17:32           ` Elijah Newren
2024-06-14 10:29         ` [PATCH 05/11] remote: simplify url/pushurl selection Jeff King
2024-06-25 17:33           ` Elijah Newren
2024-06-14 10:30         ` [PATCH 06/11] config: document remote.*.url/pushurl interaction Jeff King
2024-06-25 17:34           ` Elijah Newren
2024-06-14 10:31         ` [PATCH 07/11] remote: allow resetting url list Jeff King
2024-06-25 17:35           ` Elijah Newren
2024-06-14 10:31         ` [PATCH 08/11] t5801: make remote-testgit GIT_DIR setup more robust Jeff King
2024-06-25 17:36           ` Elijah Newren
2024-06-14 10:34         ` [PATCH 09/11] t5801: test remote.*.vcs config Jeff King
2024-06-14 10:37         ` [PATCH 10/11] remote: always require at least one url in a remote Jeff King
2024-06-14 10:42         ` [PATCH 11/11] remote: drop checks for zero-url case Jeff King
2024-06-25 17:37           ` Elijah Newren
2024-06-25 17:44         ` [PATCH 0/11] allow overriding remote.*.url Elijah Newren
2024-06-26 20:40           ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq34pjxzva.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=mathewegeorge@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.