Optimize "diff-index --cached" using cache-tree
[git/dscho.git] / t / t7601-merge-pull-config.sh
blob7ba94ea99bc0785da5b398e494d23469ba44992d
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 'merge c1 with c2 (ours in pull.twohead)' '
42 git reset --hard c1 &&
43 git config pull.twohead ours &&
44 git merge c2 &&
45 test -f c1.c &&
46 ! test -f c2.c
49 test_expect_success 'merge c1 with c2 and c3 (recursive in pull.octopus)' '
50 git reset --hard c1 &&
51 git config pull.octopus "recursive" &&
52 test_must_fail git merge c2 c3 &&
53 test "$(git rev-parse c1)" = "$(git rev-parse HEAD)"
56 test_expect_success 'merge c1 with c2 and c3 (recursive and octopus in pull.octopus)' '
57 git reset --hard c1 &&
58 git config pull.octopus "recursive octopus" &&
59 git merge c2 c3 &&
60 test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" &&
61 test "$(git rev-parse c1)" = "$(git rev-parse HEAD^1)" &&
62 test "$(git rev-parse c2)" = "$(git rev-parse HEAD^2)" &&
63 test "$(git rev-parse c3)" = "$(git rev-parse HEAD^3)" &&
64 git diff --exit-code &&
65 test -f c0.c &&
66 test -f c1.c &&
67 test -f c2.c &&
68 test -f c3.c
71 conflict_count()
74 git diff-files --name-only
75 git ls-files --unmerged
76 } | wc -l
79 # c4 - c5
80 # \ c6
82 # There are two conflicts here:
84 # 1) Because foo.c is renamed to bar.c, recursive will handle this,
85 # resolve won't.
87 # 2) One in conflict.c and that will always fail.
89 test_expect_success 'setup conflicted merge' '
90 git reset --hard c0 &&
91 echo A >conflict.c &&
92 git add conflict.c &&
93 echo contents >foo.c &&
94 git add foo.c &&
95 git commit -m c4 &&
96 git tag c4 &&
97 echo B >conflict.c &&
98 git add conflict.c &&
99 git mv foo.c bar.c &&
100 git commit -m c5 &&
101 git tag c5 &&
102 git reset --hard c4 &&
103 echo C >conflict.c &&
104 git add conflict.c &&
105 echo secondline >> foo.c &&
106 git add foo.c &&
107 git commit -m c6 &&
108 git tag c6
111 # First do the merge with resolve and recursive then verify that
112 # recusive is choosen.
114 test_expect_success 'merge picks up the best result' '
115 git config --unset-all pull.twohead &&
116 git reset --hard c5 &&
117 git merge -s resolve c6
118 resolve_count=$(conflict_count) &&
119 git reset --hard c5 &&
120 git merge -s recursive c6
121 recursive_count=$(conflict_count) &&
122 git reset --hard c5 &&
123 git merge -s recursive -s resolve c6
124 auto_count=$(conflict_count) &&
125 test $auto_count = $recursive_count &&
126 test $auto_count != $resolve_count
129 test_expect_success 'merge picks up the best result (from config)' '
130 git config pull.twohead "recursive resolve" &&
131 git reset --hard c5 &&
132 git merge -s resolve c6
133 resolve_count=$(conflict_count) &&
134 git reset --hard c5 &&
135 git merge -s recursive c6
136 recursive_count=$(conflict_count) &&
137 git reset --hard c5 &&
138 git merge c6
139 auto_count=$(conflict_count) &&
140 test $auto_count = $recursive_count &&
141 test $auto_count != $resolve_count
144 test_expect_success 'merge errors out on invalid strategy' '
145 git config pull.twohead "foobar" &&
146 git reset --hard c5 &&
147 test_must_fail git merge c6
150 test_expect_success 'merge errors out on invalid strategy' '
151 git config --unset-all pull.twohead &&
152 git reset --hard c5 &&
153 test_must_fail git merge -s "resolve recursive" c6
156 test_done