git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] Be more careful when determining whether a remote was configured

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 17, 2017, 21:19 UTC
Message-ID
<41c347f22c80e96c54db34baa739b6e37e268b61.1484687919.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1484687919.git.johannes.schindelin@gmx.de>

One of the really nice features of the ~/.gitconfig file is that users can override defaults by their own preferred settings for all of their repositories.

One such default that some users like to override is whether the "origin" remote gets auto-pruned or not. The user would simply call

	git config --global remote.origin.prune true

and from now on all "origin" remotes would be pruned automatically when fetching into the local repository.

There is just one catch: now Git thinks that the "origin" remote is configured, as it does not discern between having a remote whose fetch (and/or push) URL and refspec is set, and merely having preemptively-configured, global flags for specific remotes.

Let's fix this by telling Git that a remote is not configured unless any fetch/push URL or refspect is configured explicitly.

As a special exception, we deem a remote configured also when *only* the "vcs" setting is configured. The commit a31eeae27f (remote: use remote_is_configured() for add and rename, 2016-02-16) specifically extended our test suite to verify this, so it is safe to assume that there has been at least one user with a legitimate use case for this.

This fixes https://github.com/git-for-windows/git/issues/888
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 remote.c          | 9 ++++++++-
 remote.h          | 2 +-
 t/t5505-remote.sh | 2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/remote.c b/remote.c
index ad6c5424ed..298f2f93fa 100644
--- a/remote.c
+++ b/remote.c
@@ -255,6 +255,7 @@ static void read_remotes_file(struct remote *remote)
 
 	if (!f)
 		return;
+	remote->configured = 1;
 	remote->origin = REMOTE_REMOTES;
 	while (strbuf_getline(&buf, f) != EOF) {
 		const char *v;
@@ -289,6 +290,7 @@ static void read_branches_file(struct remote *remote)
 		return;
 	}
 
+	remote->configured = 1;
 	remote->origin = REMOTE_BRANCHES;
 
 	/*
@@ -384,21 +386,25 @@ static int handle_config(const char *key, const char *value, void *cb)
 		if (git_config_string(&v, key, value))
 			return -1;
 		add_url(remote, v);
+		remote->configured = 1;
 	} else if (!strcmp(subkey, "pushurl")) {
 		const char *v;
 		if (git_config_string(&v, key, value))
 			return -1;
 		add_pushurl(remote, v);
+		remote->configured = 1;
 	} else if (!strcmp(subkey, "push")) {
 		const char *v;
 		if (git_config_string(&v, key, value))
 			return -1;
 		add_push_refspec(remote, v);
+		remote->configured = 1;
 	} else if (!strcmp(subkey, "fetch")) {
 		const char *v;
 		if (git_config_string(&v, key, value))
 			return -1;
 		add_fetch_refspec(remote, v);
+		remote->configured = 1;
 	} else if (!strcmp(subkey, "receivepack")) {
 		const char *v;
 		if (git_config_string(&v, key, value))
@@ -427,6 +433,7 @@ static int handle_config(const char *key, const char *value, void *cb)
 		return git_config_string((const char **)&remote->http_proxy_authmethod,
 					 key, value);
 	} else if (!strcmp(subkey, "vcs")) {
+		remote->configured = 1;
 		return git_config_string(&remote->foreign_vcs, key, value);
 	}
 	return 0;
@@ -716,7 +723,7 @@ struct remote *pushremote_get(const char *name)
 
 int remote_is_configured(struct remote *remote)
 {
-	return remote && remote->origin;
+	return remote && remote->configured;
 }
 
 int for_each_remote(each_remote_fn fn, void *priv)
diff --git a/remote.h b/remote.h
index 924881169d..7e6c8067bb 100644
--- a/remote.h
+++ b/remote.h
@@ -15,7 +15,7 @@ struct remote {
 	struct hashmap_entry ent;  /* must be first */
 
 	const char *name;
-	int origin;
+	int origin, configured;
 
 	const char *foreign_vcs;
 
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index d7e41e9230..09c9823002 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -764,7 +764,7 @@ test_expect_success 'rename a remote with name prefix of other remote' '
 	)
 '
 
-test_expect_failure 'rename succeeds with existing remote.<target>.prune' '
+test_expect_success 'rename succeeds with existing remote.<target>.prune' '
 	git clone one four.four &&
 	(
 		cd four.four &&
-- 
2.11.0.windows.3
Previous: Johannes SchindelinNext: Jeff King
Message 3 of 21 in “Fix remote_is_configured()”
  1. 0/2 Fix remote_is_configured()Johannes Schindelin, Jan 17, 2017
  2. 1/2 remote rename: demonstrate a bogus "remote exists" bugJohannes Schindelin, Jan 17, 2017
  3. 2/2 Be more careful when determining whether a remote was configuredJohannes Schindelin, Jan 17, 2017
  4. Jeff KingJan 17, 2017
  5. Junio C HamanoJan 17, 2017
  6. Johannes SchindelinJan 18, 2017
  7. Johannes SchindelinJan 18, 2017
  8. Jeff KingJan 18, 2017
  9. Johannes SchindelinJan 18, 2017
  10. Jeff KingJan 19, 2017
  11. Junio C HamanoJan 19, 2017
  12. Jeff KingJan 19, 2017
  13. Johannes SchindelinJan 19, 2017
  14. Jeff KingJan 17, 2017
  15. 0/2 Fix remote_is_configured()Johannes Schindelin, Jan 19, 2017
  16. 1/2 remote rename: demonstrate a bogus "remote exists" bugJohannes Schindelin, Jan 19, 2017
  17. 2/2 Be more careful when determining whether a remote was configuredJohannes Schindelin, Jan 19, 2017
  18. Jeff KingJan 19, 2017
  19. Johannes SchindelinJan 19, 2017
  20. Junio C HamanoJan 19, 2017
  21. Jeff KingJan 19, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.