diff options
-rw-r--r-- | builtin-fetch.c | 29 | ||||
-rwxr-xr-x | t/t5521-pull-options.sh | 18 |
2 files changed, 40 insertions, 7 deletions
diff --git a/builtin-fetch.c b/builtin-fetch.c index 61b2e4060c..b059d652c6 100644 --- a/builtin-fetch.c +++ b/builtin-fetch.c @@ -651,6 +651,17 @@ static void check_not_current_branch(struct ref *ref_map) "of non-bare repository", current_branch->refname); } +static int truncate_fetch_head(void) +{ + char *filename = git_path("FETCH_HEAD"); + FILE *fp = fopen(filename, "w"); + + if (!fp) + return error("cannot open %s: %s\n", filename, strerror(errno)); + fclose(fp); + return 0; +} + static int do_fetch(struct transport *transport, struct refspec *refs, int ref_count) { @@ -672,11 +683,9 @@ static int do_fetch(struct transport *transport, /* if not appending, truncate FETCH_HEAD */ if (!append && !dry_run) { - char *filename = git_path("FETCH_HEAD"); - FILE *fp = fopen(filename, "w"); - if (!fp) - return error("cannot open %s: %s\n", filename, strerror(errno)); - fclose(fp); + int errcode = truncate_fetch_head(); + if (errcode) + return errcode; } ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags); @@ -784,8 +793,8 @@ static int add_remote_or_group(const char *name, struct string_list *list) static int fetch_multiple(struct string_list *list) { int i, result = 0; - const char *argv[10] = { "fetch" }; - int argc = 1; + const char *argv[11] = { "fetch", "--append" }; + int argc = 2; if (dry_run) argv[argc++] = "--dry-run"; @@ -804,6 +813,12 @@ static int fetch_multiple(struct string_list *list) else if (verbosity < 0) argv[argc++] = "-q"; + if (!append && !dry_run) { + int errcode = truncate_fetch_head(); + if (errcode) + return errcode; + } + for (i = 0; i < list->nr; i++) { const char *name = list->items[i].string; argv[argc] = name; diff --git a/t/t5521-pull-options.sh b/t/t5521-pull-options.sh index 84059d82d5..1b06691bb4 100755 --- a/t/t5521-pull-options.sh +++ b/t/t5521-pull-options.sh @@ -72,4 +72,22 @@ test_expect_success 'git pull --force' ' ) ' +test_expect_success 'git pull --all' ' + mkdir clonedmulti && + (cd clonedmulti && git init && + cat >>.git/config <<-\EOF && + [remote "one"] + url = ../parent + fetch = refs/heads/*:refs/remotes/one/* + [remote "two"] + url = ../parent + fetch = refs/heads/*:refs/remotes/two/* + [branch "master"] + remote = one + merge = refs/heads/master + EOF + git pull --all + ) +' + test_done |