1#!/bin/sh
23
test_description='fetch handles conflicting refspecs correctly'
45
. ./test-lib.sh
67
D=$(pwd)
89
setup_repository () {
10git init "$1" && (
11cd "$1" &&
12git config remote.origin.url "$D" &&
13shift &&
14for refspec in "$@"
15do
16git config --add remote.origin.fetch "$refspec"
17done
18)
19}
2021
test_expect_success 'setup' '
22git commit --allow-empty -m "Initial" &&
23git branch branch1 &&
24git tag tag1 &&
25git commit --allow-empty -m "First" &&
26git branch branch2 &&
27git tag tag2
28'
2930
test_expect_success 'fetch with no conflict' '
31setup_repository ok "+refs/heads/*:refs/remotes/origin/*" && (
32cd ok &&
33git fetch origin
34)
35'
3637
test_expect_success 'fetch conflict: config vs. config' '
38setup_repository ccc \
39"+refs/heads/branch1:refs/remotes/origin/branch1" \
40"+refs/heads/branch2:refs/remotes/origin/branch1" && (
41cd ccc &&
42test_must_fail git fetch origin 2>error &&
43test_i18ngrep "fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1" error
44)
45'
4647
test_expect_success 'fetch duplicate: config vs. config' '
48setup_repository dcc \
49"+refs/heads/*:refs/remotes/origin/*" \
50"+refs/heads/branch1:refs/remotes/origin/branch1" && (
51cd dcc &&
52git fetch origin
53)
54'
5556
test_expect_success 'fetch conflict: arg overrides config' '
57setup_repository aoc \
58"+refs/heads/*:refs/remotes/origin/*" && (
59cd aoc &&
60git fetch origin refs/heads/branch2:refs/remotes/origin/branch1
61)
62'
6364
test_expect_success 'fetch conflict: arg vs. arg' '
65setup_repository caa && (
66cd caa &&
67test_must_fail git fetch origin \
68refs/heads/*:refs/remotes/origin/* \
69refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
70test_i18ngrep "fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1" error
71)
72'
7374
test_expect_success 'fetch conflict: criss-cross args' '
75setup_repository xaa \
76"+refs/heads/*:refs/remotes/origin/*" && (
77cd xaa &&
78git fetch origin \
79refs/heads/branch1:refs/remotes/origin/branch2 \
80refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
81test_i18ngrep "warning: refs/remotes/origin/branch1 usually tracks refs/heads/branch1, not refs/heads/branch2" error &&
82test_i18ngrep "warning: refs/remotes/origin/branch2 usually tracks refs/heads/branch2, not refs/heads/branch1" error
83)
84'
8586
test_done