@@ -35,6 +35,8 @@ def test_repo_features(self):
35
35
self .assertEqual (set (branch_names ), set (['master' , 'title' , 'body' ]))
36
36
37
37
def test_start_branch (self ):
38
+ ''' Make a simple edit in a clone, verify that it appears in the other.
39
+ '''
38
40
name = str (uuid4 ())
39
41
branch1 = bizarro .repo .start_branch (self .clone1 , 'master' , name )
40
42
@@ -62,6 +64,8 @@ def test_start_branch(self):
62
64
self .assertEquals (branch2 .commit .message , message )
63
65
64
66
def test_new_file (self ):
67
+ ''' Make a new file in a clone, verify that it appears in the other.
68
+ '''
65
69
name = str (uuid4 ())
66
70
branch1 = bizarro .repo .start_branch (self .clone1 , 'master' , name )
67
71
@@ -98,6 +102,91 @@ def test_new_file(self):
98
102
self .assertEquals (front ['title' ], 'Hello' )
99
103
self .assertEquals (body , 'Hello hello.' )
100
104
105
+ def test_simple_merge (self ):
106
+ ''' Test that two simultaneous non-conflicting changes merge cleanly.
107
+ '''
108
+ name = str (uuid4 ())
109
+ branch1 = bizarro .repo .start_branch (self .clone1 , 'master' , name )
110
+ branch2 = bizarro .repo .start_branch (self .clone2 , 'master' , name )
111
+
112
+ #
113
+ # Make a new files in each branch and save them.
114
+ #
115
+ branch1 .checkout ()
116
+ branch2 .checkout ()
117
+
118
+ repo_path1 , real_path1 = bizarro .repo .make_working_file (self .clone1 , '' , 'file1.md' )
119
+ repo_path2 , real_path2 = bizarro .repo .make_working_file (self .clone2 , '' , 'file2.md' )
120
+
121
+ with open (real_path1 , 'w' ) as file :
122
+ jekyll .dump_jekyll_doc (dict (title = 'Hello' ), 'Hello hello.' , file )
123
+
124
+ with open (real_path2 , 'w' ) as file :
125
+ jekyll .dump_jekyll_doc (dict (title = 'Goodbye' ), 'Goodbye goodbye.' , file )
126
+
127
+ #
128
+ # Show that the changes from the first branch made it to origin.
129
+ #
130
+ args1 = self .clone1 , 'file1.md' , 'Saving' , branch1 .commit .hexsha
131
+ commit1 = bizarro .repo .save_working_file (* args1 )
132
+
133
+ self .assertEquals (self .origin .branches [name ].commit , commit1 )
134
+ self .assertEquals (commit1 , branch1 .commit )
135
+
136
+ #
137
+ # Show that the changes from the second branch also made it to origin.
138
+ #
139
+ args2 = self .clone2 , 'file2.md' , 'Saving' , branch2 .commit .hexsha
140
+ commit2 = bizarro .repo .save_working_file (* args2 )
141
+
142
+ self .assertEquals (self .origin .branches [name ].commit , commit2 )
143
+ self .assertEquals (commit2 , branch2 .commit )
144
+
145
+ #
146
+ # Show that the merge from the second branch made it back to the first.
147
+ #
148
+ branch1b = bizarro .repo .start_branch (self .clone1 , 'master' , name )
149
+
150
+ self .assertEquals (branch1b .commit , branch2 .commit )
151
+
152
+ def test_simple_conflict (self ):
153
+ ''' Test that a conflict in two branches appears at the right spot.
154
+ '''
155
+ name = str (uuid4 ())
156
+ branch1 = bizarro .repo .start_branch (self .clone1 , 'master' , name )
157
+ branch2 = bizarro .repo .start_branch (self .clone2 , 'master' , name )
158
+
159
+ #
160
+ # Make a new files in each branch and save them.
161
+ #
162
+ branch1 .checkout ()
163
+ branch2 .checkout ()
164
+
165
+ repo_path1 , real_path1 = bizarro .repo .make_working_file (self .clone1 , '' , 'conflict.md' )
166
+ repo_path2 , real_path2 = bizarro .repo .make_working_file (self .clone2 , '' , 'conflict.md' )
167
+
168
+ with open (real_path1 , 'w' ) as file :
169
+ jekyll .dump_jekyll_doc (dict (title = 'Hello' ), 'Hello hello.' , file )
170
+
171
+ with open (real_path2 , 'w' ) as file :
172
+ jekyll .dump_jekyll_doc (dict (title = 'Goodbye' ), 'Goodbye goodbye.' , file )
173
+
174
+ #
175
+ # Show that the changes from the first branch made it to origin.
176
+ #
177
+ args1 = self .clone1 , 'conflict.md' , 'Saving' , branch1 .commit .hexsha
178
+ commit1 = bizarro .repo .save_working_file (* args1 )
179
+
180
+ self .assertEquals (self .origin .branches [name ].commit , commit1 )
181
+ self .assertEquals (commit1 , branch1 .commit )
182
+
183
+ #
184
+ # Show that the changes from the second branch conflict with the first.
185
+ #
186
+ with self .assertRaises (bizarro .repo .MergeConflict ):
187
+ args2 = self .clone2 , 'conflict.md' , 'Saving' , branch2 .commit .hexsha
188
+ commit2 = bizarro .repo .save_working_file (* args2 )
189
+
101
190
def tearDown (self ):
102
191
rmtree (self .origin .git_dir )
103
192
rmtree (self .clone1 .working_dir )
0 commit comments