The 20th batch
[alt-git.git] / t / t5536-fetch-conflicts.sh
blob2dcbe790523cc3e53ad6ad100242d52f92fabf51
1 #!/bin/sh
3 test_description='fetch handles conflicting refspecs correctly'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 D=$(pwd)
10 setup_repository () {
11 git init "$1" && (
12 cd "$1" &&
13 git config remote.origin.url "$D" &&
14 shift &&
15 for refspec in "$@"
17 git config --add remote.origin.fetch "$refspec"
18 done
22 test_expect_success 'setup' '
23 git commit --allow-empty -m "Initial" &&
24 git branch branch1 &&
25 git tag tag1 &&
26 git commit --allow-empty -m "First" &&
27 git branch branch2 &&
28 git tag tag2
31 test_expect_success 'fetch with no conflict' '
32 setup_repository ok "+refs/heads/*:refs/remotes/origin/*" && (
33 cd ok &&
34 git fetch origin
38 test_expect_success 'fetch conflict: config vs. config' '
39 setup_repository ccc \
40 "+refs/heads/branch1:refs/remotes/origin/branch1" \
41 "+refs/heads/branch2:refs/remotes/origin/branch1" && (
42 cd ccc &&
43 test_must_fail git fetch origin 2>error &&
44 test_grep "fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1" error
48 test_expect_success 'fetch duplicate: config vs. config' '
49 setup_repository dcc \
50 "+refs/heads/*:refs/remotes/origin/*" \
51 "+refs/heads/branch1:refs/remotes/origin/branch1" && (
52 cd dcc &&
53 git fetch origin
57 test_expect_success 'fetch conflict: arg overrides config' '
58 setup_repository aoc \
59 "+refs/heads/*:refs/remotes/origin/*" && (
60 cd aoc &&
61 git fetch origin refs/heads/branch2:refs/remotes/origin/branch1
65 test_expect_success 'fetch conflict: arg vs. arg' '
66 setup_repository caa && (
67 cd caa &&
68 test_must_fail git fetch origin \
69 refs/heads/*:refs/remotes/origin/* \
70 refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
71 test_grep "fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1" error
75 test_expect_success 'fetch conflict: criss-cross args' '
76 setup_repository xaa \
77 "+refs/heads/*:refs/remotes/origin/*" && (
78 cd xaa &&
79 git fetch origin \
80 refs/heads/branch1:refs/remotes/origin/branch2 \
81 refs/heads/branch2:refs/remotes/origin/branch1 2>error &&
82 test_grep "warning: refs/remotes/origin/branch1 usually tracks refs/heads/branch1, not refs/heads/branch2" error &&
83 test_grep "warning: refs/remotes/origin/branch2 usually tracks refs/heads/branch2, not refs/heads/branch1" error
87 test_done