[PATCH 1/2] git remote add: allow re-adding remotes with the same URL
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Dec 22, 2014, 17:06 UTC
- Message-ID
- <9c0c693efe68b1c0b080c14104bb6c5f7bf74097.1419267895.git.johannes.schindelin@gmx.de>
- In-Reply-To
- <cover.1419267895.git.johannes.schindelin@gmx.de>
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);
-- 2.0.0.rc3.9669.g840d1f9