aboutsummaryrefslogtreecommitdiff
path: root/builtin-fetch.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2010-02-24 11:02:05 -0800
committerJunio C Hamano <gitster@pobox.com>2010-02-24 11:16:36 -0800
commite6cc51046f3669332f51a52a7de966d842b9d4e4 (patch)
treecfeb5cb99a2312d95d219874ac68080f9089f67c /builtin-fetch.c
parentbba5322a71a3399a94f53e1dddf5bd66e493dfbc (diff)
downloadgit-e6cc51046f3669332f51a52a7de966d842b9d4e4.tar.gz
git-e6cc51046f3669332f51a52a7de966d842b9d4e4.tar.xz
fetch --all/--multiple: keep all the fetched branch information
Since "git fetch" learned "--all" and "--multiple" options, it has become tempting for users to say "git pull --all". Even though it may fetch from remotes that do not need to be fetched from for merging with the current branch, it is handy. "git fetch" however clears the list of fetched branches every time it contacts a different remote. Unless the current branch is configured to merge with a branch from a remote that happens to be the last in the list of remotes that are contacted, "git pull" that fetches from multiple remotes will not be able to find the branch it should be merging with. Make "fetch" clear FETCH_HEAD (unless --append is given) and then append the list of branches fetched to it (even when --append is not given). That way, "pull" will be able to find the data for the branch being merged in FETCH_HEAD no matter where the remote appears in the list of remotes to be contacted by "git fetch". Reported-by: Michael Lukashov Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-fetch.c')
-rw-r--r--builtin-fetch.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/builtin-fetch.c b/builtin-fetch.c
index 61b2e4060..b059d652c 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;