Skip to content

Commit da0204d

Browse files
dschospearce
authored andcommitted
fetch: if not fetching from default remote, ignore default merge
When doing "git fetch <remote>" on a remote that does not have the branch referenced in branch.<current-branch>.merge, git fetch failed. It failed because it tried to add the "merge" ref to the refs to be fetched. Fix that. And add a test case. Incidentally, this unconvered a bug in our own test suite, where "git pull <some-path>" was expected to merge the ref given in the defaults, even if not pulling from the default remote. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
1 parent fe5d1d3 commit da0204d

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

builtin-fetch.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ static struct ref *get_ref_map(struct transport *transport,
105105
!remote->fetch[0].pattern)
106106
ref_map->merge = 1;
107107
}
108-
if (has_merge)
108+
/*
109+
* if the remote we're fetching from is the same
110+
* as given in branch.<name>.remote, we add the
111+
* ref given in branch.<name>.merge, too.
112+
*/
113+
if (has_merge && !strcmp(branch->remote_name,
114+
remote->name))
109115
add_merge_config(&ref_map, remote_refs, branch, &tail);
110116
} else {
111117
ref_map = get_remote_ref(remote_refs, "HEAD");

t/t5510-fetch.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,12 @@ test_expect_success 'push via rsync' '
200200
'
201201
}
202202

203+
test_expect_success 'fetch with a non-applying branch.<name>.merge' '
204+
git config branch.master.remote yeti &&
205+
git config branch.master.merge refs/heads/bigfoot &&
206+
git config remote.blub.url one &&
207+
git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
208+
git fetch blub
209+
'
210+
203211
test_done

t/t5700-clone-reference.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ cd "$base_dir"
3838

3939
test_expect_success 'pulling from reference' \
4040
'cd C &&
41-
git pull ../B'
41+
git pull ../B master'
4242

4343
cd "$base_dir"
4444

@@ -61,7 +61,7 @@ test_expect_success 'existence of info/alternates' \
6161
cd "$base_dir"
6262

6363
test_expect_success 'pulling from reference' \
64-
'cd D && git pull ../B'
64+
'cd D && git pull ../B master'
6565

6666
cd "$base_dir"
6767

0 commit comments

Comments
 (0)