Browse Source

Fix ensuring the list of branches on the new PR page matches the repo

Before this commit, the list of branches shown in the drop-down for the
branch from in the new PR page was the list of branches of the target
repo instead of being the list of branches for the destination repo.

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
Pierre-Yves Chibon 5 years ago
parent
commit
d114c702f9
2 changed files with 88 additions and 2 deletions
  1. 1 1
      pagure/ui/fork.py
  2. 87 1
      tests/test_pagure_flask_ui_fork.py

+ 1 - 1
pagure/ui/fork.py

@@ -1760,7 +1760,7 @@ def new_request_pull(
         repo=repo,
         username=username,
         orig_repo=orig_repo,
-        parent_branches=sorted(orig_repo.listall_branches()),
+        parent_branches=sorted(flask.g.repo_obj.listall_branches()),
         diff_commits=diff_commits,
         diff=diff,
         form=form,

+ 87 - 1
tests/test_pagure_flask_ui_fork.py

@@ -2280,7 +2280,8 @@ index 0000000..2a552bb
             os.path.join(self.path, 'requests'), bare=True)
 
         repo = pagure.lib.query.get_authorized_project(self.session, 'test')
-        fork = pagure.lib.query.get_authorized_project(self.session, 'test', user='foo')
+        fork = pagure.lib.query.get_authorized_project(
+            self.session, 'test', user='foo')
 
         set_up_git_repo(
             self.session, self.path, new_project=fork,
@@ -2339,6 +2340,11 @@ index 0000000..2a552bb
             placeholder="Describe your changes" tabindex=1>
 More information</textarea>
             <div id="preview" class="p-1">''', output_text)
+            self.assertIn(
+                '<a href="javascript:void(0)" class="dropdown-item '
+                'branch_from_item" data-value="master"><span '
+                'class="fa fa-random"></span> master</a>',
+                output_text)
 
             csrf_token = self.get_csrf(output=output)
 
@@ -2552,6 +2558,86 @@ More information</textarea>
         self.assertIsNotNone(request.commit_start)
         self.assertIsNotNone(request.commit_stop)
 
+    @patch('pagure.lib.notify.send_email')
+    def test_new_request_pull_from_fork_branch(self, send_email):
+        """ Test creating a fork to fork PR. """
+        send_email.return_value = True
+
+        # Create main repo with some content
+        tests.create_projects(self.session)
+        tests.create_projects_git(
+            os.path.join(self.path, "repos"),
+            bare=True
+        )
+        tests.add_content_git_repo(
+            os.path.join(self.path, "repos", "test.git"))
+
+        # Create fork repo with more content
+        tests.create_projects(
+            self.session,
+            is_fork=True,
+            hook_token_suffix='fork')
+        tests.create_projects_git(
+            os.path.join(self.path, "repos", "forks", "pingou"),
+            bare=True
+        )
+        tests.add_content_git_repo(
+            os.path.join(self.path, "repos", "forks", "pingou", "test.git"))
+        tests.add_readme_git_repo(
+            os.path.join(self.path, "repos", "forks", "pingou", "test.git"),
+            branch='feature')
+        tests.add_readme_git_repo(
+            os.path.join(self.path, "repos", "forks", "pingou", "test.git"),
+            branch='random_branch')
+
+        user = tests.FakeUser(username='pingou')
+        with tests.user_set(self.app.application, user):
+            data = {
+                'csrf_token': self.get_csrf(),
+            }
+
+            output = self.app.post(
+                '/do_fork/test', data=data,
+                follow_redirects=True)
+            self.assertEqual(output.status_code, 200)
+
+            # Check that Ralph's fork do exist
+            output = self.app.get('/fork/pingou/test')
+            self.assertEqual(output.status_code, 200)
+
+            tests.create_projects_git(
+                os.path.join(self.path, 'requests'), bare=True)
+
+            fork = pagure.lib.query.get_authorized_project(
+                self.session, 'test', user='ralph')
+
+            set_up_git_repo(
+                self.session, self.path, new_project=fork,
+                branch_from='feature', mtype='FF')
+
+            # Try opening a pull-request
+            output = self.app.get(
+                '/fork/pingou/test/diff/master..feature')
+            self.assertEqual(output.status_code, 200)
+            output_text = output.get_data(as_text=True)
+            self.assertIn(
+                '<title>Create new Pull Request for master - '
+                'fork/pingou/test\n - Pagure</title>', output_text)
+            self.assertIn(
+                '<input type="submit" class="btn btn-primary" value="Create Pull Request">\n',
+                output_text)
+            self.assertIn(
+                '<a href="javascript:void(0)" class="dropdown-item '
+                'branch_from_item" data-value="master"><span '
+                'class="fa fa-random"></span> master</a>',
+                output_text)
+            self.assertIn(
+                '<a href="javascript:void(0)" class="dropdown-item '
+                'branch_from_item" data-value="random_branch"><span '
+                'class="fa fa-random"></span> random_branch</a>',
+                output_text)
+
+
     @patch('pagure.lib.notify.send_email')
     def test_new_request_pull_fork_to_fork_pr_disabled(self, send_email):
         """ Test creating a fork to fork PR. """