Show More
@@ -1,346 +1,347 b'' | |||
|
1 | 1 | from rhodecode.tests import * |
|
2 | 2 | from rhodecode.model.repo import RepoModel |
|
3 | 3 | from rhodecode.model.meta import Session |
|
4 | 4 | from rhodecode.model.db import Repository |
|
5 | 5 | from rhodecode.model.scm import ScmModel |
|
6 | 6 | from rhodecode.lib.vcs.backends.base import EmptyChangeset |
|
7 | 7 | |
|
8 | 8 | |
|
9 | 9 | def _fork_repo(fork_name, vcs_type, parent=None): |
|
10 | 10 | if vcs_type =='hg': |
|
11 | 11 | _REPO = HG_REPO |
|
12 | 12 | elif vcs_type == 'git': |
|
13 | 13 | _REPO = GIT_REPO |
|
14 | 14 | |
|
15 | 15 | if parent: |
|
16 | 16 | _REPO = parent |
|
17 | 17 | |
|
18 | 18 | form_data = dict( |
|
19 | 19 | repo_name=fork_name, |
|
20 | 20 | repo_name_full=fork_name, |
|
21 | 21 | repo_group=None, |
|
22 | 22 | repo_type=vcs_type, |
|
23 | 23 | description='', |
|
24 | 24 | private=False, |
|
25 | 25 | copy_permissions=False, |
|
26 | 26 | landing_rev='tip', |
|
27 | 27 | update_after_clone=False, |
|
28 | 28 | fork_parent_id=Repository.get_by_repo_name(_REPO), |
|
29 | 29 | ) |
|
30 | 30 | repo = RepoModel().create_fork(form_data, cur_user=TEST_USER_ADMIN_LOGIN) |
|
31 | 31 | |
|
32 | 32 | Session().commit() |
|
33 | 33 | return Repository.get_by_repo_name(fork_name) |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | def _commit_change(repo, filename, content, message, vcs_type, parent=None, newfile=False): |
|
37 | 37 | repo = Repository.get_by_repo_name(repo) |
|
38 | 38 | _cs = parent |
|
39 | 39 | if not parent: |
|
40 | 40 | _cs = EmptyChangeset(alias=vcs_type) |
|
41 | 41 | |
|
42 | 42 | if newfile: |
|
43 | 43 | cs = ScmModel().create_node( |
|
44 | 44 | repo=repo.scm_instance, repo_name=repo.repo_name, |
|
45 | 45 | cs=_cs, user=TEST_USER_ADMIN_LOGIN, |
|
46 | 46 | author=TEST_USER_ADMIN_LOGIN, |
|
47 | 47 | message=message, |
|
48 | 48 | content=content, |
|
49 | 49 | f_path=filename |
|
50 | 50 | ) |
|
51 | 51 | else: |
|
52 | 52 | cs = ScmModel().commit_change( |
|
53 | 53 | repo=repo.scm_instance, repo_name=repo.repo_name, |
|
54 | 54 | cs=parent, user=TEST_USER_ADMIN_LOGIN, |
|
55 | 55 | author=TEST_USER_ADMIN_LOGIN, |
|
56 | 56 | message=message, |
|
57 | 57 | content=content, |
|
58 | 58 | f_path=filename |
|
59 | 59 | ) |
|
60 | 60 | return cs |
|
61 | 61 | |
|
62 | 62 | |
|
63 | 63 | class TestCompareController(TestController): |
|
64 | 64 | |
|
65 | 65 | def test_compare_forks_on_branch_extra_commits_hg(self): |
|
66 | 66 | self.log_user() |
|
67 | 67 | |
|
68 | 68 | repo1 = RepoModel().create_repo(repo_name='one', repo_type='hg', |
|
69 | 69 | description='diff-test', |
|
70 | 70 | owner=TEST_USER_ADMIN_LOGIN) |
|
71 | 71 | r1_id = repo1.repo_id |
|
72 | 72 | Session().commit() |
|
73 | 73 | #commit something ! |
|
74 | 74 | cs0 = _commit_change(repo1.repo_name, filename='file1', content='line1\n', |
|
75 | 75 | message='commit1', vcs_type='hg', parent=None, newfile=True) |
|
76 | 76 | |
|
77 | 77 | #fork this repo |
|
78 | 78 | repo2 = _fork_repo('one-fork', 'hg', parent='one') |
|
79 | 79 | Session().commit() |
|
80 | 80 | r2_id = repo2.repo_id |
|
81 | 81 | |
|
82 | 82 | #add two extra commit into fork |
|
83 | 83 | cs1 = _commit_change(repo2.repo_name, filename='file1', content='line1\nline2\n', |
|
84 | 84 | message='commit2', vcs_type='hg', parent=cs0) |
|
85 | 85 | |
|
86 | 86 | cs2 = _commit_change(repo2.repo_name, filename='file1', content='line1\nline2\nline3\n', |
|
87 | 87 | message='commit3', vcs_type='hg', parent=cs1) |
|
88 | 88 | |
|
89 | 89 | rev1 = 'default' |
|
90 | 90 | rev2 = 'default' |
|
91 | 91 | response = self.app.get(url(controller='compare', action='index', |
|
92 | 92 | repo_name=repo2.repo_name, |
|
93 | 93 | org_ref_type="branch", |
|
94 | 94 | org_ref=rev1, |
|
95 | 95 | other_ref_type="branch", |
|
96 | 96 | other_ref=rev2, |
|
97 | 97 | repo=repo1.repo_name |
|
98 | 98 | )) |
|
99 | 99 | |
|
100 | 100 | try: |
|
101 | 101 | response.mustcontain('%s@%s -> %s@%s' % (repo2.repo_name, rev1, repo1.repo_name, rev2)) |
|
102 | 102 | response.mustcontain("""Showing 2 commits""") |
|
103 | 103 | response.mustcontain("""1 file changed with 2 insertions and 0 deletions""") |
|
104 | 104 | |
|
105 | 105 | response.mustcontain("""<div class="message tooltip" title="commit2" style="white-space:normal">commit2</div>""") |
|
106 | 106 | response.mustcontain("""<div class="message tooltip" title="commit3" style="white-space:normal">commit3</div>""") |
|
107 | 107 | |
|
108 | 108 | response.mustcontain("""<a href="/%s/changeset/%s">r1:%s</a>""" % (repo2.repo_name, cs1.raw_id, cs1.short_id)) |
|
109 | 109 | response.mustcontain("""<a href="/%s/changeset/%s">r2:%s</a>""" % (repo2.repo_name, cs2.raw_id, cs2.short_id)) |
|
110 | 110 | ## files |
|
111 | 111 | response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s#C--826e8142e6ba">file1</a>""" % (repo2.repo_name, rev1, rev2)) |
|
112 | 112 | |
|
113 | 113 | finally: |
|
114 | RepoModel().delete(r2_id) | |
|
114 | 115 | RepoModel().delete(r1_id) |
|
115 | RepoModel().delete(r2_id) | |
|
116 | ||
|
116 | 117 | |
|
117 | 118 | def test_compare_forks_on_branch_extra_commits_origin_has_incomming_hg(self): |
|
118 | 119 | self.log_user() |
|
119 | 120 | |
|
120 | 121 | repo1 = RepoModel().create_repo(repo_name='one', repo_type='hg', |
|
121 | 122 | description='diff-test', |
|
122 | 123 | owner=TEST_USER_ADMIN_LOGIN) |
|
123 | 124 | r1_id = repo1.repo_id |
|
124 | 125 | Session().commit() |
|
125 | 126 | #commit something ! |
|
126 | 127 | cs0 = _commit_change(repo1.repo_name, filename='file1', content='line1\n', |
|
127 | 128 | message='commit1', vcs_type='hg', parent=None, newfile=True) |
|
128 | 129 | |
|
129 | 130 | #fork this repo |
|
130 | 131 | repo2 = _fork_repo('one-fork', 'hg', parent='one') |
|
131 | 132 | Session().commit() |
|
132 | 133 | |
|
133 | 134 | #now commit something to origin repo |
|
134 | 135 | cs1_prim = _commit_change(repo1.repo_name, filename='file2', content='line1file2\n', |
|
135 | 136 | message='commit2', vcs_type='hg', parent=cs0, newfile=True) |
|
136 | 137 | |
|
137 | 138 | r2_id = repo2.repo_id |
|
138 | 139 | |
|
139 | 140 | #add two extra commit into fork |
|
140 | 141 | cs1 = _commit_change(repo2.repo_name, filename='file1', content='line1\nline2\n', |
|
141 | 142 | message='commit2', vcs_type='hg', parent=cs0) |
|
142 | 143 | |
|
143 | 144 | cs2 = _commit_change(repo2.repo_name, filename='file1', content='line1\nline2\nline3\n', |
|
144 | 145 | message='commit3', vcs_type='hg', parent=cs1) |
|
145 | 146 | |
|
146 | 147 | rev1 = 'default' |
|
147 | 148 | rev2 = 'default' |
|
148 | 149 | response = self.app.get(url(controller='compare', action='index', |
|
149 | 150 | repo_name=repo2.repo_name, |
|
150 | 151 | org_ref_type="branch", |
|
151 | 152 | org_ref=rev1, |
|
152 | 153 | other_ref_type="branch", |
|
153 | 154 | other_ref=rev2, |
|
154 | 155 | repo=repo1.repo_name |
|
155 | 156 | )) |
|
156 | 157 | |
|
157 | 158 | try: |
|
158 | 159 | response.mustcontain('%s@%s -> %s@%s' % (repo2.repo_name, rev1, repo1.repo_name, rev2)) |
|
159 | 160 | response.mustcontain("""Showing 2 commits""") |
|
160 | 161 | response.mustcontain("""1 file changed with 2 insertions and 0 deletions""") |
|
161 | 162 | |
|
162 | 163 | response.mustcontain("""<div class="message tooltip" title="commit2" style="white-space:normal">commit2</div>""") |
|
163 | 164 | response.mustcontain("""<div class="message tooltip" title="commit3" style="white-space:normal">commit3</div>""") |
|
164 | 165 | |
|
165 | 166 | response.mustcontain("""<a href="/%s/changeset/%s">r1:%s</a>""" % (repo2.repo_name, cs1.raw_id, cs1.short_id)) |
|
166 | 167 | response.mustcontain("""<a href="/%s/changeset/%s">r2:%s</a>""" % (repo2.repo_name, cs2.raw_id, cs2.short_id)) |
|
167 | 168 | ## files |
|
168 | 169 | response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s#C--826e8142e6ba">file1</a>""" % (repo2.repo_name, rev1, rev2)) |
|
169 | 170 | |
|
170 | 171 | finally: |
|
172 | RepoModel().delete(r2_id) | |
|
171 | 173 | RepoModel().delete(r1_id) |
|
172 | RepoModel().delete(r2_id) | |
|
173 | 174 | |
|
174 | 175 | |
|
175 | 176 | # def test_compare_remote_repos_remote_flag_off(self): |
|
176 | 177 | # self.log_user() |
|
177 | 178 | # _fork_repo(HG_FORK, 'hg') |
|
178 | 179 | # |
|
179 | 180 | # rev1 = '56349e29c2af' |
|
180 | 181 | # rev2 = '7d4bc8ec6be5' |
|
181 | 182 | # |
|
182 | 183 | # response = self.app.get(url(controller='compare', action='index', |
|
183 | 184 | # repo_name=HG_REPO, |
|
184 | 185 | # org_ref_type="rev", |
|
185 | 186 | # org_ref=rev1, |
|
186 | 187 | # other_ref_type="rev", |
|
187 | 188 | # other_ref=rev2, |
|
188 | 189 | # repo=HG_FORK, |
|
189 | 190 | # bundle=False, |
|
190 | 191 | # )) |
|
191 | 192 | # |
|
192 | 193 | # try: |
|
193 | 194 | # response.mustcontain('%s@%s -> %s@%s' % (HG_REPO, rev1, HG_FORK, rev2)) |
|
194 | 195 | # ## outgoing changesets between those revisions |
|
195 | 196 | # |
|
196 | 197 | # response.mustcontain("""<a href="/%s/changeset/2dda4e345facb0ccff1a191052dd1606dba6781d">r4:2dda4e345fac</a>""" % (HG_REPO)) |
|
197 | 198 | # response.mustcontain("""<a href="/%s/changeset/6fff84722075f1607a30f436523403845f84cd9e">r5:6fff84722075</a>""" % (HG_REPO)) |
|
198 | 199 | # response.mustcontain("""<a href="/%s/changeset/7d4bc8ec6be56c0f10425afb40b6fc315a4c25e7">r6:%s</a>""" % (HG_REPO, rev2)) |
|
199 | 200 | # |
|
200 | 201 | # ## files |
|
201 | 202 | # response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s#C--9c390eb52cd6">vcs/backends/hg.py</a>""" % (HG_REPO, rev1, rev2)) |
|
202 | 203 | # response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s#C--41b41c1f2796">vcs/backends/__init__.py</a>""" % (HG_REPO, rev1, rev2)) |
|
203 | 204 | # response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s#C--2f574d260608">vcs/backends/base.py</a>""" % (HG_REPO, rev1, rev2)) |
|
204 | 205 | # finally: |
|
205 | 206 | # RepoModel().delete(HG_FORK) |
|
206 | 207 | |
|
207 | 208 | |
|
208 | 209 | |
|
209 | 210 | # |
|
210 | 211 | # def test_compare_remote_branches_hg(self): |
|
211 | 212 | # self.log_user() |
|
212 | 213 | # |
|
213 | 214 | # _fork_repo(HG_FORK, 'hg') |
|
214 | 215 | # |
|
215 | 216 | # rev1 = '56349e29c2af' |
|
216 | 217 | # rev2 = '7d4bc8ec6be5' |
|
217 | 218 | # |
|
218 | 219 | # response = self.app.get(url(controller='compare', action='index', |
|
219 | 220 | # repo_name=HG_REPO, |
|
220 | 221 | # org_ref_type="rev", |
|
221 | 222 | # org_ref=rev1, |
|
222 | 223 | # other_ref_type="rev", |
|
223 | 224 | # other_ref=rev2, |
|
224 | 225 | # repo=HG_FORK, |
|
225 | 226 | # )) |
|
226 | 227 | # |
|
227 | 228 | # try: |
|
228 | 229 | # response.mustcontain('%s@%s -> %s@%s' % (HG_REPO, rev1, HG_FORK, rev2)) |
|
229 | 230 | # ## outgoing changesets between those revisions |
|
230 | 231 | # |
|
231 | 232 | # response.mustcontain("""<a href="/%s/changeset/2dda4e345facb0ccff1a191052dd1606dba6781d">r4:2dda4e345fac</a>""" % (HG_REPO)) |
|
232 | 233 | # response.mustcontain("""<a href="/%s/changeset/6fff84722075f1607a30f436523403845f84cd9e">r5:6fff84722075</a>""" % (HG_REPO)) |
|
233 | 234 | # response.mustcontain("""<a href="/%s/changeset/7d4bc8ec6be56c0f10425afb40b6fc315a4c25e7">r6:%s</a>""" % (HG_REPO, rev2)) |
|
234 | 235 | # |
|
235 | 236 | # ## files |
|
236 | 237 | # response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s#C--9c390eb52cd6">vcs/backends/hg.py</a>""" % (HG_REPO, rev1, rev2)) |
|
237 | 238 | # response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s#C--41b41c1f2796">vcs/backends/__init__.py</a>""" % (HG_REPO, rev1, rev2)) |
|
238 | 239 | # response.mustcontain("""<a href="/%s/compare/rev@%s...rev@%s#C--2f574d260608">vcs/backends/base.py</a>""" % (HG_REPO, rev1, rev2)) |
|
239 | 240 | # finally: |
|
240 | 241 | # RepoModel().delete(HG_FORK) |
|
241 | 242 | # |
|
242 | 243 | # def test_org_repo_new_commits_after_forking_simple_diff(self): |
|
243 | 244 | # self.log_user() |
|
244 | 245 | # |
|
245 | 246 | # repo1 = RepoModel().create_repo(repo_name='one', repo_type='hg', |
|
246 | 247 | # description='diff-test', |
|
247 | 248 | # owner=TEST_USER_ADMIN_LOGIN) |
|
248 | 249 | # |
|
249 | 250 | # Session().commit() |
|
250 | 251 | # r1_id = repo1.repo_id |
|
251 | 252 | # r1_name = repo1.repo_name |
|
252 | 253 | # |
|
253 | 254 | # #commit something initially ! |
|
254 | 255 | # cs0 = ScmModel().create_node( |
|
255 | 256 | # repo=repo1.scm_instance, repo_name=r1_name, |
|
256 | 257 | # cs=EmptyChangeset(alias='hg'), user=TEST_USER_ADMIN_LOGIN, |
|
257 | 258 | # author=TEST_USER_ADMIN_LOGIN, |
|
258 | 259 | # message='commit1', |
|
259 | 260 | # content='line1', |
|
260 | 261 | # f_path='file1' |
|
261 | 262 | # ) |
|
262 | 263 | # Session().commit() |
|
263 | 264 | # self.assertEqual(repo1.scm_instance.revisions, [cs0.raw_id]) |
|
264 | 265 | # #fork the repo1 |
|
265 | 266 | # repo2 = RepoModel().create_repo(repo_name='one-fork', repo_type='hg', |
|
266 | 267 | # description='compare-test', |
|
267 | 268 | # clone_uri=repo1.repo_full_path, |
|
268 | 269 | # owner=TEST_USER_ADMIN_LOGIN, fork_of='one') |
|
269 | 270 | # Session().commit() |
|
270 | 271 | # self.assertEqual(repo2.scm_instance.revisions, [cs0.raw_id]) |
|
271 | 272 | # r2_id = repo2.repo_id |
|
272 | 273 | # r2_name = repo2.repo_name |
|
273 | 274 | # |
|
274 | 275 | # #make 3 new commits in fork |
|
275 | 276 | # cs1 = ScmModel().create_node( |
|
276 | 277 | # repo=repo2.scm_instance, repo_name=r2_name, |
|
277 | 278 | # cs=repo2.scm_instance[-1], user=TEST_USER_ADMIN_LOGIN, |
|
278 | 279 | # author=TEST_USER_ADMIN_LOGIN, |
|
279 | 280 | # message='commit1-fork', |
|
280 | 281 | # content='file1-line1-from-fork', |
|
281 | 282 | # f_path='file1-fork' |
|
282 | 283 | # ) |
|
283 | 284 | # cs2 = ScmModel().create_node( |
|
284 | 285 | # repo=repo2.scm_instance, repo_name=r2_name, |
|
285 | 286 | # cs=cs1, user=TEST_USER_ADMIN_LOGIN, |
|
286 | 287 | # author=TEST_USER_ADMIN_LOGIN, |
|
287 | 288 | # message='commit2-fork', |
|
288 | 289 | # content='file2-line1-from-fork', |
|
289 | 290 | # f_path='file2-fork' |
|
290 | 291 | # ) |
|
291 | 292 | # cs3 = ScmModel().create_node( |
|
292 | 293 | # repo=repo2.scm_instance, repo_name=r2_name, |
|
293 | 294 | # cs=cs2, user=TEST_USER_ADMIN_LOGIN, |
|
294 | 295 | # author=TEST_USER_ADMIN_LOGIN, |
|
295 | 296 | # message='commit3-fork', |
|
296 | 297 | # content='file3-line1-from-fork', |
|
297 | 298 | # f_path='file3-fork' |
|
298 | 299 | # ) |
|
299 | 300 | # |
|
300 | 301 | # #compare ! |
|
301 | 302 | # rev1 = 'default' |
|
302 | 303 | # rev2 = 'default' |
|
303 | 304 | # response = self.app.get(url(controller='compare', action='index', |
|
304 | 305 | # repo_name=r2_name, |
|
305 | 306 | # org_ref_type="branch", |
|
306 | 307 | # org_ref=rev1, |
|
307 | 308 | # other_ref_type="branch", |
|
308 | 309 | # other_ref=rev2, |
|
309 | 310 | # repo=r1_name, |
|
310 | 311 | # bundle=False, |
|
311 | 312 | # )) |
|
312 | 313 | # |
|
313 | 314 | # try: |
|
314 | 315 | # #response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2)) |
|
315 | 316 | # |
|
316 | 317 | # #add new commit into parent ! |
|
317 | 318 | # cs0 = ScmModel().create_node( |
|
318 | 319 | # repo=repo1.scm_instance, repo_name=r1_name, |
|
319 | 320 | # cs=EmptyChangeset(alias='hg'), user=TEST_USER_ADMIN_LOGIN, |
|
320 | 321 | # author=TEST_USER_ADMIN_LOGIN, |
|
321 | 322 | # message='commit2', |
|
322 | 323 | # content='line1', |
|
323 | 324 | # f_path='file2' |
|
324 | 325 | # ) |
|
325 | 326 | # #compare ! |
|
326 | 327 | # rev1 = 'default' |
|
327 | 328 | # rev2 = 'default' |
|
328 | 329 | # response = self.app.get(url(controller='compare', action='index', |
|
329 | 330 | # repo_name=r2_name, |
|
330 | 331 | # org_ref_type="branch", |
|
331 | 332 | # org_ref=rev1, |
|
332 | 333 | # other_ref_type="branch", |
|
333 | 334 | # other_ref=rev2, |
|
334 | 335 | # repo=r1_name, |
|
335 | 336 | # bundle=False |
|
336 | 337 | # )) |
|
337 | 338 | # |
|
338 | 339 | # response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2)) |
|
339 | 340 | # response.mustcontain("""file1-line1-from-fork""") |
|
340 | 341 | # response.mustcontain("""file2-line1-from-fork""") |
|
341 | 342 | # response.mustcontain("""file3-line1-from-fork""") |
|
342 | 343 | # self.assertFalse("""<a href="#">file2</a>""" in response.body) # new commit from parent |
|
343 | 344 | # self.assertFalse("""line1-from-new-parent""" in response.body) |
|
344 | 345 | # finally: |
|
345 | 346 | # RepoModel().delete(r2_id) |
|
346 | 347 | # RepoModel().delete(r1_id) |
General Comments 0
You need to be logged in to leave comments.
Login now