diff --git a/pagure/lib/git.py b/pagure/lib/git.py index d9b9d12..b2322e1 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -1399,7 +1399,12 @@ def get_diff_info(repo_obj, orig_repo, branch_from, branch_to, prid=None): :kwarg prid: the identifier of the pull-request to ''' - frombranch = repo_obj.lookup_branch(branch_from) + try: + frombranch = repo_obj.lookup_branch(branch_from) + except ValueError: + raise pagure.exceptions.BranchNotFoundException( + 'Branch %s does not exist' % branch_from + ) if not frombranch and not repo_obj.is_empty and prid is None: raise pagure.exceptions.BranchNotFoundException( 'Branch %s does not exist' % branch_from @@ -1407,7 +1412,12 @@ def get_diff_info(repo_obj, orig_repo, branch_from, branch_to, prid=None): branch = None if branch_to: - branch = orig_repo.lookup_branch(branch_to) + try: + branch = orig_repo.lookup_branch(branch_to) + except ValueError: + raise pagure.exceptions.BranchNotFoundException( + 'Branch %s does not exist' % branch_to + ) local_branches = orig_repo.listall_branches(pygit2.GIT_BRANCH_LOCAL) if not branch and local_branches: raise pagure.exceptions.BranchNotFoundException( diff --git a/tests/test_pagure_flask_ui_fork.py b/tests/test_pagure_flask_ui_fork.py index 842470e..98d1eea 100644 --- a/tests/test_pagure_flask_ui_fork.py +++ b/tests/test_pagure_flask_ui_fork.py @@ -1692,6 +1692,30 @@ index 0000000..2a552bb self.assertEqual(output.status_code, 200) @patch('pagure.lib.notify.send_email') + def test_new_request_pull_branch_space(self, send_email): + """ Test the new_request_pull endpoint. """ + send_email.return_value = True + + self.test_fork_project() + + tests.create_projects_git( + os.path.join(self.path, 'requests'), bare=True) + + repo = pagure.lib.get_authorized_project(self.session, 'test') + fork = pagure.lib.get_authorized_project(self.session, 'test', user='foo') + + self.set_up_git_repo( + new_project=fork, branch_from='feature', mtype='FF') + + user = tests.FakeUser(username = 'pingou') + with tests.user_set(self.app.application, user): + output = self.app.get('/test/diff/master..foo bar') + self.assertEqual(output.status_code, 400) + output_text = output.get_data(as_text=True) + self.assertIn( + '

Branch foo bar does not exist

', output_text) + + @patch('pagure.lib.notify.send_email') def test_new_request_pull(self, send_email): """ Test the new_request_pull endpoint. """ send_email.return_value = True