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

[PATCH 1/3] fetch: add --allow-local option

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 16, 2013, 07:31 UTC
Message-ID
<1368689474-28911-2-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1368689474-28911-1-git-send-email-felipe.contreras@gmail.com>

So that it becomes possible to override the behavior when the remote tracked is '.'; if it is, we default back to 'origin'.

To do this, we need to add a new helper fetchremote_get() that accepts the boolean to enable/disable this behavior.

The default is 'true' which shouldn't cause any change in behavior.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/fetch.c |  6 +++++-
 remote.c        | 17 ++++++++++++++---
 remote.h        |  1 +
 3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 4b6b1df..2efbd7b 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -39,6 +39,7 @@ static struct strbuf default_rla = STRBUF_INIT;
 static struct transport *transport;
 static const char *submodule_prefix = "";
 static const char *recurse_submodules_default;
+static int allow_local = 1;
 
 static int option_parse_recurse_submodules(const struct option *opt,
 				   const char *arg, int unset)
@@ -90,6 +91,9 @@ static struct option builtin_fetch_options[] = {
 	{ OPTION_STRING, 0, "recurse-submodules-default",
 		   &recurse_submodules_default, NULL,
 		   N_("default mode for recursion"), PARSE_OPT_HIDDEN },
+	{ OPTION_SET_INT, 0, "allow-local", &allow_local, NULL,
+		   N_("allow fetching from local repository"),
+		   PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1 },
 	OPT_END()
 };
 
@@ -1006,7 +1010,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 		result = fetch_multiple(&list);
 	} else if (argc == 0) {
 		/* No arguments -- use default remote */
-		remote = remote_get(NULL);
+		remote = fetchremote_get(NULL, allow_local);
 		result = fetch_one(remote, argc, argv);
 	} else if (multiple) {
 		/* All arguments are assumed to be remotes or groups */
diff --git a/remote.c b/remote.c
index 68eb99b..a7e59ab 100644
--- a/remote.c
+++ b/remote.c
@@ -682,7 +682,7 @@ static int valid_remote_nick(const char *name)
 	return !strchr(name, '/'); /* no slash */
 }
 
-static struct remote *remote_get_1(const char *name, const char *pushremote_name)
+static struct remote *remote_get_1(const char *name, const char *pushremote_name, int allow_local)
 {
 	struct remote *ret;
 	int name_given = 0;
@@ -699,6 +699,11 @@ static struct remote *remote_get_1(const char *name, const char *pushremote_name
 		}
 	}
 
+	if (!allow_local && !strcmp(name, ".")) {
+		name = "origin";
+		name_given = 0;
+	}
+
 	ret = make_remote(name, 0);
 	if (valid_remote_nick(name)) {
 		if (!valid_remote(ret))
@@ -718,13 +723,19 @@ static struct remote *remote_get_1(const char *name, const char *pushremote_name
 struct remote *remote_get(const char *name)
 {
 	read_config();
-	return remote_get_1(name, NULL);
+	return remote_get_1(name, NULL, 1);
 }
 
 struct remote *pushremote_get(const char *name)
 {
 	read_config();
-	return remote_get_1(name, pushremote_name);
+	return remote_get_1(name, pushremote_name, 1);
+}
+
+struct remote *fetchremote_get(const char *name, int allow_local)
+{
+	read_config();
+	return remote_get_1(name, NULL, allow_local);
 }
 
 int remote_is_configured(const char *name)
diff --git a/remote.h b/remote.h
index cf56724..f0d6cf3 100644
--- a/remote.h
+++ b/remote.h
@@ -52,6 +52,7 @@ struct remote {
 
 struct remote *remote_get(const char *name);
 struct remote *pushremote_get(const char *name);
+struct remote *fetchremote_get(const char *name, int allow_local);
 int remote_is_configured(const char *name);
 
 typedef int each_remote_fn(struct remote *remote, void *priv);
-- 
1.8.3.rc1.579.g184e698
Previous: Felipe ContrerasNext: Ramkumar Ramachandra
Message 2 of 31 in “fetch: fix '.' fetching”
  1. 0/3 fetch: fix '.' fetchingFelipe Contreras, May 16, 2013
  2. 1/3 fetch: add --allow-local optionFelipe Contreras, May 16, 2013
  3. Ramkumar RamachandraMay 16, 2013
  4. Felipe ContrerasMay 16, 2013
  5. Ramkumar RamachandraMay 16, 2013
  6. Felipe ContrerasMay 16, 2013
  7. Ramkumar RamachandraMay 16, 2013
  8. Felipe ContrerasMay 16, 2013
  9. Ramkumar RamachandraMay 16, 2013
  10. Felipe ContrerasMay 16, 2013
  11. Junio C HamanoMay 16, 2013
  12. Felipe ContrerasMay 16, 2013
  13. Junio C HamanoMay 16, 2013
  14. Felipe ContrerasMay 16, 2013
  15. Junio C HamanoMay 16, 2013
  16. Felipe ContrerasMay 16, 2013
  17. Junio C HamanoMay 16, 2013
  18. Felipe ContrerasMay 17, 2013
  19. Junio C HamanoMay 17, 2013
  20. Felipe ContrerasMay 18, 2013
  21. Junio C HamanoMay 19, 2013
  22. Felipe ContrerasMay 19, 2013
  23. About overzealous compatibilityFelipe Contreras, May 19, 2013
  24. Felipe ContrerasMay 19, 2013
  25. Philip OakleyMay 18, 2013
  26. Felipe ContrerasMay 18, 2013
  27. Philip OakleyMay 18, 2013
  28. Felipe ContrerasMay 18, 2013
  29. Junio C HamanoMay 19, 2013
  30. 2/3 fetch: switch allow-local off by defaultFelipe Contreras, May 16, 2013
  31. 3/3 remote: disable allow-local for pushesFelipe Contreras, May 16, 2013

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.