Test commit
[cogito/jonas.git] / t / t9200-merge.sh
blobeb9ef10ab430161fa80e86aa766f3ac61371d3b2
1 #!/usr/bin/env bash
3 # Copyright (c) 2005 Petr Baudis
5 test_description="Tests basic cg-merge functionality
7 Generates two simple branches, and tests fast-forward cg-merge, clean cg-merge,
8 cg-merge doing automatic merge, cg-merge with conflicts and baseless cg-merge."
10 . ./test-lib.sh
12 # branch1 -> branch2
14 mkdir branch1
15 # The blank space is to prevent conflicts for automatic merges.
16 cat >branch1/brm <<__END__
17 blah
28 boo
29 __END__
31 >branch1/foo
32 >branch1/bar
33 >branch1/baz
35 test_expect_success 'initialize branch1' \
36 "(cd branch1 && cg-init -I && cg-add brm foo bar baz && cg-commit -C -m\"Initial commit\")"
37 test_expect_success 'fork branch2' \
38 "cg-clone branch1 branch2"
39 test_expect_success 'registering branch2 in branch1' \
40 "(cd branch1 && cg-branch-add origin ../branch2)"
42 echo appended >>branch2/foo
43 echo newinbranch2forfastforward >branch2/quux
44 test_expect_success 'adding/removing files in branch2' \
45 "(cd branch2 && cg-rm -f baz && cg-add quux)"
46 test_expect_success 'local commit in branch2' \
47 "(cd branch2 && cg-commit -m\"To-be-fastforwarded commit\")"
48 test_expect_success 'fetching from branch2 to branch1' \
49 "(cd branch1 && cg-fetch)"
50 test_expect_success 'merging branch2 to branch1 (fast-forward)' \
51 "(cd branch1 && cg-merge </dev/null)"
52 test_expect_success 'checking for correct merged content' \
53 "(cmp branch2/foo branch1/foo)"
54 test_expect_success 'checking for properly removed file' \
55 "(cd branch1 && [ ! -e baz ])"
56 test_expect_success 'checking for properly added file' \
57 "(cd branch1 && [ -e quux ] && git-ls-files | fgrep -x quux)"
58 test_expect_success 'checking if it was really a fast-forward' \
59 "(cmp branch1/.git/refs/heads/origin branch1/.git/refs/heads/master)"
61 echo justsomedummystuff >>branch1/bar
62 test_expect_success 'local commit in branch1' \
63 "(cd branch1 && cg-commit -m\"Second commit 1\")"
64 echo appended >>branch2/brm
65 test_expect_success 'local commit in branch2' \
66 "(cd branch2 && cg-commit -m\"Second commit 2\")"
67 test_expect_success 'fetching from branch2 to branch1' \
68 "(cd branch1 && cg-fetch)"
69 test_expect_success 'merging branch2 to branch1 (clean)' \
70 "(cd branch1 && cg-merge </dev/null)"
71 test_expect_success 'checking for correct merged content' \
72 "(cmp branch2/brm branch1/brm)"
76 mv branch1/brm branch1/brm-old
77 echo prepended >branch1/brm
78 cat branch1/brm-old >>branch1/brm
79 rm branch1/brm-old
80 test_expect_success 'local commit in branch1' \
81 "(cd branch1 && cg-commit -m\"Another commit 1\")"
83 echo appended2 >>branch2/brm
84 test_expect_success 'local commit in branch2' \
85 "(cd branch2 && cg-commit -m\"Another commit 2\")"
87 test_expect_success 'fetching from branch2 to branch1' \
88 "(cd branch1 && cg-fetch)"
89 test_expect_success 'merging branch2 to branch1 (automatic)' \
90 "(cd branch1 && cg-merge </dev/null)"
91 cat >expect <<__END__
92 prepended
93 blah
105 appended
106 appended2
107 __END__
108 test_expect_success 'checking for correct merged content' \
109 "(cmp branch1/brm expect)"
113 echo append conflict1 >>branch1/brm
114 test_expect_success 'local commit in branch1' \
115 "(cd branch1 && cg-commit -m\"Yet another commit 1\")"
116 echo append conflict2 >>branch2/brm
117 echo append stuff >>branch2/foo
118 test_expect_success 'local commit in branch2' \
119 "(cd branch2 && cg-commit -m\"Yet another commit 2\")"
121 test_expect_success 'fetching from branch2 to branch1' \
122 "(cd branch1 && cg-fetch)"
123 test_expect_failure 'merging branch2 to branch1 (conflicting)' \
124 "(cd branch1 && cg-merge </dev/null)"
125 cat >expect <<__END__
126 prepended
127 blah
139 appended
140 appended2
141 <<<<<<< master
142 append conflict1
143 =======
144 append conflict2
145 >>>>>>> origin
146 __END__
147 sed 's/merge_file.*$/merge_file/' <branch1/brm >brm-cleaned-up
148 test_expect_success 'checking for correct conflict content' \
149 "(cmp brm-cleaned-up expect)"
150 test_expect_success 'checking for correct automerge result in the conflicting tree' \
151 "(cmp branch2/foo branch1/foo)"
155 # And now for something totally different...
156 mkdir branch3
157 echo branch3file >branch3/b3
158 cp branch3/b3 branch3/b3-
159 test_expect_success 'initialize branch3' \
160 "(cd branch3 && cg-init -I && cg-add b3 && cg-commit -C -m\"Initial commit\")"
161 mkdir branch4
162 echo branch4file >branch4/b4
163 test_expect_success 'initialize branch4' \
164 "(cd branch4 && cg-init -I && cg-add b4 && cg-commit -C -m\"Initial commit\")"
165 test_expect_success 'fetching branch4 from branch3' \
166 "(cd branch3 && cg-branch-add origin ../branch4 && cg-fetch)"
167 test_expect_failure 'baseless merge of branch3 and branch4' \
168 "(cd branch3 && cg-merge)"
169 test_expect_success 'baseless joining merge of branch3 and branch4' \
170 "(cd branch3 && cg-merge -j </dev/null)"
171 test_expect_success 'verifying merge' \
172 "(cd branch3 && cmp b3 b3- && cmp b4 ../branch4/b4)"
175 test_done