launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24384
[Merge] ~twom/launchpad:git-page-default-branch into launchpad:master
Tom Wardill has proposed merging ~twom/launchpad:git-page-default-branch into launchpad:master.
Commit message:
Add a default branch to the Git Merge Proposal page.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/379902
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
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:git-page-default-branch into launchpad:master.
diff --git a/lib/lp/code/browser/gitref.py b/lib/lp/code/browser/gitref.py
index 84bfc25..8552bd7 100644
--- a/lib/lp/code/browser/gitref.py
+++ b/lib/lp/code/browser/gitref.py
@@ -47,6 +47,7 @@ from lp.code.interfaces.branchmergeproposal import IBranchMergeProposal
from lp.code.interfaces.codereviewvote import ICodeReviewVoteReference
from lp.code.interfaces.gitref import IGitRef
from lp.code.interfaces.gitrepository import IGitRepositorySet
+from lp.registry.interfaces.person import IPerson
from lp.services.helpers import english_list
from lp.services.propertycache import cachedproperty
from lp.services.scripts import log
@@ -387,3 +388,27 @@ class GitRefRegisterMergeProposalView(LaunchpadFormView):
'prerequisite_git_repository',
"This repository is not mergeable into %s." %
target_repository.identity)
+
+ @property
+ def initial_values(self):
+ values = {}
+ if IGitRef.providedBy(self.context):
+ repository = self.context.repository
+ else:
+ repository = self.context
+
+ if IPerson.providedBy(repository.target):
+ # If the source is a personal repository, then the only valid
+ # target is that same repository.
+ target_repository = repository
+ else:
+ repository_set = getUtility(IGitRepositorySet)
+ target_repository = repository_set.getDefaultRepository(
+ repository.target)
+ # If the target has a default branch, use that.
+ # If not, see if we can use the source one for convenience.
+ if target_repository and target_repository.default_branch:
+ values['target_git_path'] = target_repository.default_branch
+ elif repository.default_branch:
+ values['target_git_path'] = repository.default_branch
+ return values
diff --git a/lib/lp/code/browser/tests/test_branchmergeproposal.py b/lib/lp/code/browser/tests/test_branchmergeproposal.py
index 8180bc0..65c53a8 100644
--- a/lib/lp/code/browser/tests/test_branchmergeproposal.py
+++ b/lib/lp/code/browser/tests/test_branchmergeproposal.py
@@ -862,6 +862,16 @@ class TestRegisterBranchMergeProposalViewGit(
values.update(extras)
return values
+ def test_default_branch(self):
+ with admin_logged_in():
+ target_branch = self._makeTargetBranch(target_default=True)
+ removeSecurityProxy(
+ target_branch.repository)._default_branch = target_branch.path
+ view = self._createView()
+ self.assertEqual(
+ target_branch.repository.default_branch,
+ view.initial_values['target_git_path'])
+
def test_register_ajax_request_with_confirmation(self):
# Ajax submits return json data containing info about what the visible
# repositories are if they are not all visible to the reviewer.