Merge lp:~cjwatson/launchpad/fix-git-prerequisite into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 17845
Proposed branch: lp:~cjwatson/launchpad/fix-git-prerequisite
Merge into: lp:launchpad
Diff against target: 111 lines (+35/-16)
4 files modified
lib/lp/code/browser/tests/test_branchmergeproposal.py (+24/-0)
lib/lp/code/model/diff.py (+5/-12)
lib/lp/code/model/githosting.py (+5/-3)
lib/lp/code/templates/branchmergeproposal-pagelet-summary.pt (+1/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/fix-git-prerequisite
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+277281@code.launchpad.net

Commit message

Handle prerequisites in Git-based merge proposals.

Description of the change

Handle prerequisites in Git-based merge proposals.

The corresponding turnip change is now live on qastaging, and there's what should be an XS ticket (RT#86272) to upgrade production.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

And I've fixed the conflicts now, whoops.

Revision history for this message
Colin Watson (cjwatson) wrote :

The corresponding turnip change has now been rolled out to production, so this should be good to go now.

Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/browser/tests/test_branchmergeproposal.py'
--- lib/lp/code/browser/tests/test_branchmergeproposal.py 2015-10-05 17:02:20 +0000
+++ lib/lp/code/browser/tests/test_branchmergeproposal.py 2015-11-11 18:30:32 +0000
@@ -11,6 +11,7 @@
11 timedelta,11 timedelta,
12 )12 )
13from difflib import unified_diff13from difflib import unified_diff
14import re
1415
15from lazr.lifecycle.event import ObjectModifiedEvent16from lazr.lifecycle.event import ObjectModifiedEvent
16from lazr.restful.interfaces import IJSONRequestCache17from lazr.restful.interfaces import IJSONRequestCache
@@ -1484,6 +1485,29 @@
1484 self.assertThat(browser.contents, HTMLContains(expected_meta))1485 self.assertThat(browser.contents, HTMLContains(expected_meta))
14851486
14861487
1488class TestBranchMergeProposalBrowserView(BrowserTestCase):
1489
1490 layer = DatabaseFunctionalLayer
1491
1492 def test_prerequisite_bzr(self):
1493 # A prerequisite branch is rendered in the Bazaar case.
1494 branch = self.factory.makeProductBranch()
1495 identity = branch.identity
1496 bmp = self.factory.makeBranchMergeProposal(prerequisite_branch=branch)
1497 text = self.getMainText(bmp, '+index')
1498 self.assertTextMatchesExpressionIgnoreWhitespace(
1499 'Prerequisite: ' + re.escape(identity), text)
1500
1501 def test_prerequisite_git(self):
1502 # A prerequisite reference is rendered in the Git case.
1503 [ref] = self.factory.makeGitRefs()
1504 identity = ref.identity
1505 bmp = self.factory.makeBranchMergeProposalForGit(prerequisite_ref=ref)
1506 text = self.getMainText(bmp, '+index')
1507 self.assertTextMatchesExpressionIgnoreWhitespace(
1508 'Prerequisite: ' + re.escape(identity), text)
1509
1510
1487class TestBranchMergeProposalChangeStatusView(TestCaseWithFactory):1511class TestBranchMergeProposalChangeStatusView(TestCaseWithFactory):
1488 """Test the +edit-status view."""1512 """Test the +edit-status view."""
14891513
14901514
=== modified file 'lib/lp/code/model/diff.py'
--- lib/lp/code/model/diff.py 2015-07-09 20:06:17 +0000
+++ lib/lp/code/model/diff.py 2015-11-11 18:30:32 +0000
@@ -450,22 +450,15 @@
450 path = "%s:%s" % (450 path = "%s:%s" % (
451 target_repository.getInternalPath(),451 target_repository.getInternalPath(),
452 source_repository.getInternalPath())452 source_repository.getInternalPath())
453 # XXX cjwatson 2015-04-30: Add prerequisite handling once turnip
454 # supports it.
455 response = getUtility(IGitHostingClient).getMergeDiff(453 response = getUtility(IGitHostingClient).getMergeDiff(
456 path, bmp.target_git_ref.commit_sha1,454 path, bmp.target_git_commit_sha1, bmp.source_git_commit_sha1,
457 bmp.source_git_ref.commit_sha1)455 prerequisite=bmp.prerequisite_git_commit_sha1)
458 source_revision_id = bmp.source_git_ref.commit_sha1
459 target_revision_id = bmp.target_git_ref.commit_sha1
460 if bmp.prerequisite_git_ref is not None:
461 prerequisite_revision_id = bmp.prerequisite_git_ref.commit_sha1
462 else:
463 prerequisite_revision_id = None
464 conflicts = u"".join(456 conflicts = u"".join(
465 u"Conflict in %s\n" % path for path in response['conflicts'])457 u"Conflict in %s\n" % path for path in response['conflicts'])
466 preview = cls.create(458 preview = cls.create(
467 bmp, response['patch'].encode('utf-8'), source_revision_id,459 bmp, response['patch'].encode('utf-8'),
468 target_revision_id, prerequisite_revision_id, conflicts,460 bmp.source_git_commit_sha1, bmp.target_git_commit_sha1,
461 bmp.prerequisite_git_commit_sha1, conflicts,
469 strip_prefix_segments=1)462 strip_prefix_segments=1)
470 del get_property_cache(bmp).preview_diffs463 del get_property_cache(bmp).preview_diffs
471 del get_property_cache(bmp).preview_diff464 del get_property_cache(bmp).preview_diff
472465
=== modified file 'lib/lp/code/model/githosting.py'
--- lib/lp/code/model/githosting.py 2015-10-05 04:57:16 +0000
+++ lib/lp/code/model/githosting.py 2015-11-11 18:30:32 +0000
@@ -125,15 +125,17 @@
125 "Failed to get commit details from Git repository: %s" %125 "Failed to get commit details from Git repository: %s" %
126 unicode(e))126 unicode(e))
127127
128 def getMergeDiff(self, path, base, head, logger=None):128 def getMergeDiff(self, path, base, head, prerequisite=None, logger=None):
129 """See `IGitHostingClient`."""129 """See `IGitHostingClient`."""
130 try:130 try:
131 if logger is not None:131 if logger is not None:
132 logger.info(132 logger.info(
133 "Requesting merge diff for %s from %s to %s" % (133 "Requesting merge diff for %s from %s to %s" % (
134 path, base, head))134 path, base, head))
135 return self._get(135 url = "/repo/%s/compare-merge/%s:%s" % (path, base, head)
136 "/repo/%s/compare-merge/%s:%s" % (path, base, head))136 if prerequisite is not None:
137 url += "?sha1_prerequisite=%s" % prerequisite
138 return self._get(url)
137 except Exception as e:139 except Exception as e:
138 raise GitRepositoryScanFault(140 raise GitRepositoryScanFault(
139 "Failed to get merge diff from Git repository: %s" %141 "Failed to get merge diff from Git repository: %s" %
140142
=== modified file 'lib/lp/code/templates/branchmergeproposal-pagelet-summary.pt'
--- lib/lp/code/templates/branchmergeproposal-pagelet-summary.pt 2015-06-10 10:25:28 +0000
+++ lib/lp/code/templates/branchmergeproposal-pagelet-summary.pt 2015-11-11 18:30:32 +0000
@@ -110,7 +110,7 @@
110 <td tal:content="structure context/merge_target/fmt:link">lp:~foo/bar/baz</td>110 <td tal:content="structure context/merge_target/fmt:link">lp:~foo/bar/baz</td>
111 </tr>111 </tr>
112 <tr id="summary-row-a-prerequisite-branch"112 <tr id="summary-row-a-prerequisite-branch"
113 tal:condition="context/prerequisite_branch">113 tal:condition="context/merge_prerequisite">
114 <th>Prerequisite:</th>114 <th>Prerequisite:</th>
115 <td tal:content="structure context/merge_prerequisite/fmt:link">lp:~foo/bar/baz</td>115 <td tal:content="structure context/merge_prerequisite/fmt:link">lp:~foo/bar/baz</td>
116 </tr>116 </tr>