Skip to content

Commit 16679e3

Browse files
bjornggitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9c4a036 commit 16679e3

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

Documentation/fetch-options.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
--keep::
2525
Keep downloaded pack.
2626

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+
2733
ifdef::git-pull[]
2834
--no-tags::
2935
endif::git-pull[]

Documentation/git-fetch.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ SYNOPSIS
1212

1313
'git fetch' <options> <group>
1414

15+
'git fetch' --multiple <options> [<repository> | <group>]...
16+
1517
'git fetch' --all <options>
1618

1719

builtin-fetch.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
static const char * const builtin_fetch_usage[] = {
1616
"git fetch [options] [<repository> <refspec>...]",
1717
"git fetch [options] <group>",
18+
"git fetch --multiple [options] [<repository> | <group>]...",
1819
"git fetch --all [options]",
1920
NULL
2021
};
@@ -25,7 +26,7 @@ enum {
2526
TAGS_SET = 2
2627
};
2728

28-
static int all, append, force, keep, update_head_ok, verbosity;
29+
static int all, append, force, keep, multiple, update_head_ok, verbosity;
2930
static int tags = TAGS_DEFAULT;
3031
static const char *depth;
3132
static const char *upload_pack;
@@ -42,6 +43,8 @@ static struct option builtin_fetch_options[] = {
4243
"path to upload pack on remote end"),
4344
OPT_BOOLEAN('f', "force", &force,
4445
"force overwrite of local branch"),
46+
OPT_BOOLEAN('m', "multiple", &multiple,
47+
"fetch from multiple remotes"),
4548
OPT_SET_INT('t', "tags", &tags,
4649
"fetch all tags and associated objects", TAGS_SET),
4750
OPT_SET_INT('n', NULL, &tags,
@@ -798,6 +801,12 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
798801
/* No arguments -- use default remote */
799802
remote = remote_get(NULL);
800803
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);
801810
} else {
802811
/* Single remote or group */
803812
(void) add_remote_or_group(argv[0], &list);

t/t5514-fetch-multiple.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,48 @@ test_expect_success 'git fetch --all does not allow non-option arguments' '
7373
test_must_fail git fetch --all origin master)
7474
'
7575

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+
76120
test_done

0 commit comments

Comments
 (0)