Merge ~twom/launchpad:git-page-default-branch into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: 6a9a70b85c3aa9c0454891bfbdaf84e29bc50c7c
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:git-page-default-branch
Merge into: launchpad:master
Diff against target: 53 lines (+31/-0)
2 files modified
lib/lp/code/browser/gitref.py (+11/-0)
lib/lp/code/browser/tests/test_branchmergeproposal.py (+20/-0)
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+379902@code.launchpad.net

Commit message

Add a default branch to the Git Merge Proposal page.

Description of the change

The target branch needs manually filling in, but most of the time you want to merge to the equivalent of 'master', or whatever is set as the default branch on that repository.

This change populates the box with the ref path with one of (choosing in order from):
* The default branch of the target repository
* The default branch of the source repository
* Nothing

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Needs Fixing
09ef3cf... by Tom Wardill

Use setupWidgets for more code reuse

Revision history for this message
Colin Watson (cjwatson) :
review: Approve
6a9a70b... by Tom Wardill

Variable name and test assertion

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/code/browser/gitref.py b/lib/lp/code/browser/gitref.py
2index 84bfc25..edbb0bf 100644
3--- a/lib/lp/code/browser/gitref.py
4+++ b/lib/lp/code/browser/gitref.py
5@@ -279,6 +279,17 @@ class GitRefRegisterMergeProposalView(LaunchpadFormView):
6 raise NotFound(self.context, '+register-merge')
7 super(GitRefRegisterMergeProposalView, self).initialize()
8
9+ def setUpWidgets(self, context=None):
10+ super(GitRefRegisterMergeProposalView, self).setUpWidgets(
11+ context=context)
12+ term = next(
13+ iter(self.widgets['target_git_repository'].vocabulary),
14+ None)
15+ # If we have a target, and the user hasn't entered a value.
16+ if term and not self.widgets['target_git_path'].hasInput():
17+ self.widgets['target_git_path'].setRenderedValue(
18+ term.value.default_branch)
19+
20 @action('Propose Merge', name='register',
21 failure=LaunchpadFormView.ajax_failure_handler)
22 def register_action(self, action, data):
23diff --git a/lib/lp/code/browser/tests/test_branchmergeproposal.py b/lib/lp/code/browser/tests/test_branchmergeproposal.py
24index 8180bc0..bf5bdb3 100644
25--- a/lib/lp/code/browser/tests/test_branchmergeproposal.py
26+++ b/lib/lp/code/browser/tests/test_branchmergeproposal.py
27@@ -862,6 +862,26 @@ class TestRegisterBranchMergeProposalViewGit(
28 values.update(extras)
29 return values
30
31+ def test_default_branch(self):
32+ with admin_logged_in():
33+ target_branch = self._makeTargetBranch(target_default=True)
34+ removeSecurityProxy(
35+ target_branch.repository)._default_branch = target_branch.path
36+ view = self._createView()
37+ self.assertEqual(
38+ target_branch.repository.default_branch,
39+ view.widgets['target_git_path']._getCurrentValue())
40+
41+ def test_default_branch_no_default_set(self):
42+ with admin_logged_in():
43+ self._makeTargetBranch(target_default=True)
44+ view = self._createView()
45+ self.assertIsNone(view.widgets['target_git_path']._getCurrentValue())
46+
47+ def test_default_branch_no_target(self):
48+ view = self._createView()
49+ self.assertIsNone(view.widgets['target_git_path']._getCurrentValue())
50+
51 def test_register_ajax_request_with_confirmation(self):
52 # Ajax submits return json data containing info about what the visible
53 # repositories are if they are not all visible to the reviewer.

Subscribers

People subscribed via source and target branches

to status/vote changes: