Skip to content

Commit 2071e05

Browse files
mhaggergitster
authored andcommitted
t5536: new test of refspec conflicts when fetching
Add some tests that "git fetch" handles refspec conflicts (i.e., when the same local reference should be updated from two different remote references) correctly. There is a small bug when updating references opportunistically, namely that an explicit user wish like git fetch origin \ refs/heads/branch1:refs/remotes/origin/branch2 \ refs/heads/branch2:refs/remotes/origin/branch1 should override a configured refspec like +refs/heads/*:refs/remotes/origin/* The current code incorrectly treats this as a fatal error. In a few commits we will improve the error messages for refspec conflicts in general and also turn this buggy fatal error into a warning. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 09ea1f8 commit 2071e05

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

t/t5536-fetch-conflicts.sh

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/bin/sh
2+
3+
test_description='fetch handles conflicting refspecs correctly'
4+
5+
. ./test-lib.sh
6+
7+
D=$(pwd)
8+
9+
setup_repository () {
10+
git init "$1" && (
11+
cd "$1" &&
12+
git config remote.origin.url "$D" &&
13+
shift &&
14+
for refspec in "$@"
15+
do
16+
git config --add remote.origin.fetch "$refspec"
17+
done
18+
)
19+
}
20+
21+
verify_stderr () {
22+
cat >expected &&
23+
# We're not interested in the error
24+
# "fatal: The remote end hung up unexpectedly":
25+
grep -v "hung up" <error >actual &&
26+
test_cmp expected actual
27+
}
28+
29+
test_expect_success 'setup' '
30+
git commit --allow-empty -m "Initial" &&
31+
git branch branch1 &&
32+
git tag tag1 &&
33+
git commit --allow-empty -m "First" &&
34+
git branch branch2 &&
35+
git tag tag2
36+
'
37+
38+
test_expect_success 'fetch with no conflict' '
39+
setup_repository ok "+refs/heads/*:refs/remotes/origin/*" && (
40+
cd ok &&
41+
git fetch origin
42+
)
43+
'
44+
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" && (
49+
cd ccc &&
50+
test_must_fail git fetch origin 2>error &&
51+
verify_stderr <<-\EOF
52+
fatal: refs/remotes/origin/branch1 tracks both refs/heads/branch1 and refs/heads/branch2
53+
EOF
54+
)
55+
'
56+
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" && (
61+
cd dcc &&
62+
git fetch origin
63+
)
64+
'
65+
66+
test_expect_success 'fetch conflict: arg overrides config' '
67+
setup_repository aoc \
68+
"+refs/heads/*:refs/remotes/origin/*" && (
69+
cd aoc &&
70+
git fetch origin refs/heads/branch2:refs/remotes/origin/branch1
71+
)
72+
'
73+
74+
test_expect_success 'fetch conflict: arg vs. arg' '
75+
setup_repository caa && (
76+
cd caa &&
77+
test_must_fail git fetch origin \
78+
refs/heads/*:refs/remotes/origin/* \
79+
refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
80+
verify_stderr <<-\EOF
81+
fatal: refs/remotes/origin/branch1 tracks both refs/heads/branch1 and refs/heads/branch2
82+
EOF
83+
)
84+
'
85+
86+
test_expect_failure 'fetch conflict: criss-cross args' '
87+
setup_repository xaa \
88+
"+refs/heads/*:refs/remotes/origin/*" && (
89+
cd xaa &&
90+
git fetch origin \
91+
refs/heads/branch1:refs/remotes/origin/branch2 \
92+
refs/heads/branch2:refs/remotes/origin/branch1
93+
)
94+
'
95+
96+
test_done

0 commit comments

Comments
 (0)