From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Jens Lehmann <Jens.Lehmann@web.de>,
Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH 1/3] fetch: add --allow-local option
Date: Thu, 16 May 2013 02:31:12 -0500 [thread overview]
Message-ID: <1368689474-28911-2-git-send-email-felipe.contreras@gmail.com> (raw)
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
next prev parent reply other threads:[~2013-05-16 7:32 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-16 7:31 [PATCH 0/3] fetch: fix '.' fetching Felipe Contreras
2013-05-16 7:31 ` Felipe Contreras [this message]
2013-05-16 8:25 ` [PATCH 1/3] fetch: add --allow-local option Ramkumar Ramachandra
2013-05-16 8:53 ` Felipe Contreras
2013-05-16 9:27 ` Ramkumar Ramachandra
2013-05-16 9:34 ` Felipe Contreras
2013-05-16 9:58 ` Ramkumar Ramachandra
2013-05-16 10:27 ` Felipe Contreras
2013-05-16 10:32 ` Ramkumar Ramachandra
2013-05-16 12:54 ` Felipe Contreras
2013-05-16 15:58 ` Junio C Hamano
2013-05-16 16:26 ` Felipe Contreras
2013-05-16 16:38 ` Junio C Hamano
2013-05-16 16:52 ` Felipe Contreras
2013-05-16 18:04 ` Junio C Hamano
2013-05-16 23:07 ` Felipe Contreras
2013-05-16 23:24 ` Junio C Hamano
2013-05-17 0:04 ` Felipe Contreras
2013-05-17 18:30 ` Junio C Hamano
2013-05-18 12:25 ` Felipe Contreras
2013-05-19 5:51 ` Junio C Hamano
2013-05-19 6:10 ` Felipe Contreras
2013-05-19 7:56 ` About overzealous compatibility Felipe Contreras
2013-05-19 14:27 ` Felipe Contreras
2013-05-18 13:12 ` [PATCH 1/3] fetch: add --allow-local option Philip Oakley
2013-05-18 14:23 ` Felipe Contreras
2013-05-18 20:53 ` Philip Oakley
2013-05-18 22:26 ` Felipe Contreras
2013-05-19 6:10 ` Junio C Hamano
2013-05-16 7:31 ` [PATCH 2/3] fetch: switch allow-local off by default Felipe Contreras
2013-05-16 7:31 ` [PATCH 3/3] remote: disable allow-local for pushes Felipe Contreras
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1368689474-28911-2-git-send-email-felipe.contreras@gmail.com \
--to=felipe.contreras@gmail.com \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).