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. Signed-off-by: Björn Gustavsson <bgustavsson@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Björn Gustavsson committed
Nov 9, 2009 at 21:10 UTC
16679e373fa85a75c85e6e3b4ae5cd58a89a4114
4 files changed
+62
-1
Documentation/fetch-options.txt
+6
@@ -24,6 +24,12 @@
24
--keep::
25
Keep downloaded pack.
26
27
+ifndef::git-pull[]
28
+--multiple::
29
+ Allow several <repository> and <group> arguments to be
30
+ specified. No <refspec>s may be specified.
31
+endif::git-pull[]
32
+
33
ifdef::git-pull[]
34
--no-tags::
35
endif::git-pull[]
Documentation/git-fetch.txt
+2
@@ -12,6 +12,8 @@ SYNOPSIS
12
13
'git fetch' <options> <group>
14
15
+'git fetch' --multiple <options> [<repository> | <group>]...
16
+
17
'git fetch' --all <options>
18
19
builtin-fetch.c
+10
-1
@@ -15,6 +15,7 @@
15
static const char * const builtin_fetch_usage[] = {
16
"git fetch [options] [<repository> <refspec>...]",
17
"git fetch [options] <group>",
18
+ "git fetch --multiple [options] [<repository> | <group>]...",
19
"git fetch --all [options]",
20
NULL
21
};
@@ -25,7 +26,7 @@ enum {
26
TAGS_SET = 2
27
};
28
28
-static int all, append, force, keep, update_head_ok, verbosity;
29
+static int all, append, force, keep, multiple, update_head_ok, verbosity;
30
static int tags = TAGS_DEFAULT;
31
static const char *depth;
32
static const char *upload_pack;
@@ -42,6 +43,8 @@ static struct option builtin_fetch_options[] = {
43
"path to upload pack on remote end"),
44
OPT_BOOLEAN('f', "force", &force,
45
"force overwrite of local branch"),
46
+ OPT_BOOLEAN('m', "multiple", &multiple,
47
+ "fetch from multiple remotes"),
48
OPT_SET_INT('t', "tags", &tags,
49
"fetch all tags and associated objects", TAGS_SET),
50
OPT_SET_INT('n', NULL, &tags,
@@ -798,6 +801,12 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
801
/* No arguments -- use default remote */
802
remote = remote_get(NULL);
803
result = fetch_one(remote, argc, argv);
804
+ } else if (multiple) {
805
+ /* All arguments are assumed to be remotes or groups */
806
+ for (i = 0; i < argc; i++)
807
+ if (!add_remote_or_group(argv[i], &list))
808
+ die("No such remote or remote group: %s", argv[i]);
809
+ result = fetch_multiple(&list);
810
} else {
811
/* Single remote or group */
812
(void) add_remote_or_group(argv[0], &list);
t/t5514-fetch-multiple.sh
+44
@@ -73,4 +73,48 @@ test_expect_success 'git fetch --all does not allow non-option arguments' '
73
test_must_fail git fetch --all origin master)
74
'
75
76
+cat > expect << EOF
77
+ origin/HEAD -> origin/master
78
+ origin/master
79
+ origin/side
80
+ three/another
81
+ three/master
82
+ three/side
83
+EOF
84
+
85
+test_expect_success 'git fetch --multiple (but only one remote)' '
86
+ (git clone one test3 &&
87
+ cd test3 &&
88
+ git remote add three ../three &&
89
+ git fetch --multiple three &&
90
+ git branch -r > output &&
91
+ test_cmp ../expect output)
92
+'
93
+
94
+cat > expect << EOF
95
+ one/master
96
+ one/side
97
+ origin/HEAD -> origin/master
98
+ origin/master
99
+ origin/side
100
+ two/another
101
+ two/master
102
+ two/side
103
+EOF
104
+
105
+test_expect_success 'git fetch --multiple (two remotes)' '
106
+ (git clone one test4 &&
107
+ cd test4 &&
108
+ git remote add one ../one &&
109
+ git remote add two ../two &&
110
+ git fetch --multiple one two &&
111
+ git branch -r > output &&
112
+ test_cmp ../expect output)
113
+'
114
+
115
+test_expect_success 'git fetch --multiple (bad remote names)' '
116
+ (cd test4 &&
117
+ test_must_fail git fetch --multiple four)
118
+'
119
+
120
test_done