#3225 Fix diffing two branches if one has a space in its name
Merged 6 years ago by pingou. Opened 6 years ago by pingou.

file modified
+12 -2
@@ -1399,7 +1399,12 @@ 

      :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 @@ 

  

      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(

@@ -1692,6 +1692,30 @@ 

              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(

+                 '<p>Branch foo bar does not exist</p>', 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

Looks good to me and fixes the problem. :thumbsup:

rebased onto e3d601c

6 years ago

Thanks for the review!

Pull-Request has been merged by pingou

6 years ago