Skip to contentSkip to conversation

Teach the --multiple option to 'git fetch'

PATCH New Björn Gustavsson 1 participant 1 message Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 2/5 Teach the --multiple option to 'git fetch'

Add the --multiple option to specify that all arguments are either groups or remotes. The primary reason for adding this option is to allow us to re-implement 'git remote update' using fetch.

It would have been nice if this option was not needed, but since the colon in a refspec is optional, it is in general not possible to know whether a single, colon-less argument is a remote or a refspec.

---
 Documentation/fetch-options.txt |    6 +++++
 Documentation/git-fetch.txt     |    2 +
 builtin-fetch.c                 |   11 ++++++++-
 t/t5514-fetch-multiple.sh       |   44 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 62 insertions(+), 1 deletions(-)
Documentation/fetch-options.txt +6 -0
index 93d73c3..8b0cf58 100644
@@ -24,6 +24,12 @@
 --keep::
 	Keep downloaded pack.
 
+ifndef::git-pull[]
+--multiple::
+	Allow several <repository> and <group> arguments to be
+	specified. No <refspec>s may be specified.
+endif::git-pull[]
+
 ifdef::git-pull[]
 --no-tags::
 endif::git-pull[]
Documentation/git-fetch.txt +2 -0
index 3616466..9b9e568 100644
@@ -12,6 +12,8 @@ SYNOPSIS
 
 'git fetch' <options> <group>
 
+'git fetch' --multiple <options> [<repository> | <group>]...
+
 'git fetch' --all <options>
 
 
builtin-fetch.c +10 -1
index 2bf51cc..a5a70a0 100644
@@ -15,6 +15,7 @@
 static const char * const builtin_fetch_usage[] = {
 	"git fetch [options] [<repository> <refspec>...]",
 	"git fetch [options] <group>",
+	"git fetch --multiple [options] [<repository> | <group>]...",
 	"git fetch --all [options]",
 	NULL
 };
@@ -25,7 +26,7 @@ enum {
 	TAGS_SET = 2
 };
 
-static int all, append, force, keep, update_head_ok, verbosity;
+static int all, append, force, keep, multiple, update_head_ok, verbosity;
 static int tags = TAGS_DEFAULT;
 static const char *depth;
 static const char *upload_pack;
@@ -42,6 +43,8 @@ static struct option builtin_fetch_options[] = {
 		   "path to upload pack on remote end"),
 	OPT_BOOLEAN('f', "force", &force,
 		    "force overwrite of local branch"),
+	OPT_BOOLEAN('m', "multiple", &multiple,
+		    "fetch from multiple remotes"),
 	OPT_SET_INT('t', "tags", &tags,
 		    "fetch all tags and associated objects", TAGS_SET),
 	OPT_SET_INT('n', NULL, &tags,
@@ -839,6 +842,12 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
 		/* No arguments -- use default remote */
 		remote = remote_get(NULL);
 		result = fetch_one(remote, argc, argv);
+	} else if (multiple) {
+		/* All arguments are assumed to be remotes or groups */
+		for (i = 0; i < argc; i++)
+			if (!add_remote_or_group(argv[i], &list))
+				die("No such remote or remote group: %s", argv[i]);
+		result = fetch_multiple(&list);
 	} else {
 		/* Single remote or group */
 		(void) add_remote_or_group(argv[0], &list);
t/t5514-fetch-multiple.sh +44 -0

48 lines not on this page · raw message

Signature · 1 line
1.6.5.1.69.g36942