3 test_description='fetch handles conflicting refspecs correctly'
12 git config remote.origin.url "$D" &&
16 git config --add remote.origin.fetch "$refspec"
23 # We're not interested in the error
24 # "fatal: The remote end hung up unexpectedly":
25 grep -E '^(fatal|warning):' <error | grep -v 'hung up' >actual | sort &&
26 test_cmp expected actual
29 test_expect_success 'setup' '
30 git commit --allow-empty -m "Initial" &&
33 git commit --allow-empty -m "First" &&
38 test_expect_success 'fetch with no conflict' '
39 setup_repository ok "+refs/heads/*:refs/remotes/origin/*" && (
45 test_expect_success 'fetch conflict: config vs. config' '
46 setup_repository ccc \
47 "+refs/heads/branch1:refs/remotes/origin/branch1" \
48 "+refs/heads/branch2:refs/remotes/origin/branch1" && (
50 test_must_fail git fetch origin 2>error &&
52 fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1
57 test_expect_success 'fetch duplicate: config vs. config' '
58 setup_repository dcc \
59 "+refs/heads/*:refs/remotes/origin/*" \
60 "+refs/heads/branch1:refs/remotes/origin/branch1" && (
66 test_expect_success 'fetch conflict: arg overrides config' '
67 setup_repository aoc \
68 "+refs/heads/*:refs/remotes/origin/*" && (
70 git fetch origin refs/heads/branch2:refs/remotes/origin/branch1
74 test_expect_success 'fetch conflict: arg vs. arg' '
75 setup_repository caa && (
77 test_must_fail git fetch origin \
78 refs/heads/*:refs/remotes/origin/* \
79 refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
81 fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1
86 test_expect_success 'fetch conflict: criss-cross args' '
87 setup_repository xaa \
88 "+refs/heads/*:refs/remotes/origin/*" && (
91 refs/heads/branch1:refs/remotes/origin/branch2 \
92 refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
94 warning: refs/remotes/origin/branch1 usually tracks refs/heads/branch1, not refs/heads/branch2
95 warning: refs/remotes/origin/branch2 usually tracks refs/heads/branch2, not refs/heads/branch1