diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 5702b79..0199dcf 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -2512,6 +2512,18 @@ def new_git_branch( tempclone.push(username, branch, branch) +def git_set_ref_head(project, branch): + """ Set the HEAD reference of the project + :arg project: The project instance to set the HEAD reference + :arg branch: The branch to be set as HEAD reference + """ + repo_path = pagure.utils.get_repo_path(project) + repo_obj = PagureRepo(repo_path) + + reference = repo_obj.lookup_reference("refs/heads/%s" % branch).resolve() + repo_obj.set_head(reference.name) + + def delete_project_repos(project): """ Deletes the actual git repositories on disk or repoSpanner diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 88ca471..5630ad3 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -1631,10 +1631,7 @@ def change_ref_head(repo, username=None, namespace=None): if form.validate_on_submit(): branchname = form.branches.data try: - reference = repo_obj.lookup_reference( - "refs/heads/%s" % branchname - ).resolve() - repo_obj.set_head(reference.name) + pagure.lib.git.git_set_ref_head(project=repo, branch=branchname) flask.flash("Default branch updated to %s" % branchname) except Exception as err: # pragma: no cover _log.exception(err)