From d114c702f99bbc2efde186920e8d054d55b68292 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 17 2018 12:23:43 +0000 Subject: 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 --- diff --git a/pagure/ui/fork.py b/pagure/ui/fork.py index 68845da..d26dd66 100644 --- a/pagure/ui/fork.py +++ b/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, diff --git a/tests/test_pagure_flask_ui_fork.py b/tests/test_pagure_flask_ui_fork.py index 311da94..3ac12ab 100644 --- a/tests/test_pagure_flask_ui_fork.py +++ b/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
''', output_text) + self.assertIn( + ' master', + output_text) csrf_token = self.get_csrf(output=output) @@ -2553,6 +2559,86 @@ More information 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( + 'Create new Pull Request for master - ' + 'fork/pingou/test\n - Pagure', output_text) + self.assertIn( + '\n', + output_text) + self.assertIn( + ' master', + output_text) + self.assertIn( + ' random_branch', + 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. """ send_email.return_value = True