Skip to contentSkip to conversation

Teach the --all option to 'git fetch'

PATCH In review Björn Gustavsson 2 participants 3 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Teach the --all option to 'git fetch'

'git remote' is meant for managing remotes and 'git fetch' is meant for actually fetching data from remote repositories. Therefore, it is not logical that you must use 'git remote update' to fetch from several repositories at once. (Junio called 'git remote update' a "half-baked UI experiment that failed" in topic 130891 in Gmane.)

Add the --all option to 'git fetch', to tell it to attempt to fetch from all remotes. (The configuration variable skipDefaultUpdate for the remote will NOT be consulted.)

Other options except -v and -q are silently ignored.

---
See

http://thread.gmane.org/gmane.comp.version-control.git/130819/focus=130891

for a previous discussion.

My implementation is deliberately minimal:

* There is no way to configure that certain remotes should be skipped by the --all option. I have never used skipDefaultUpdate with 'git remote update'. If there is a real need for that feature, it can easily be added. (But it should not use the existing skipDefaultUpdate configuration variable, as the name does not make sense for 'git fetch --all'.)

* All options except -q and -v are silently ignored. It might be useful to support some more options if there is a real need for them. (Perhaps --keep or --no-tags?)

 Documentation/git-fetch.txt |    5 +++
 builtin-fetch.c             |   80 +++++++++++++++++++++++++++++++++++++-----
 t/t5514-fetch-all.sh        |   76 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 151 insertions(+), 10 deletions(-)
 create mode 100755 t/t5514-fetch-all.sh
Documentation/git-fetch.txt +5 -0
index f2483d6..9172454 100644
@@ -10,6 +10,8 @@ SYNOPSIS
 --------
 'git fetch' <options> <repository> <refspec>...
 
+'git fetch' --all <options>
+
 
 DESCRIPTION
 -----------
@@ -31,6 +33,9 @@ branches you are not interested in, you will not get them.
 
 OPTIONS
 -------
+--all::
+	Fetch all remotes.
+
 include::fetch-options.txt[]
 
 include::pull-fetch-param.txt[]
builtin-fetch.c +70 -10

113 lines not on this page · raw message

t/t5514-fetch-all.sh new file +76 -0

76 lines not on this page · raw message

Signature · 1 line
1.6.5.1.69.g36942
#1 lore raw
Quoted 5 lines · Björn Gustavsson

'git remote' is meant for managing remotes and 'git fetch' is meant for actually fetching data from remote repositories. Therefore, it is not logical that you must use 'git remote update' to fetch from several repositories at once. (Junio called 'git remote update' a "half-baked UI experiment that failed" in topic 130891 in Gmane.)

Please drop the "because I said so" part, as I made myself clear in the message I was speaking as mere one-of-participants to the project, not as the maintainer.

Quoted 32 lines
builtin-fetch.c +31 -0
+static int get_one_remote_for_fetch(struct remote *remote, void *priv)
+{
+	struct string_list *list = priv;
+	string_list_append(remote->name, list);
+	return 0;
+}
+
+static int fetch_all(int argc)
+{
+...
+	for (i = 0; i < list.nr; i++) {
+		const char *name = list.items[i].string;
+		argv[argc] = name;
+		if (verbosity >= 0)
+			printf("Fetching %s\n", name);
+		if (run_command_v_opt(argv, RUN_GIT_CMD)) {
+			error("Could not fetch %s", name);
+			result = 1;
+		}
+	}
+...
+}
+
...
+int cmd_fetch(int argc, const char **argv, const char *prefix)
+{
+	int i;
+
+	/* Record the command line for the reflog */
+	strbuf_addstr(&default_rla, "fetch");
+	for (i = 1; i < argc; i++)
+		strbuf_addf(&default_rla, " %s", argv[i]);

builtin-fetch.c static void set_option(const char *name, const char *value)

Quoted 10 lines
builtin-fetch.c +10 -0
+
+	argc = parse_options(argc, argv, prefix,
+			     builtin_fetch_options, builtin_fetch_usage, 0);
+
+	if (all) {
+		return fetch_all(argc);
+	} else {
+		return fetch_one(argc, argv);
+	}
+}

Very nice. I like the simplicity of this.

Hopefully after the parse_options() we can inspect the "repo" argument to see if it names remote groups and transplant the support for that from "remote update" codepath into this, right?

#2 lore raw

2009/11/8 Junio C Hamano <[email protected]>:

Quoted 5 lines

Björn Gustavsson <[email protected]> writes:

Please drop the "because I said so" part, as I made myself clear in the message I was speaking as mere one-of-participants to the project, not as the maintainer.

OK.

Quoted 1 line

Very nice.  I like the simplicity of this.

Thanks!

Quoted 3 lines

Hopefully after the parse_options() we can inspect the "repo" argument to see if it names remote groups and transplant the support for that from "remote update" codepath into this, right?

Yes, it can be done, but it will lose some of its simplicity. I'll send a new patch series that do that soon.

/Björn

Signature · 1 line
Björn Gustavsson, Erlang/OTP, Ericsson AB