From: Junio C Hamano <gitster@pobox•com>
To: Johannes Schindelin <johannes.schindelin@gmx•de>
Cc: anapsix@random•io, git@vger•kernel.org
Subject: Re: [PATCH 1/2] git remote add: allow re-adding remotes with the same URL
Date: Mon, 22 Dec 2014 09:49:22 -0800 [thread overview]
Message-ID: <xmqq1tnrbmn1.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <9c0c693efe68b1c0b080c14104bb6c5f7bf74097.1419267895.git.johannes.schindelin@gmx.de> (Johannes Schindelin's message of "Mon, 22 Dec 2014 18:06:50 +0100 (CET)")
Johannes Schindelin <johannes.schindelin@gmx•de> writes:
> When adding a remote, we make sure that the remote does not exist
> already.
>
> For convenience, we allow re-adding remotes with the same URLs.
> This also handles the case that there is an "[url ...] insteadOf"
> setting in the config.
>
> It might seem like a mistake to compare against remote->url[0] without
> verifying that remote->url_nr >=1, but at this point a missing URL has
> been filled by the name already, therefore url_nr cannot be zero.
>
> Noticed by Anastas Dancha.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx•de>
> ---
> builtin/remote.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/remote.c b/builtin/remote.c
> index 46ecfd9..9168c83 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -180,7 +180,8 @@ static int add(int argc, const char **argv)
> url = argv[1];
>
> remote = remote_get(name);
> - if (remote && (remote->url_nr > 1 || strcmp(name, remote->url[0]) ||
> + if (remote && (remote->url_nr > 1 || (strcmp(name, remote->url[0]) &&
> + strcmp(url, remote->url[0])) ||
> remote->fetch_refspec_nr))
> die(_("remote %s already exists."), name);
When we need to fold an overlong line, it is easier to read if the
line is folded at an operator with higher precedence, i.e. this line
if (A && (B || (C && D) || E))
folded like this
if (A && (B || (C &&
D) ||
E))
is harder to read than when folded like this
if (A && (B ||
(C && D) ||
E))
So, it is an error if we have "remote" and if
(1) URL for the remote is defined already twice or more; or
(2) we are adding a nickname (i.e. not a URL) and it is different
from what we already have; or
(3) we already have fetch_refspec
The way I read the log message's rationale was that this is to allow
replacing an existing remote's URL; wouldn't checking the existence
of fetch_refspec go against that goal?
Puzzled. Either the code is wrong or I am mislead by the
explanation in the log.
next prev parent reply other threads:[~2014-12-22 17:49 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-16 2:30 [PATCH] remote: allow adding remote w same name as alias Anastas Dancha
2014-12-16 9:01 ` Johannes Schindelin
2014-12-16 14:57 ` Anastas Dancha
2014-12-19 9:37 ` Johannes Schindelin
2014-12-19 15:44 ` Anastas Dancha
2014-12-19 16:30 ` Michael J Gruber
2014-12-20 20:57 ` Anastas Dancha
2014-12-21 20:40 ` Johannes Schindelin
2014-12-16 9:33 ` Michael J Gruber
2014-12-22 17:06 ` [PATCH 0/2] Let `git remote add` play nicer with url.<url>.insteadOf Johannes Schindelin
2014-12-22 17:06 ` [PATCH 1/2] git remote add: allow re-adding remotes with the same URL Johannes Schindelin
2014-12-22 17:49 ` Junio C Hamano [this message]
2014-12-23 13:25 ` Johannes Schindelin
[not found] ` <CAPc5daXcXs+Sw8jr65dmLnpf6LQ6Lr34y80bxSf2AhhFyXa_mQ@mail.gmail.com>
2014-12-23 18:26 ` Johannes Schindelin
2014-12-23 18:51 ` Junio C Hamano
2014-12-22 17:06 ` [PATCH 2/2] Add a regression test for 'git remote add <existing> <same-url>' Johannes Schindelin
2014-12-23 13:24 ` [PATCH v2 0/2] Let `git remote add` play nicer with url.<url>.insteadOf Johannes Schindelin
2014-12-23 13:25 ` [PATCH v2 1/2] git remote: allow adding remotes agreeing with url.<...>.insteadOf Johannes Schindelin
2014-12-23 13:25 ` [PATCH v2 2/2] Add a regression test for 'git remote add <existing> <same-url>' Johannes Schindelin
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=xmqq1tnrbmn1.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox$(echo .)com \
--cc=anapsix@random$(echo .)io \
--cc=git@vger$(echo .)kernel.org \
--cc=johannes.schindelin@gmx$(echo .)de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox