Test commit
[cogito/jonas.git] / t / t9204-merge-weird-conflicts.sh
blobd3626384d19d3e086f42085c72626a15c6b22fa3
1 #!/usr/bin/env bash
3 # Copyright (c) 2005 Petr Baudis
5 test_description="Tests cg-merge 'dealing' with non-trivial conflicts
7 Generates two simple branches, and tests how cg-merge responds to various
8 conflicting situations. Basically, if it generated conflict every time
9 it should do so."
11 . ./test-lib.sh
13 # branch1 -> branch2
15 mkdir branch1
16 echo "file1" >branch1/file1
18 test_expect_success 'initialize branch1' \
19 "(cd branch1 && cg-init -I && cg-add file1 && cg-commit -C -m\"Initial commit\")"
20 test_expect_success 'fork branch2' \
21 "cg-clone branch1 branch2"
22 test_expect_success 'registering branch2 in branch1' \
23 "(cd branch1 && cg-branch-add origin ../branch2)"
26 echo "file1 branch1" >branch1/file1
27 echo "file1 branch1" >branch1/file1-
28 test_expect_success 'content change in branch1' \
29 "(cd branch1 && cg-commit -m\"Content change\")"
30 chmod a+x branch2/file1
31 test_expect_success 'mode change in branch2' \
32 "(cd branch2 && cg-commit -m\"Mode change\")"
33 test_expect_success 'fetching from branch2 to branch1' \
34 "(cd branch1 && cg-fetch)"
35 test_expect_failure 'merging branch2 to branch1 (should conflict)' \
36 "(cd branch1 && cg-merge </dev/null)"
37 test_expect_success 'checking for defaulting to +x' \
38 "([ -x branch1/file1 ])"
39 test_expect_success 'checking for properly merged content' \
40 "(cmp branch1/file1 branch1/file1-)"
43 echo "new file2" >branch1/file2
44 test_expect_success 'identical file added in branch1' \
45 "(cd branch1 && cg-add file2 && cg-commit -m\"Identical file add\")"
46 echo "new file2" >branch2/file2
47 test_expect_success 'identical file added in branch2' \
48 "(cd branch2 && cg-add file2 && cg-commit -m\"Identical file add\")"
50 test_expect_success 'fetching from branch2 to branch1' \
51 "(cd branch1 && cg-fetch)"
52 test_expect_success 'merging branch2 to branch1 (should success)' \
53 "(cd branch1 && cg-merge </dev/null)"
54 test_expect_success 'checking for the proper file being added' \
55 "(cmp branch1/file2 branch2/file2)"
58 echo "new file3" >branch1/file3
59 test_expect_success 'identical file added in branch1' \
60 "(cd branch1 && cg-add file3 && cg-commit -m\"Identical file add\")"
61 echo "new file3" >branch2/file3
62 chmod a+x branch2/file3
63 test_expect_success 'identical file added in branch2, but with +x' \
64 "(cd branch2 && cg-add file3 && cg-commit -m\"+x file add\")"
66 test_expect_success 'fetching from branch2 to branch1' \
67 "(cd branch1 && cg-fetch)"
68 test_expect_failure 'merging branch2 to branch1 (should conflict)' \
69 "(cd branch1 && cg-merge </dev/null)"
70 test_expect_success 'checking for the proper file being added...' \
71 "(cmp branch1/file3 branch2/file3)"
72 test_expect_success '...defaulting to +x' \
73 "([ -x branch1/file3 ])"
76 echo "new file4 branch1" >branch1/file4
77 echo "new file4 branch1" >branch1/file4-
78 test_expect_success 'different file added in branch1' \
79 "(cd branch1 && cg-add file4 && cg-commit -m\"Different file add\")"
80 echo "new file4 branch2" >branch2/file4
81 chmod a+x branch2/file4
82 test_expect_success 'different file added in branch2' \
83 "(cd branch2 && cg-add file4 && cg-commit -m\"Different file add\")"
85 test_expect_success 'fetching from branch2 to branch1' \
86 "(cd branch1 && cg-fetch)"
87 test_expect_failure 'merging branch2 to branch1 (should conflict)' \
88 "(cd branch1 && cg-merge </dev/null)"
89 test_expect_success 'checking for the proper conflict being generated for branch1' \
90 "(cmp branch1/file4~master branch1/file4-)"
91 test_expect_success 'checking for the proper conflict being generated for branch2' \
92 "(cmp branch1/file4~origin branch2/file4 && [ -x branch2/file4 ])"
93 test_expect_success 'checking for the proper conflict being generated (no file4)' \
94 "([ ! -e branch1/file4 ])"
97 test_expect_success 'resolving the last conflict' \
98 "(cd branch1 && mv file4~master file4 && cg-commit -m\"Resolved\")"
99 test_expect_success 'removing branch1/file4' \
100 "(cd branch1 && cg-rm -f file4 && cg-commit -m\"Killed file4\")"
101 test_expect_success 'removing branch2/file4' \
102 "(cd branch2 && cg-rm -f file4 && cg-commit -m\"Killed file4\")"
104 test_expect_success 'fetching from branch2 to branch1' \
105 "(cd branch1 && cg-fetch)"
106 test_expect_success 'merging branch2 to branch1 (should not conflict)' \
107 "(cd branch1 && cg-merge </dev/null)"
108 test_expect_success 'checking for the proper conflict resolution (file4 gone)' \
109 "([ ! -e branch1/file4 ])"
112 test_expect_success 'removing branch1/file3' \
113 "(cd branch1 && cp file3 file3- && cg-rm -f file3 && cg-commit -m\"Killed file3\")"
114 test_expect_success 'modifying branch2/file3' \
115 "(cd branch2 && echo modificaton >>file3 && chmod a+x file3 && cg-commit -m\"Modified file3\")"
117 test_expect_success 'fetching from branch2 to branch1' \
118 "(cd branch1 && cg-fetch)"
119 test_expect_failure 'merging branch2 to branch1 (should conflict)' \
120 "(cd branch1 && cg-merge </dev/null)"
121 test_expect_success 'checking for the proper conflict being generated for branch2' \
122 "(cmp branch1/file3~origin branch2/file3 && [ -x branch2/file3 ])"
123 test_expect_success 'checking for the proper conflict being generated (no file3)' \
124 "([ ! -e branch1/file3 ] && cmp branch1/file3- branch1/file3~merge~base)"
125 test_expect_success 'resolving the file3 conflict' \
126 "(cd branch1 && cg-rm file3 && cg-commit -m\"Resolved file3 (removed)\")"
129 test_expect_success 'removing branch1/file2' \
130 "(cd branch1 && cg-rm -f file2 && cg-commit -m\"Killed file2\")"
131 test_expect_success 'adding branch2/file5' \
132 "(cd branch2 && echo file5b2 >file5 && cg-add file5 && cg-commit -m\"Added file5\")"
134 test_expect_success 'fetching from branch2 to branch1' \
135 "(cd branch1 && cg-fetch)"
136 test_expect_success 'merging branch2 to branch1 (should not conflict)' \
137 "(cd branch1 && cg-merge </dev/null)"
138 test_expect_success 'checking if file2 is still gone and file5 is there' \
139 "([ ! -e branch1/file2 ] && [ -e branch1/file5 ])"
142 test_expect_success 'removing branch2/file5' \
143 "(cd branch2 && cg-rm -f file5 && cg-commit -m\"Killed file5\")"
145 test_expect_success 'fetching from branch2 to branch1' \
146 "(cd branch1 && cg-fetch)"
147 test_expect_success 'merging branch2 to branch1 (should not conflict)' \
148 "(cd branch1 && cg-merge </dev/null)"
149 test_expect_success 'checking if file5 is gone' \
150 "([ ! -e branch1/file5 ])"
151 test_expect_success 'checking if everything is committed properly' \
152 "([ ! \"\$(cg-status -w | grep -v ^\?)\" ])"
154 test_done