##// END OF EJS Templates
fixed pull-requests with cherry picking changesets...
marcink -
r3380:01fe360a beta
parent child Browse files
Show More
@@ -40,9 +40,7 b' from rhodecode.lib import diffs'
40 from rhodecode.model.db import Repository
40 from rhodecode.model.db import Repository
41 from rhodecode.model.pull_request import PullRequestModel
41 from rhodecode.model.pull_request import PullRequestModel
42 from webob.exc import HTTPBadRequest
42 from webob.exc import HTTPBadRequest
43 from rhodecode.lib.utils2 import str2bool
44 from rhodecode.lib.diffs import LimitedDiffContainer
43 from rhodecode.lib.diffs import LimitedDiffContainer
45 from rhodecode.lib.vcs.backends.base import EmptyChangeset
46
44
47 log = logging.getLogger(__name__)
45 log = logging.getLogger(__name__)
48
46
@@ -99,32 +97,50 b' class CompareController(BaseRepoControll'
99 other_repo=org_repo,
97 other_repo=org_repo,
100 other_ref_type=org_ref[0], other_ref=org_ref[1])
98 other_ref_type=org_ref[0], other_ref=org_ref[1])
101
99
102 c.org_repo = org_repo = Repository.get_by_repo_name(org_repo)
100 partial = request.environ.get('HTTP_X_PARTIAL_XHR')
103 c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
101
102 org_repo = Repository.get_by_repo_name(org_repo)
103 other_repo = Repository.get_by_repo_name(other_repo)
104
104
105 if c.org_repo is None:
105 self.__get_cs_or_redirect(rev=org_ref, repo=org_repo, partial=partial)
106 self.__get_cs_or_redirect(rev=other_ref, repo=other_repo, partial=partial)
107
108 if org_repo is None:
106 log.error('Could not find org repo %s' % org_repo)
109 log.error('Could not find org repo %s' % org_repo)
107 raise HTTPNotFound
110 raise HTTPNotFound
108 if c.other_repo is None:
111 if other_repo is None:
109 log.error('Could not find other repo %s' % other_repo)
112 log.error('Could not find other repo %s' % other_repo)
110 raise HTTPNotFound
113 raise HTTPNotFound
111
114
112 if c.org_repo != c.other_repo and h.is_git(c.rhodecode_repo):
115 if org_repo != other_repo and h.is_git(org_repo):
113 log.error('compare of two remote repos not available for GIT REPOS')
116 log.error('compare of two remote repos not available for GIT REPOS')
114 raise HTTPNotFound
117 raise HTTPNotFound
115
118
116 if c.org_repo.scm_instance.alias != c.other_repo.scm_instance.alias:
119 if org_repo.scm_instance.alias != other_repo.scm_instance.alias:
117 log.error('compare of two different kind of remote repos not available')
120 log.error('compare of two different kind of remote repos not available')
118 raise HTTPNotFound
121 raise HTTPNotFound
119
122
120 partial = request.environ.get('HTTP_X_PARTIAL_XHR')
123 c.org_repo = org_repo
121 self.__get_cs_or_redirect(rev=org_ref, repo=org_repo, partial=partial)
124 c.other_repo = other_repo
122 self.__get_cs_or_redirect(rev=other_ref, repo=other_repo, partial=partial)
125 c.org_ref = org_ref[1]
126 c.other_ref = other_ref[1]
127 c.org_ref_type = org_ref[0]
128 c.other_ref_type = other_ref[0]
123
129
124 if rev_start and rev_end:
130 if rev_start and rev_end:
125 #replace our org_ref with given CS
131 # swap revs with cherry picked ones, save them for display
132 #org_ref = ('rev', rev_start)
133 #other_ref = ('rev', rev_end)
134 c.org_ref = rev_start[:12]
135 c.other_ref = rev_end[:12]
136 # get parent of
137 # rev start to include it in the diff
138 _cs = other_repo.scm_instance.get_changeset(rev_start)
139 rev_start = _cs.parents[0].raw_id
126 org_ref = ('rev', rev_start)
140 org_ref = ('rev', rev_start)
127 other_ref = ('rev', rev_end)
141 other_ref = ('rev', rev_end)
142 #if we cherry pick it's not remote, make the other_repo org_repo
143 org_repo = other_repo
128
144
129 c.cs_ranges, ancestor = PullRequestModel().get_compare_data(
145 c.cs_ranges, ancestor = PullRequestModel().get_compare_data(
130 org_repo, org_ref, other_repo, other_ref)
146 org_repo, org_ref, other_repo, other_ref)
@@ -136,18 +152,13 b' class CompareController(BaseRepoControll'
136 if partial:
152 if partial:
137 return render('compare/compare_cs.html')
153 return render('compare/compare_cs.html')
138
154
139 c.org_ref = org_ref[1]
155 if ancestor and org_repo != other_repo:
140 c.org_ref_type = org_ref[0]
141 c.other_ref = other_ref[1]
142 c.other_ref_type = other_ref[0]
143
144 if ancestor and c.org_repo != c.other_repo:
145 # case we want a simple diff without incoming changesets,
156 # case we want a simple diff without incoming changesets,
146 # previewing what will be merged.
157 # previewing what will be merged.
147 # Make the diff on the forked repo, with
158 # Make the diff on the forked repo, with
148 # revision that is common ancestor
159 # revision that is common ancestor
149 _org_ref = org_ref
160 log.debug('Using ancestor %s as org_ref instead of %s'
150 log.debug('Using ancestor %s as org_ref instead of %s', ancestor, _org_ref)
161 % (ancestor, org_ref))
151 org_ref = ('rev', ancestor)
162 org_ref = ('rev', ancestor)
152 org_repo = other_repo
163 org_repo = other_repo
153
164
@@ -227,13 +227,9 b' class PullRequestModel(BaseModel):'
227 Returns incoming changesets for mercurial repositories
227 Returns incoming changesets for mercurial repositories
228
228
229 :param org_repo:
229 :param org_repo:
230 :type org_repo:
231 :param org_ref:
230 :param org_ref:
232 :type org_ref:
233 :param other_repo:
231 :param other_repo:
234 :type other_repo:
235 :param other_ref:
232 :param other_ref:
236 :type other_ref:
237 """
233 """
238
234
239 if len(org_ref) != 2 or not isinstance(org_ref, (list, tuple)):
235 if len(org_ref) != 2 or not isinstance(org_ref, (list, tuple)):
@@ -163,7 +163,6 b''
163 var repo_name = sel_box.options[sel_box.selectedIndex].value;
163 var repo_name = sel_box.options[sel_box.selectedIndex].value;
164 YUD.get('pull_request_overview_url').href = url;
164 YUD.get('pull_request_overview_url').href = url;
165 YUD.setStyle(YUD.get('pull_request_overview_url').parentElement,'display','');
165 YUD.setStyle(YUD.get('pull_request_overview_url').parentElement,'display','');
166 YUD.get('other_repo_gravatar').src = other_repos_info[repo_name]['gravatar'];
167 YUD.get('other_repo_desc').innerHTML = other_repos_info[repo_name]['description'];
166 YUD.get('other_repo_desc').innerHTML = other_repos_info[repo_name]['description'];
168 YUD.get('other_ref').innerHTML = other_repos_info[repo_name]['revs'];
167 YUD.get('other_ref').innerHTML = other_repos_info[repo_name]['revs'];
169 // select back the revision that was just compared
168 // select back the revision that was just compared
@@ -27,7 +27,7 b' def _fork_repo(fork_name, vcs_type, pare'
27 update_after_clone=False,
27 update_after_clone=False,
28 fork_parent_id=Repository.get_by_repo_name(_REPO),
28 fork_parent_id=Repository.get_by_repo_name(_REPO),
29 )
29 )
30 repo = RepoModel().create_fork(form_data, cur_user=TEST_USER_ADMIN_LOGIN)
30 RepoModel().create_fork(form_data, cur_user=TEST_USER_ADMIN_LOGIN)
31
31
32 Session().commit()
32 Session().commit()
33 return Repository.get_by_repo_name(fork_name)
33 return Repository.get_by_repo_name(fork_name)
@@ -87,7 +87,6 b' class TestCompareController(TestControll'
87
87
88 #fork this repo
88 #fork this repo
89 repo2 = _fork_repo('one-fork', 'hg', parent='one')
89 repo2 = _fork_repo('one-fork', 'hg', parent='one')
90 Session().commit()
91 self.r2_id = repo2.repo_id
90 self.r2_id = repo2.repo_id
92
91
93 #add two extra commit into fork
92 #add two extra commit into fork
@@ -138,7 +137,6 b' class TestCompareController(TestControll'
138
137
139 #fork this repo
138 #fork this repo
140 repo2 = _fork_repo('one-fork', 'hg', parent='one')
139 repo2 = _fork_repo('one-fork', 'hg', parent='one')
141 Session().commit()
142 self.r2_id = repo2.repo_id
140 self.r2_id = repo2.repo_id
143
141
144 #now commit something to origin repo
142 #now commit something to origin repo
@@ -178,18 +176,17 b' class TestCompareController(TestControll'
178 response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?as_form=None&amp;other_repo=%s">[swap]</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
176 response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?as_form=None&amp;other_repo=%s">[swap]</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
179
177
180 def test_compare_cherry_pick_changesets_from_bottom(self):
178 def test_compare_cherry_pick_changesets_from_bottom(self):
181 """
179
182 repo1:
180 # repo1:
183 cs1:
181 # cs0:
184 cs2:
182 # cs1:
185 repo1-fork- in which we will cherry pick bottom changesets
183 # repo1-fork- in which we will cherry pick bottom changesets
186 cs1:
184 # cs0:
187 cs2:
185 # cs1:
188 cs3: x
186 # cs2: x
189 cs4: x
187 # cs3: x
190 cs5: x
188 # cs4: x
191 cs6:
189 # cs5:
192 """
193 #make repo1, and cs1+cs2
190 #make repo1, and cs1+cs2
194 self.log_user()
191 self.log_user()
195
192
@@ -200,25 +197,89 b' class TestCompareController(TestControll'
200 self.r1_id = repo1.repo_id
197 self.r1_id = repo1.repo_id
201
198
202 #commit something !
199 #commit something !
203 cs1 = _commit_change(repo1.repo_name, filename='file1', content='line1\n',
200 cs0 = _commit_change(repo1.repo_name, filename='file1', content='line1\n',
204 message='commit1', vcs_type='hg', parent=None,
201 message='commit1', vcs_type='hg', parent=None,
205 newfile=True)
202 newfile=True)
206 cs2 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\n',
203 cs1 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\n',
207 message='commit2', vcs_type='hg', parent=cs1)
204 message='commit2', vcs_type='hg', parent=cs0)
208 #fork this repo
205 #fork this repo
209 repo2 = _fork_repo('repo1-fork', 'hg', parent='repo1')
206 repo2 = _fork_repo('repo1-fork', 'hg', parent='repo1')
210 Session().commit()
211 self.r2_id = repo2.repo_id
207 self.r2_id = repo2.repo_id
212 #now make cs3-6
208 #now make cs3-6
213 cs3 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\n',
209 cs2 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\n',
214 message='commit3', vcs_type='hg', parent=cs2)
210 message='commit3', vcs_type='hg', parent=cs1)
215 cs4 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\n',
211 cs3 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\n',
216 message='commit4', vcs_type='hg', parent=cs3)
212 message='commit4', vcs_type='hg', parent=cs2)
217 cs5 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\n',
213 cs4 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\n',
218 message='commit5', vcs_type='hg', parent=cs4)
214 message='commit5', vcs_type='hg', parent=cs3)
219 cs6 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\nline6\n',
215 cs5 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\nline6\n',
220 message='commit6', vcs_type='hg', parent=cs5)
216 message='commit6', vcs_type='hg', parent=cs4)
217
218 rev1 = 'tip'
219 rev2 = 'tip'
220
221 response = self.app.get(url(controller='compare', action='index',
222 repo_name=repo2.repo_name,
223 org_ref_type="tag",
224 org_ref=rev1,
225 other_repo=repo1.repo_name,
226 other_ref_type="tag",
227 other_ref=rev2,
228 rev_start=cs2.raw_id,
229 rev_end=cs4.raw_id,
230 ))
231 response.mustcontain('%s@%s -&gt; %s@%s' % (repo2.repo_name, cs2.short_id, repo1.repo_name, cs4.short_id))
232 response.mustcontain("""Showing 3 commits""")
233 response.mustcontain("""1 file changed with 3 insertions and 0 deletions""")
234
235 response.mustcontain("""<div class="message tooltip" title="commit3" style="white-space:normal">commit3</div>""")
236 response.mustcontain("""<div class="message tooltip" title="commit4" style="white-space:normal">commit4</div>""")
237 response.mustcontain("""<div class="message tooltip" title="commit5" style="white-space:normal">commit5</div>""")
238
239 response.mustcontain("""<a href="/%s/changeset/%s">r2:%s</a>""" % (repo1.repo_name, cs2.raw_id, cs2.short_id))
240 response.mustcontain("""<a href="/%s/changeset/%s">r3:%s</a>""" % (repo1.repo_name, cs3.raw_id, cs3.short_id))
241 response.mustcontain("""<a href="/%s/changeset/%s">r4:%s</a>""" % (repo1.repo_name, cs4.raw_id, cs4.short_id))
242 ## files
243 response.mustcontain("""#C--826e8142e6ba">file1</a>""")
221
244
245 def test_compare_cherry_pick_changesets_from_top(self):
246 # repo1:
247 # cs0:
248 # cs1:
249 # repo1-fork- in which we will cherry pick bottom changesets
250 # cs0:
251 # cs1:
252 # cs2:
253 # cs3: x
254 # cs4: x
255 # cs5: x
256 #
257 #make repo1, and cs1+cs2
258 self.log_user()
259 repo1 = RepoModel().create_repo(repo_name='repo1', repo_type='hg',
260 description='diff-test',
261 owner=TEST_USER_ADMIN_LOGIN)
262 Session().commit()
263 self.r1_id = repo1.repo_id
264
265 #commit something !
266 cs0 = _commit_change(repo1.repo_name, filename='file1', content='line1\n',
267 message='commit1', vcs_type='hg', parent=None,
268 newfile=True)
269 cs1 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\n',
270 message='commit2', vcs_type='hg', parent=cs0)
271 #fork this repo
272 repo2 = _fork_repo('repo1-fork', 'hg', parent='repo1')
273 self.r2_id = repo2.repo_id
274 #now make cs3-6
275 cs2 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\n',
276 message='commit3', vcs_type='hg', parent=cs1)
277 cs3 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\n',
278 message='commit4', vcs_type='hg', parent=cs2)
279 cs4 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\n',
280 message='commit5', vcs_type='hg', parent=cs3)
281 cs5 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\nline6\n',
282 message='commit6', vcs_type='hg', parent=cs4)
222 rev1 = 'tip'
283 rev1 = 'tip'
223 rev2 = 'tip'
284 rev2 = 'tip'
224
285
@@ -232,91 +293,20 b' class TestCompareController(TestControll'
232 rev_start=cs3.raw_id,
293 rev_start=cs3.raw_id,
233 rev_end=cs5.raw_id,
294 rev_end=cs5.raw_id,
234 ))
295 ))
235 response.mustcontain('%s@%s -&gt; %s@%s' % (repo2.repo_name, rev1, repo1.repo_name, rev2))
296
297 response.mustcontain('%s@%s -&gt; %s@%s' % (repo2.repo_name, cs3.short_id, repo1.repo_name, cs5.short_id))
236 response.mustcontain("""Showing 3 commits""")
298 response.mustcontain("""Showing 3 commits""")
237 response.mustcontain("""1 file changed with 3 insertions and 0 deletions""")
299 response.mustcontain("""1 file changed with 3 insertions and 0 deletions""")
238
300
239 response.mustcontain("""<div class="message tooltip" title="commit3" style="white-space:normal">commit3</div>""")
240 response.mustcontain("""<div class="message tooltip" title="commit4" style="white-space:normal">commit4</div>""")
301 response.mustcontain("""<div class="message tooltip" title="commit4" style="white-space:normal">commit4</div>""")
241 response.mustcontain("""<div class="message tooltip" title="commit5" style="white-space:normal">commit5</div>""")
302 response.mustcontain("""<div class="message tooltip" title="commit5" style="white-space:normal">commit5</div>""")
242
303 response.mustcontain("""<div class="message tooltip" title="commit6" style="white-space:normal">commit6</div>""")
243 response.mustcontain("""<a href="/%s/changeset/%s">r3:%s</a>""" % (repo2.repo_name, cs3.raw_id, cs3.short_id))
244 response.mustcontain("""<a href="/%s/changeset/%s">r4:%s</a>""" % (repo2.repo_name, cs4.raw_id, cs4.short_id))
245 response.mustcontain("""<a href="/%s/changeset/%s">r5:%s</a>""" % (repo2.repo_name, cs5.raw_id, cs5.short_id))
246 ## files
247 response.mustcontain("""<a href="/%s/compare/tag@%s...tag@%s?other_repo=%s#C--826e8142e6ba">file1</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
248 #swap
249 response.mustcontain("""<a href="/%s/compare/tag@%s...tag@%s?as_form=None&amp;other_repo=%s">[swap]</a>""" % (repo1.repo_name, rev1, rev2, repo2.repo_name))
250
251 def test_compare_cherry_pick_changesets_from_top(self):
252 """
253 repo1:
254 cs1:
255 cs2:
256 repo1-fork- in which we will cherry pick bottom changesets
257 cs1:
258 cs2:
259 cs3:
260 cs4: x
261 cs5: x
262 cs6: x
263 """
264 #make repo1, and cs1+cs2
265 self.log_user()
266 repo1 = RepoModel().create_repo(repo_name='repo1', repo_type='hg',
267 description='diff-test',
268 owner=TEST_USER_ADMIN_LOGIN)
269 Session().commit()
270 self.r1_id = repo1.repo_id
271
304
272 #commit something !
305 response.mustcontain("""<a href="/%s/changeset/%s">r3:%s</a>""" % (repo1.repo_name, cs3.raw_id, cs3.short_id))
273 cs1 = _commit_change(repo1.repo_name, filename='file1', content='line1\n',
306 response.mustcontain("""<a href="/%s/changeset/%s">r4:%s</a>""" % (repo1.repo_name, cs4.raw_id, cs4.short_id))
274 message='commit1', vcs_type='hg', parent=None,
307 response.mustcontain("""<a href="/%s/changeset/%s">r5:%s</a>""" % (repo1.repo_name, cs5.raw_id, cs5.short_id))
275 newfile=True)
276 cs2 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\n',
277 message='commit2', vcs_type='hg', parent=cs1)
278 #fork this repo
279 repo2 = _fork_repo('repo1-fork', 'hg', parent='repo1')
280 Session().commit()
281 self.r2_id = repo1.repo_id
282 #now make cs3-6
283 cs3 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\n',
284 message='commit3', vcs_type='hg', parent=cs2)
285 cs4 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\n',
286 message='commit4', vcs_type='hg', parent=cs3)
287 cs5 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\n',
288 message='commit5', vcs_type='hg', parent=cs4)
289 cs6 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\nline6\n',
290 message='commit6', vcs_type='hg', parent=cs5)
291 rev1 = 'tip'
292 rev2 = 'tip'
293
294 response = self.app.get(url(controller='compare', action='index',
295 repo_name=repo2.repo_name,
296 org_ref_type="tag",
297 org_ref=rev1,
298 other_repo=repo1.repo_name,
299 other_ref_type="tag",
300 other_ref=rev2,
301 rev_start=cs4.raw_id,
302 rev_end=cs6.raw_id,
303 ))
304
305 response.mustcontain('%s@%s -&gt; %s@%s' % (repo2.repo_name, rev1, repo1.repo_name, rev2))
306 response.mustcontain("""Showing 3 commits""")
307 response.mustcontain("""1 file changed with 3 insertions and 0 deletions""")
308
309 response.mustcontain("""<div class="message tooltip" title="commit3" style="white-space:normal">commit4</div>""")
310 response.mustcontain("""<div class="message tooltip" title="commit4" style="white-space:normal">commit5</div>""")
311 response.mustcontain("""<div class="message tooltip" title="commit5" style="white-space:normal">commit6</div>""")
312
313 response.mustcontain("""<a href="/%s/changeset/%s">r4:%s</a>""" % (repo2.repo_name, cs4.raw_id, cs4.short_id))
314 response.mustcontain("""<a href="/%s/changeset/%s">r5:%s</a>""" % (repo2.repo_name, cs5.raw_id, cs5.short_id))
315 response.mustcontain("""<a href="/%s/changeset/%s">r6:%s</a>""" % (repo2.repo_name, cs6.raw_id, cs6.short_id))
316 ## files
308 ## files
317 response.mustcontain("""<a href="/%s/compare/tag@%s...tag@%s?other_repo=%s#C--826e8142e6ba">file1</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
309 response.mustcontain("""#C--826e8142e6ba">file1</a>""")
318 #swap
319 response.mustcontain("""<a href="/%s/compare/tag@%s...tag@%s?as_form=None&amp;other_repo=%s">[swap]</a>""" % (repo1.repo_name, rev1, rev2, repo2.repo_name))
320
310
321 def test_compare_cherry_pick_changeset_mixed_branches(self):
311 def test_compare_cherry_pick_changeset_mixed_branches(self):
322 """
312 """
@@ -328,8 +318,8 b' class TestCompareController(TestControll'
328 def test_compare_remote_branches_hg(self):
318 def test_compare_remote_branches_hg(self):
329 self.log_user()
319 self.log_user()
330
320
331 _fork_repo(HG_FORK, 'hg')
321 repo2 = _fork_repo(HG_FORK, 'hg')
332
322 self.r2_id = repo2.repo_id
333 rev1 = '56349e29c2af'
323 rev1 = '56349e29c2af'
334 rev2 = '7d4bc8ec6be5'
324 rev2 = '7d4bc8ec6be5'
335
325
General Comments 0
You need to be logged in to leave comments. Login now