aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Gustavsson <bgustavsson@gmail.com>2009-11-09 21:10:32 +0100
committerJunio C Hamano <gitster@pobox.com>2009-11-10 01:01:07 -0800
commit16679e373fa85a75c85e6e3b4ae5cd58a89a4114 (patch)
tree524b0c7624e007c36d00d837484eae17e6a80eb5
parent9c4a036b34acef63ab754f0e27e5e54bd9d9a210 (diff)
downloadgit-16679e373fa85a75c85e6e3b4ae5cd58a89a4114.tar.gz
git-16679e373fa85a75c85e6e3b4ae5cd58a89a4114.tar.xz
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>
-rw-r--r--Documentation/fetch-options.txt6
-rw-r--r--Documentation/git-fetch.txt2
-rw-r--r--builtin-fetch.c11
-rwxr-xr-xt/t5514-fetch-multiple.sh44
4 files changed, 62 insertions, 1 deletions
diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt
index 93d73c3ee..8b0cf5819 100644
--- a/Documentation/fetch-options.txt
+++ b/Documentation/fetch-options.txt
@@ -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[]
diff --git a/Documentation/git-fetch.txt b/Documentation/git-fetch.txt
index 334744c2e..edb77dc54 100644
--- a/Documentation/git-fetch.txt
+++ b/Documentation/git-fetch.txt
@@ -12,6 +12,8 @@ SYNOPSIS
'git fetch' <options> <group>
+'git fetch' --multiple <options> [<repository> | <group>]...
+
'git fetch' --all <options>
diff --git a/builtin-fetch.c b/builtin-fetch.c
index e6bbdc7a1..c903c66d4 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -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,
@@ -798,6 +801,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);
diff --git a/t/t5514-fetch-multiple.sh b/t/t5514-fetch-multiple.sh
index 25244bf8e..69c64ab1e 100755
--- a/t/t5514-fetch-multiple.sh
+++ b/t/t5514-fetch-multiple.sh
@@ -73,4 +73,48 @@ test_expect_success 'git fetch --all does not allow non-option arguments' '
test_must_fail git fetch --all origin master)
'
+cat > expect << EOF
+ origin/HEAD -> origin/master
+ origin/master
+ origin/side
+ three/another
+ three/master
+ three/side
+EOF
+
+test_expect_success 'git fetch --multiple (but only one remote)' '
+ (git clone one test3 &&
+ cd test3 &&
+ git remote add three ../three &&
+ git fetch --multiple three &&
+ git branch -r > output &&
+ test_cmp ../expect output)
+'
+
+cat > expect << EOF
+ one/master
+ one/side
+ origin/HEAD -> origin/master
+ origin/master
+ origin/side
+ two/another
+ two/master
+ two/side
+EOF
+
+test_expect_success 'git fetch --multiple (two remotes)' '
+ (git clone one test4 &&
+ cd test4 &&
+ git remote add one ../one &&
+ git remote add two ../two &&
+ git fetch --multiple one two &&
+ git branch -r > output &&
+ test_cmp ../expect output)
+'
+
+test_expect_success 'git fetch --multiple (bad remote names)' '
+ (cd test4 &&
+ test_must_fail git fetch --multiple four)
+'
+
test_done