Merge branch 'sp/pack-protocol-doc-on-shallow'
[git/mingw.git] / t / t7601-merge-pull-config.sh
blobf768c900abd1cddc6d69a1bdeae897374e7d0dad
1 #!/bin/sh
3 test_description='git merge
5 Testing pull.* configuration parsing.'
7 . ./test-lib.sh
9 test_expect_success 'setup' '
10 echo c0 >c0.c &&
11 git add c0.c &&
12 git commit -m c0 &&
13 git tag c0 &&
14 echo c1 >c1.c &&
15 git add c1.c &&
16 git commit -m c1 &&
17 git tag c1 &&
18 git reset --hard c0 &&
19 echo c2 >c2.c &&
20 git add c2.c &&
21 git commit -m c2 &&
22 git tag c2 &&
23 git reset --hard c0 &&
24 echo c3 >c3.c &&
25 git add c3.c &&
26 git commit -m c3 &&
27 git tag c3
30 test_expect_success 'merge c1 with c2' '
31 git reset --hard c1 &&
32 test -f c0.c &&
33 test -f c1.c &&
34 test ! -f c2.c &&
35 test ! -f c3.c &&
36 git merge c2 &&
37 test -f c1.c &&
38 test -f c2.c
41 test_expect_success 'fast-forward pull succeeds with "true" in pull.ff' '
42 git reset --hard c0 &&
43 test_config pull.ff true &&
44 git pull . c1 &&
45 test "$(git rev-parse HEAD)" = "$(git rev-parse c1)"
48 test_expect_success 'fast-forward pull creates merge with "false" in pull.ff' '
49 git reset --hard c0 &&
50 test_config pull.ff false &&
51 git pull . c1 &&
52 test "$(git rev-parse HEAD^1)" = "$(git rev-parse c0)" &&
53 test "$(git rev-parse HEAD^2)" = "$(git rev-parse c1)"
56 test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' '
57 git reset --hard c1 &&
58 test_config pull.ff only &&
59 test_must_fail git pull . c3
62 test_expect_success 'merge c1 with c2 (ours in pull.twohead)' '
63 git reset --hard c1 &&
64 git config pull.twohead ours &&
65 git merge c2 &&
66 test -f c1.c &&
67 ! test -f c2.c
70 test_expect_success 'merge c1 with c2 and c3 (recursive in pull.octopus)' '
71 git reset --hard c1 &&
72 git config pull.octopus "recursive" &&
73 test_must_fail git merge c2 c3 &&
74 test "$(git rev-parse c1)" = "$(git rev-parse HEAD)"
77 test_expect_success 'merge c1 with c2 and c3 (recursive and octopus in pull.octopus)' '
78 git reset --hard c1 &&
79 git config pull.octopus "recursive octopus" &&
80 git merge c2 c3 &&
81 test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
82 test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
83 test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
84 test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" &&
85 git diff --exit-code &&
86 test -f c0.c &&
87 test -f c1.c &&
88 test -f c2.c &&
89 test -f c3.c
92 conflict_count()
95 git diff-files --name-only
96 git ls-files --unmerged
97 } | wc -l
100 # c4 - c5
101 # \ c6
103 # There are two conflicts here:
105 # 1) Because foo.c is renamed to bar.c, recursive will handle this,
106 # resolve won't.
108 # 2) One in conflict.c and that will always fail.
110 test_expect_success 'setup conflicted merge' '
111 git reset --hard c0 &&
112 echo A >conflict.c &&
113 git add conflict.c &&
114 echo contents >foo.c &&
115 git add foo.c &&
116 git commit -m c4 &&
117 git tag c4 &&
118 echo B >conflict.c &&
119 git add conflict.c &&
120 git mv foo.c bar.c &&
121 git commit -m c5 &&
122 git tag c5 &&
123 git reset --hard c4 &&
124 echo C >conflict.c &&
125 git add conflict.c &&
126 echo secondline >> foo.c &&
127 git add foo.c &&
128 git commit -m c6 &&
129 git tag c6
132 # First do the merge with resolve and recursive then verify that
133 # recursive is chosen.
135 test_expect_success 'merge picks up the best result' '
136 git config --unset-all pull.twohead &&
137 git reset --hard c5 &&
138 test_must_fail git merge -s resolve c6 &&
139 resolve_count=$(conflict_count) &&
140 git reset --hard c5 &&
141 test_must_fail git merge -s recursive c6 &&
142 recursive_count=$(conflict_count) &&
143 git reset --hard c5 &&
144 test_must_fail git merge -s recursive -s resolve c6 &&
145 auto_count=$(conflict_count) &&
146 test $auto_count = $recursive_count &&
147 test $auto_count != $resolve_count
150 test_expect_success 'merge picks up the best result (from config)' '
151 git config pull.twohead "recursive resolve" &&
152 git reset --hard c5 &&
153 test_must_fail git merge -s resolve c6 &&
154 resolve_count=$(conflict_count) &&
155 git reset --hard c5 &&
156 test_must_fail git merge -s recursive c6 &&
157 recursive_count=$(conflict_count) &&
158 git reset --hard c5 &&
159 test_must_fail git merge c6 &&
160 auto_count=$(conflict_count) &&
161 test $auto_count = $recursive_count &&
162 test $auto_count != $resolve_count
165 test_expect_success 'merge errors out on invalid strategy' '
166 git config pull.twohead "foobar" &&
167 git reset --hard c5 &&
168 test_must_fail git merge c6
171 test_expect_success 'merge errors out on invalid strategy' '
172 git config --unset-all pull.twohead &&
173 git reset --hard c5 &&
174 test_must_fail git merge -s "resolve recursive" c6
177 test_done