launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25527
[Merge] ~ilasc/launchpad:git-merge-instructions into launchpad:master
Ioana Lasc has proposed merging ~ilasc/launchpad:git-merge-instructions into launchpad:master.
Commit message:
Add merge instructions to GitRefPage
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~ilasc/launchpad/+git/launchpad/+merge/392588
This is a very early "direction review" MP.
Only contains GitRefPage code and only for personal projects and package.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/launchpad:git-merge-instructions into launchpad:master.
diff --git a/lib/lp/code/browser/gitref.py b/lib/lp/code/browser/gitref.py
index f17207e..f8b706e 100644
--- a/lib/lp/code/browser/gitref.py
+++ b/lib/lp/code/browser/gitref.py
@@ -141,6 +141,14 @@ class GitRefView(LaunchpadView, HasSnapsViewMixin):
return urlunsplit(url)
@property
+ def default_branch(self):
+ return self.context.repository.default_branch.strip("/").split("/")[2]
+
+ @property
+ def current_branch(self):
+ return self.context.path.strip("/").split("/")[2]
+
+ @property
def user_can_push(self):
"""Whether the user can push to this branch."""
return (
diff --git a/lib/lp/code/browser/tests/test_gitref.py b/lib/lp/code/browser/tests/test_gitref.py
index a55268a..4da620d 100644
--- a/lib/lp/code/browser/tests/test_gitref.py
+++ b/lib/lp/code/browser/tests/test_gitref.py
@@ -160,10 +160,10 @@ class TestGitRefView(BrowserTestCase):
def test_push_directions_logged_in_cannot_push_individual(self):
repo = self.factory.makeGitRepository()
- [ref] = self.factory.makeGitRefs(repository=repo,
- paths=["refs/heads/branch"])
+ ref1, ref2 = self.factory.makeGitRefs(repository=repo,
+ paths=["refs/heads/master", "refs/heads/branch"])
login_person(self.user)
- view = create_initialized_view(ref, "+index", principal=self.user)
+ view = create_initialized_view(ref2, "+index", principal=self.user)
git_push_url_text_match = soupmatchers.HTMLContains(
soupmatchers.Tag(
'Push url text', 'dt',
@@ -271,6 +271,69 @@ class TestGitRefView(BrowserTestCase):
div,
git_push_url_text_match)))
+ def test_merge_directions_personal_project(self):
+ repository = self.factory.makeGitRepository(
+ owner=self.user, target=self.user)
+
+ ref1, ref2 = self.factory.makeGitRefs(repository=repository,
+ paths=["refs/heads/master", "refs/heads/branch"])
+ removeSecurityProxy(repository).default_branch = "refs/heads/master"
+
+ login_person(self.user)
+ view = create_initialized_view(ref2, "+index", principal=self.user)
+ git_merge_checkout_match = soupmatchers.HTMLContains(
+ soupmatchers.Tag(
+ 'Checkout command text', 'tt',
+ attrs={"id": "merge-checkout-cmd"},
+ text="git checkout master"))
+ git_merge_match = soupmatchers.HTMLContains(
+ soupmatchers.Tag(
+ 'Merge command text', 'tt',
+ attrs={"id": "merge-cmd"},
+ text="git merge branch"))
+ with person_logged_in(self.user):
+ rendered_view = view.render()
+ self.assertThat(rendered_view, git_merge_checkout_match)
+ self.assertThat(rendered_view, git_merge_match)
+
+ def test_merge_directions_package(self):
+ # Repository is the default for a package
+ mint = self.factory.makeDistribution(name="mint")
+ eric = self.factory.makePerson(name="eric")
+ mint_choc = self.factory.makeDistributionSourcePackage(
+ distribution=mint, sourcepackagename="choc")
+ repository = self.factory.makeGitRepository(
+ owner=eric, target=mint_choc, name="choc-repo")
+
+ ref1, ref2 = self.factory.makeGitRefs(repository=repository,
+ paths=["refs/heads/master", "refs/heads/branch"])
+ removeSecurityProxy(repository).default_branch = "refs/heads/master"
+
+ dsp = repository.target
+ self.repository_set = getUtility(IGitRepositorySet)
+ with admin_logged_in():
+ self.repository_set.setDefaultRepositoryForOwner(
+ repository.owner, dsp, repository, repository.owner)
+ self.repository_set.setDefaultRepository(dsp, repository)
+ login_person(self.user)
+ view = create_initialized_view(ref2, "+index", principal=self.user)
+
+ git_merge_checkout_match = soupmatchers.HTMLContains(
+ soupmatchers.Tag(
+ 'Checkout command text', 'tt',
+ attrs={"id": "merge-checkout-cmd"},
+ text="git checkout master"))
+ git_merge_match = soupmatchers.HTMLContains(
+ soupmatchers.Tag(
+ 'Merge command text', 'tt',
+ attrs={"id": "merge-cmd"},
+ text="git merge branch"))
+
+ with person_logged_in(self.user):
+ rendered_view = view.render()
+ self.assertThat(rendered_view, git_merge_checkout_match)
+ self.assertThat(rendered_view, git_merge_match)
+
def makeCommitLog(self):
authors = [self.factory.makePerson() for _ in range(5)]
with admin_logged_in():
diff --git a/lib/lp/code/templates/git-macros.pt b/lib/lp/code/templates/git-macros.pt
index 9baaf4d..7e5a46d 100644
--- a/lib/lp/code/templates/git-macros.pt
+++ b/lib/lp/code/templates/git-macros.pt
@@ -67,6 +67,13 @@
<em>BRANCHNAME</em>
</tt>
</dd>
+ <dt>To merge this branch:</dt>
+ <dd>
+ <tt id="merge-checkout-cmd" class="command" tal:content="string:git checkout ${view/default_branch}" />
+ </dd>
+ <dd>
+ <tt id="merge-cmd" class="command" tal:content="string:git merge ${view/current_branch}" />
+ </dd>
</dl>
<dt tal:condition="python: getattr(view, 'allow_fork', False)">
<a tal:attributes="href view/fork_url" class="sprite add">
@@ -97,6 +104,13 @@
<em>BRANCHNAME</em>
</tt>
</dd>
+ <dt>To merge this branch:</dt>
+ <dd>
+ <tt id="merge-checkout-cmd" class="command" tal:content="string:git checkout ${view/default_branch}" />
+ </dd>
+ <dd>
+ <tt id="merge-cmd" class="command" tal:content="string:git merge ${view/current_branch}" />
+ </dd>
<dd tal:condition="python: getattr(view, 'allow_fork', False)">
or
<a tal:attributes="href view/fork_url" class="sprite add">
Follow ups