{"thread":{"id":"21550","subject":"[PATCH 2/5] Teach the --multiple option to 'git fetch'","startedAt":"2009-11-09T20:10:32Z","lastAt":"2009-11-09T20:10:32Z","messageCount":1,"participants":["Björn Gustavsson"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"127193","messageId":"4AF87738.8010205@gmail.com","threadId":"21550","inReplyTo":null,"subject":"[PATCH 2/5] Teach the --multiple option to 'git fetch'","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-11-09T20:10:32Z","receivedAt":"2009-11-09T20:10:32Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"Add the --multiple option to specify that all arguments are either\ngroups or remotes. The primary reason for adding this option is\nto allow us to re-implement 'git remote update' using fetch.\n\nIt would have been nice if this option was not needed, but since\nthe colon in a refspec is optional, it is in general not possible\nto know whether a single, colon-less argument is a remote or a\nrefspec.\n\nSigned-off-by: Björn Gustavsson <bgustavsson@gmail.com>\n---\n Documentation/fetch-options.txt |    6 +++++\n Documentation/git-fetch.txt     |    2 +\n builtin-fetch.c                 |   11 ++++++++-\n t/t5514-fetch-multiple.sh       |   44 +++++++++++++++++++++++++++++++++++++++\n 4 files changed, 62 insertions(+), 1 deletions(-)\n\ndiff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt\nindex 93d73c3..8b0cf58 100644\n--- a/Documentation/fetch-options.txt\n+++ b/Documentation/fetch-options.txt\n@@ -24,6 +24,12 @@\n --keep::\n \tKeep downloaded pack.\n \n+ifndef::git-pull[]\n+--multiple::\n+\tAllow several <repository> and <group> arguments to be\n+\tspecified. No <refspec>s may be specified.\n+endif::git-pull[]\n+\n ifdef::git-pull[]\n --no-tags::\n endif::git-pull[]\ndiff --git a/Documentation/git-fetch.txt b/Documentation/git-fetch.txt\nindex 3616466..9b9e568 100644\n--- a/Documentation/git-fetch.txt\n+++ b/Documentation/git-fetch.txt\n@@ -12,6 +12,8 @@ SYNOPSIS\n \n 'git fetch' <options> <group>\n \n+'git fetch' --multiple <options> [<repository> | <group>]...\n+\n 'git fetch' --all <options>\n \n \ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex 2bf51cc..a5a70a0 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -15,6 +15,7 @@\n static const char * const builtin_fetch_usage[] = {\n \t\"git fetch [options] [<repository> <refspec>...]\",\n \t\"git fetch [options] <group>\",\n+\t\"git fetch --multiple [options] [<repository> | <group>]...\",\n \t\"git fetch --all [options]\",\n \tNULL\n };\n@@ -25,7 +26,7 @@ enum {\n \tTAGS_SET = 2\n };\n \n-static int all, append, force, keep, update_head_ok, verbosity;\n+static int all, append, force, keep, multiple, update_head_ok, verbosity;\n static int tags = TAGS_DEFAULT;\n static const char *depth;\n static const char *upload_pack;\n@@ -42,6 +43,8 @@ static struct option builtin_fetch_options[] = {\n \t\t   \"path to upload pack on remote end\"),\n \tOPT_BOOLEAN('f', \"force\", &force,\n \t\t    \"force overwrite of local branch\"),\n+\tOPT_BOOLEAN('m', \"multiple\", &multiple,\n+\t\t    \"fetch from multiple remotes\"),\n \tOPT_SET_INT('t', \"tags\", &tags,\n \t\t    \"fetch all tags and associated objects\", TAGS_SET),\n \tOPT_SET_INT('n', NULL, &tags,\n@@ -839,6 +842,12 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \t\t/* No arguments -- use default remote */\n \t\tremote = remote_get(NULL);\n \t\tresult = fetch_one(remote, argc, argv);\n+\t} else if (multiple) {\n+\t\t/* All arguments are assumed to be remotes or groups */\n+\t\tfor (i = 0; i < argc; i++)\n+\t\t\tif (!add_remote_or_group(argv[i], &list))\n+\t\t\t\tdie(\"No such remote or remote group: %s\", argv[i]);\n+\t\tresult = fetch_multiple(&list);\n \t} else {\n \t\t/* Single remote or group */\n \t\t(void) add_remote_or_group(argv[0], &list);\ndiff --git a/t/t5514-fetch-multiple.sh b/t/t5514-fetch-multiple.sh\nindex 25244bf..69c64ab 100755\n--- a/t/t5514-fetch-multiple.sh\n+++ b/t/t5514-fetch-multiple.sh\n@@ -73,4 +73,48 @@ test_expect_success 'git fetch --all does not allow non-option arguments' '\n \t test_must_fail git fetch --all origin master)\n '\n \n+cat > expect << EOF\n+  origin/HEAD -> origin/master\n+  origin/master\n+  origin/side\n+  three/another\n+  three/master\n+  three/side\n+EOF\n+\n+test_expect_success 'git fetch --multiple (but only one remote)' '\n+\t(git clone one test3 &&\n+\t cd test3 &&\n+\t git remote add three ../three &&\n+\t git fetch --multiple three &&\n+\t git branch -r > output &&\n+\t test_cmp ../expect output)\n+'\n+\n+cat > expect << EOF\n+  one/master\n+  one/side\n+  origin/HEAD -> origin/master\n+  origin/master\n+  origin/side\n+  two/another\n+  two/master\n+  two/side\n+EOF\n+\n+test_expect_success 'git fetch --multiple (two remotes)' '\n+\t(git clone one test4 &&\n+\t cd test4 &&\n+\t git remote add one ../one &&\n+\t git remote add two ../two &&\n+\t git fetch --multiple one two &&\n+\t git branch -r > output &&\n+\t test_cmp ../expect output)\n+'\n+\n+test_expect_success 'git fetch --multiple (bad remote names)' '\n+\t(cd test4 &&\n+\t test_must_fail git fetch --multiple four)\n+'\n+\n test_done\n-- \n1.6.5.1.69.g36942\n"}]}