#5059 Ensure a fork project has the same default branch as its parent
Merged 3 years ago by pingou. Opened 3 years ago by pingou.

file modified
+5
@@ -514,6 +514,11 @@ 

                  with open(http_clone_file, "w"):

                      pass

  

+         # Finally set the default branch to be the same as the parent

+         repo_from_obj = pygit2.Repository(repo_from.repopath("main"))

+         repo_to_obj = pygit2.Repository(repo_to.repopath("main"))

+         repo_to_obj.set_head(repo_from_obj.lookup_reference("HEAD").target)

+ 

          pagure.lib.notify.log(

              repo_to,

              topic="project.forked",

@@ -2798,6 +2798,58 @@ 

              )

              self.assertEqual(output.status_code, 200)

  

+     @patch("pagure.lib.notify.send_email", MagicMock(return_value=True))

+     def test_fork_project_non_master_default(self):

+         """ Test the fork_project endpoint with a project whose default branch

+         is not master. """

+ 

+         tests.create_projects(self.session)

+         for folder in ["docs", "tickets", "requests", "repos"]:

+             tests.create_projects_git(

+                 os.path.join(self.path, folder), bare=True

+             )

+         path = os.path.join(self.path, "repos", "test.git")

+         tests.add_content_git_repo(path)

+         project = pagure.lib.query.get_authorized_project(self.session, "test")

+ 

+         # Check before that the master branch is the default one - shown in the

+         # default page

+         output = self.app.get("/test")

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertIn(

+             '<code class="py-1 px-2 font-weight-bold commit_branch">master</code><code',

+             output_text,

+         )

+ 

+         # Create the main branch with some content and make it the default branch

+         repo = pygit2.Repository(path)

+         branchname = "main"

+         repo.create_branch(branchname, repo.head.peel())

+         pagure.lib.git.git_set_ref_head(project=project, branch=branchname)

+ 

+         user = tests.FakeUser(username="foo")

+         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)

+             output_text = output.get_data(as_text=True)

+             self.assertIn(

+                 '<code class="py-1 px-2 font-weight-bold commit_branch">main</code><code',

+                 output_text,

+             )

+ 

+         output = self.app.get("/fork/foo/test")

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertIn(

+             '<code class="py-1 px-2 font-weight-bold commit_branch">main</code><code',

+             output_text,

+         )

+ 

      @patch("pagure.lib.notify.send_email")

      def test_new_request_pull_branch_space(self, send_email):

          """ Test the new_request_pull endpoint. """

Otherwise we end up in weird situations where the default branch
differs between the two projects which ends up being quite confusing
to the users.

Fixes https://pagure.io/pagure/issue/5052

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

rebased onto 6153a3d3b4552fad5f90156653073ea025223b5f

3 years ago

rebased onto efa5eb4d40056b7cee9726f5452ce313db2020fe

3 years ago

rebased onto fcdb9606d3cb163df8f91958747d2d040852ef0c

3 years ago

LGTM from what I can tell

Also the api supports listing default branches, so we are set over there as well, I think we are good

rebased onto 24d0317

3 years ago

Pull-Request has been merged by pingou

3 years ago