Skip to content

Commit

Permalink
fetch: if not fetching from default remote, ignore default merge
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Schindelin authored and Shawn O. Pearce committed Oct 16, 2007
1 parent fe5d1d3 commit da0204d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion builtin-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ static struct ref *get_ref_map(struct transport *transport,
!remote->fetch[0].pattern)
ref_map->merge = 1;
}
if (has_merge)
/*
* if the remote we're fetching from is the same
* as given in branch.<name>.remote, we add the
* ref given in branch.<name>.merge, too.
*/
if (has_merge && !strcmp(branch->remote_name,
remote->name))
add_merge_config(&ref_map, remote_refs, branch, &tail);
} else {
ref_map = get_remote_ref(remote_refs, "HEAD");
Expand Down
8 changes: 8 additions & 0 deletions t/t5510-fetch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,12 @@ test_expect_success 'push via rsync' '
'
}

test_expect_success 'fetch with a non-applying branch.<name>.merge' '
git config branch.master.remote yeti &&
git config branch.master.merge refs/heads/bigfoot &&
git config remote.blub.url one &&
git config remote.blub.fetch "refs/heads/*:refs/remotes/one/*" &&
git fetch blub
'

test_done
4 changes: 2 additions & 2 deletions t/t5700-clone-reference.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cd "$base_dir"

test_expect_success 'pulling from reference' \
'cd C &&
git pull ../B'
git pull ../B master'

cd "$base_dir"

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

test_expect_success 'pulling from reference' \
'cd D && git pull ../B'
'cd D && git pull ../B master'

cd "$base_dir"

Expand Down

0 comments on commit da0204d

Please sign in to comment.