This is an automated email from the ASF dual-hosted git repository.

gcruz pushed a commit to branch gc/8518
in repository https://gitbox.apache.org/repos/asf/allura.git


The following commit(s) were added to refs/heads/gc/8518 by this push:
     new 71983d643 [#8518] added background task that updates the head ref
71983d643 is described below

commit 71983d64327b72d86c4d6b4617b10271d1dc1e37
Author: Guillermo Cruz <[email protected]>
AuthorDate: Thu Aug 10 13:57:52 2023 -0600

    [#8518] added background task that updates the head ref
---
 Allura/allura/lib/repository.py     | 4 +---
 Allura/allura/tasks/repo_tasks.py   | 8 ++++++++
 ForgeGit/forgegit/model/git_repo.py | 3 ++-
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/Allura/allura/lib/repository.py b/Allura/allura/lib/repository.py
index 1ed396850..bd7bf0a6e 100644
--- a/Allura/allura/lib/repository.py
+++ b/Allura/allura/lib/repository.py
@@ -295,9 +295,7 @@ class RepoAdminController(DefaultAdminController):
     def set_default_branch_name(self, branch_name=None, **kw):
         if (request.method == 'POST') and branch_name:
             self.repo.set_default_branch(branch_name)
-            project_url = self.repo.default_url_path(c.project, 
self.app.config.tool_name)
-            mount_point = self.app.config.options.mount_point
-            redirect(six.ensure_text(f'{project_url}{mount_point}/' or '/'))
+            redirect(six.ensure_text(c.app.url))
         else:
             return dict(app=self.app,
                         default_branch_name=self.app.default_branch_name)
diff --git a/Allura/allura/tasks/repo_tasks.py 
b/Allura/allura/tasks/repo_tasks.py
index e38ea26e7..ea95f0979 100644
--- a/Allura/allura/tasks/repo_tasks.py
+++ b/Allura/allura/tasks/repo_tasks.py
@@ -25,6 +25,7 @@ from ming.odm import session
 from allura.lib.decorators import task
 from allura.lib.repository import RepositoryApp
 from allura.lib.utils import skip_mod_date
+import git
 
 
 @task
@@ -178,3 +179,10 @@ def determine_mr_commits(merge_request_id):
     from allura import model as M
     mr = M.MergeRequest.query.get(_id=merge_request_id)
     mr.commits  # build & cache the commits
+
+
+@task
+def update_head_reference(fs_path, branch_name):
+    git = git.Repo(fs_path, odbt=git.GitCmdObjectDB)
+    git.head.reference = branch_name
+
diff --git a/ForgeGit/forgegit/model/git_repo.py 
b/ForgeGit/forgegit/model/git_repo.py
index a143f6938..b0aa83e90 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -43,6 +43,7 @@ from ming.utils import LazyProperty
 from allura.lib import helpers as h
 from allura.model.repository import topological_sort, prefix_paths_union
 from allura import model as M
+import allura.tasks
 
 if typing.TYPE_CHECKING:
     from ming.odm.mapper import Query
@@ -636,7 +637,7 @@ class GitImplementation(M.RepositoryImplementation):
         if not name:
             return
         self._repo.default_branch_name = name
-        self._git.head.reference = name
+        
allura.tasks.repo_tasks.update_head_reference.post(self._repo.full_fs_path, 
name)
         session(self._repo).flush(self._repo)
 
     def _get_last_commit(self, commit_id, paths):

Reply via email to