3 # Copyright (c) 2005 Petr Baudis
5 test_description
="Tests cg-merge done on a tree with local modifications
7 Under certain conditions, cg-merge can be done even on a tree with local
8 modifications. This test should ensure that no local changes are lost, while
9 they also shan't interfere with the committed merge."
17 test_expect_success
'local change on branch1 (add, should block)' \
18 "(cd branch1 && echo boo >y && cg-add y)"
19 cp branch
1/y branch
1/y-
20 test_expect_failure
"merging branch2 to branch1 ($1)" \
21 "(cd branch1 && cg-merge </dev/null)"
22 test_expect_success
'checking if we still have our local change' \
23 '(cd branch1 && cg-status -w | grep -q "^A y" && cmp y y-)'
24 test_expect_success
'undoing the local change' \
25 '(cd branch1 && cg-rm -f y)'
26 test_expect_success
'confirming that we have no uncommitted modifications' \
27 '(cd branch1 && [ -z "$(git-diff-index -r $(cg-object-id -t))" ])'
30 commit_and_propagate
()
32 test_expect_success
'local commit in branch2' \
33 "(cd branch2 && cg-commit -m\"Some commit\")"
34 test_expect_success
'fetching from branch2 to branch1' \
35 "(cd branch1 && cg-fetch)"
39 # The blank space is to prevent conflicts for automatic merges.
40 cat >branch
1/brm
<<__END__
58 test_expect_success
'initialize branch1' \
59 "(cd branch1 && cg-init -I && cg-add brm foo bar && cg-commit -C -m\"Initial commit\")"
60 test_expect_success
'fork branch2' \
61 "cg-clone branch1 branch2"
62 test_expect_success
'registering branch2 in branch1' \
63 "(cd branch1 && cg-branch-add origin ../branch2)"
65 echo appended
>>branch
2/foo
68 test_expect_success
'local change on branch1 (should not block)' \
69 "(cd branch1 && echo boo >x && cg-add x)"
70 cp branch
1/x branch
1/x-
71 test_expect_success
'merging branch2 to branch1 (fast-forward)' \
72 "(cd branch1 && cg-merge </dev/null)"
73 test_expect_success
'checking if we still have our local change' \
74 '(cd branch1 && cg-status -w | grep -q "^A x" && cmp x x-)'
77 test_expect_success
'local commit in branch1' \
78 "(cd branch1 && cg-commit -m\"Branch1 commit\")"
81 echo appended
>>branch
2/foo
84 test_add_block
"clean"
86 test_expect_success
'local change on branch1 (modify in same, should block)' \
87 "(cd branch1 && echo appended-too >>foo)"
88 cp branch
1/foo branch
1/foo-
89 test_expect_failure
'merging branch2 to branch1 (clean)' \
90 "(cd branch1 && cg-merge </dev/null)"
91 test_expect_success
'checking if we still have our local change' \
92 '(cd branch1 && cg-status -w | grep -q "^M foo" && cmp foo foo-)'
93 # This test is useful if the previous one failed - did it get lost or
94 # accidentally committed?
95 test_expect_success
'checking that we didn'\''t commit the local change' \
96 '(cd branch1 && cg-admin-cat foo >foo-tree && ! cmp foo- foo-tree)'
97 test_expect_success
'undoing the local change' \
98 '(cd branch1 && cg-restore -f foo)'
99 test_expect_success
'confirming that we have no uncommitted modifications' \
100 '(cd branch1 && [ -z "$(git-diff-index -r $(cg-object-id -t))" ])'
102 test_expect_success
'local change on branch1 (modify in different, should not block)' \
103 "(cd branch1 && echo moo >bar)"
104 cp branch
1/bar branch
1/bar-
105 test_expect_success
'merging branch2 to branch1 (clean)' \
106 "(cd branch1 && cg-merge </dev/null)"
107 test_expect_success
'checking if we still have our local change' \
108 '(cd branch1 && cg-status -w | grep -q "^M bar" && cmp bar bar-)'
109 # This test is useful if the previous one failed - did it get lost or
110 # accidentally committed?
111 test_expect_success
'checking that we didn'\''t commit the local change' \
112 '(cd branch1 && cg-admin-cat bar >bar-tree && ! cmp bar- bar-tree)'
115 mv branch
1/brm branch
1/brm-old
116 echo prepended
>branch
1/brm
117 cat branch
1/brm-old
>>branch
1/brm
119 test_expect_success
'local commit in branch1' \
120 "(cd branch1 && cg-commit -m\"Branch1 commit\")"
123 echo appended2
>>branch
2/brm
126 test_add_block
"automatic"
128 test_expect_success
'local change on branch1 (modify in different, should not block)' \
129 "(cd branch1 && echo poo >bar)"
130 cp branch
1/bar branch
1/bar-
131 cp branch
1/brm branch
1/brm-
132 test_expect_success
'merging branch2 to branch1 (automatic)' \
133 "(cd branch1 && cg-merge </dev/null)"
134 test_expect_success
'checking if the working copy was touched by the merge' \
135 '(cd branch1 && ! cmp brm brm-)'
136 test_expect_success
'checking if we still have our local change' \
137 '(cd branch1 && cg-status -w | grep -q "^M bar" && cmp bar bar-)'
138 # This test is useful if the previous one failed - did it get lost or
139 # accidentally committed?
140 test_expect_success
'checking that we didn'\''t commit the local change' \
141 '(cd branch1 && cg-admin-cat bar >bar-tree && ! cmp bar- bar-tree)'
144 echo conflicting
>>branch
1/brm
145 test_expect_success
'local commit in branch1' \
146 "(cd branch1 && cg-commit -m\"Branch1 commit\")"
149 # Theoretically the following commit should be superfluous, but we would get
150 # false successful merge if the previous test failed and merge succeeded.
152 echo appended3
>>branch
2/brm
155 test_add_block
"conflicting"
157 test_expect_success
'local change on branch1 (modify in different, should not block)' \
158 "(cd branch1 && echo zoo >bar)"
159 cp branch
1/bar branch
1/bar-
160 cp branch
1/brm branch
1/brm-
161 test_expect_failure
'merging branch2 to branch1 (conflicting)' \
162 "(cd branch1 && cg-merge </dev/null)"
163 test_expect_success
'checking if the merge caused a conflict' \
164 '(cd branch1 && grep "<<<" brm)'
165 # <now imagine me resolving the conflict>
166 test_expect_success
'checking if we still have our local change' \
167 '(cd branch1 && cg-status -w | grep -q "^m bar" && cmp bar bar-)'
168 test_expect_success
'committing "resolved" conflicting merge' \
169 '(cd branch1 && cg-commit -m"Resolved conflicting merge")'
170 test_expect_success
'checking if we still have our local change' \
171 '(cd branch1 && cg-status -w | grep -q "^M bar" && cmp bar bar-)'
172 # This test is useful if the previous one failed - did it get lost or
173 # accidentally committed?
174 test_expect_success
'checking that we didn'\''t commit the local change' \
175 '(cd branch1 && cg-admin-cat bar >bar-tree && ! cmp bar- bar-tree)'