#5060 Allow to specify a default branch for all projects hosted on an instance
Merged 3 years ago by pingou. Opened 3 years ago by pingou.

file modified
+21 -8
@@ -1909,8 +1909,27 @@ 

  When set to ``False``, this essentially makes the API ignore whether the

  ``force`` argument is set or not.

  

+ Defaults to: ``True``

+ 

+ 

+ PAGURE_PLUGINS_CONFIG

+ ~~~~~~~~~~~~~~~~~~~~~~

+ 

+ This option can be used to specify the configuration file used for loading

+ plugins. It is not set by default, instead if must be declared explicitly.

+ Also see the documentation on plugins at :ref:`plugins`.

+ 

+ 

+ GIT_DEFAULT_BRANCH

+ ~~~~~~~~~~~~~~~~~~

+ 

+ This configuration key allows to specify the default branch configured upon

+ project creation. The default branch can be specified by the user upon project

+ creation but if the user does not specify any branch, this branch name will be

+ used.

+ 

+ Defaults to: ``None`` (which results in the default branch being ``master``).

  

- Default to: ``True``

  

  

  RepoSpanner Options
@@ -2058,6 +2077,7 @@ 

  The command to run if a repository is not on repospanner when aclchecker is in use.

  

  

+ 

  MQTT Options

  ------------

  
@@ -2178,13 +2198,6 @@ 

  Defaults to: ``False``.

  

  

- PAGURE_PLUGINS_CONFIG

- ~~~~~~~~~~~~~~~~~~~~~~

- 

- This option can be used to specify the configuration file used for loading

- plugins. It is not set by default, instead if must be declared explicitly.

- Also see the documentation on plugins at :ref:`plugins`.

- 

  

  Deprecated configuration keys

  -----------------------------

file modified
+1 -1
@@ -1738,7 +1738,7 @@ 

          name,

          add_readme,

          ignore_existing_repo,

-         default_branch,

+         default_branch or pagure_config.get("GIT_DEFAULT_BRANCH"),

      )

  

  

@@ -2517,6 +2517,89 @@ 

          repo = pygit2.Repository(projects[0].repopath("main"))

          self.assertEqual(repo.listall_branches(), ["main"])

  

+     @patch.dict("pagure.config.config", {"GIT_DEFAULT_BRANCH": "main"})

+     def test_new_project_with_default_branch_instance_wide(self):

+         """ Test the new_project endpoint when new project contains a plus sign.

+         """

+         # Before

+         projects = pagure.lib.query.search_projects(self.session)

+         self.assertEqual(len(projects), 0)

+ 

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

+         with tests.user_set(self.app.application, user):

+             csrf_token = self.get_csrf()

+ 

+             data = {

+                 "description": "Project #1.",

+                 "name": "project_main",

+                 "csrf_token": csrf_token,

+                 "create_readme": True,

+             }

+             output = self.app.post("/new/", data=data, follow_redirects=True)

+             self.assertEqual(output.status_code, 200)

+             output_text = output.get_data(as_text=True)

+             self.assertIn(

+                 "<title>Overview - project_main - Pagure</title>", output_text

+             )

+             self.assertIn(

+                 '<a href="/project_main"><strong>project_main</strong></a>',

+                 output_text,

+             )

+             self.assertIn(

+                 '<code class="py-1 px-2 font-weight-bold '

+                 'commit_branch">main</code>',

+                 output_text,

+             )

+ 

+         # After

+         projects = pagure.lib.query.search_projects(self.session)

+         self.assertEqual(len(projects), 1)

+ 

+         repo = pygit2.Repository(projects[0].repopath("main"))

+         self.assertEqual(repo.listall_branches(), ["main"])

+ 

+     @patch.dict("pagure.config.config", {"GIT_DEFAULT_BRANCH": "main"})

+     def test_new_project_with_default_branch_instance_wide_overriden(self):

+         """ Test the new_project endpoint when new project contains a plus sign.

+         """

+         # Before

+         projects = pagure.lib.query.search_projects(self.session)

+         self.assertEqual(len(projects), 0)

+ 

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

+         with tests.user_set(self.app.application, user):

+             csrf_token = self.get_csrf()

+ 

+             data = {

+                 "description": "Project #1.",

+                 "name": "project_main",

+                 "csrf_token": csrf_token,

+                 "default_branch": "rawhide",

+                 "create_readme": True,

+             }

+             output = self.app.post("/new/", data=data, follow_redirects=True)

+             self.assertEqual(output.status_code, 200)

+             output_text = output.get_data(as_text=True)

+             self.assertIn(

+                 "<title>Overview - project_main - Pagure</title>", output_text

+             )

+             self.assertIn(

+                 '<a href="/project_main"><strong>project_main</strong></a>',

+                 output_text,

+             )

+             self.assertIn(

+                 '<code class="py-1 px-2 font-weight-bold '

+                 'commit_branch">rawhide</code>',

+                 output_text,

+             )

+ 

+         # After

+         projects = pagure.lib.query.search_projects(self.session)

+         self.assertEqual(len(projects), 1)

+ 

+         repo = pygit2.Repository(projects[0].repopath("main"))

+         self.assertEqual(repo.listall_branches(), ["rawhide"])

+ 

      def test_new_project_when_turned_off(self):

          """ Test the new_project endpoint when new project creation is

          not allowed in the pagure instance. """

no initial comment

rebased onto 27abe6060f5ee3619fb5b91b58e3e14f81ad6fcc

3 years ago

rebased onto 27abe6060f5ee3619fb5b91b58e3e14f81ad6fcc

3 years ago

rebased onto aa8dfb1

3 years ago

Pull-Request has been merged by pingou

3 years ago