Addon Manager: Allow primary branch name change

This commit is contained in:
Chris Hennes
2024-01-30 14:25:08 +01:00
committed by Chris Hennes
parent 430b6c75cb
commit 39043cf176
8 changed files with 117 additions and 31 deletions

View File

@@ -387,6 +387,30 @@ class GitManager:
result_dict[author]["count"] += 1
return result_dict
def migrate_branch(self, local_path: str, old_branch: str, new_branch: str) -> None:
"""Rename a branch (used when the remote branch name changed). Assumes that "origin"
exists."""
old_dir = os.getcwd()
os.chdir(local_path)
try:
self._synchronous_call_git(["branch", "-m", old_branch, new_branch])
self._synchronous_call_git(["fetch", "origin"])
self._synchronous_call_git(["branch", "--unset-upstream"])
self._synchronous_call_git(["branch", f"--set-upstream-to=origin/{new_branch}"])
self._synchronous_call_git(["pull"])
except GitFailed as e:
fci.Console.PrintWarning(
translate(
"AddonsInstaller",
"Git branch rename failed with the following message:",
)
+ str(e)
+ "\n"
)
os.chdir(old_dir)
raise e
os.chdir(old_dir)
def _find_git(self):
# Find git. In preference order
# A) The value of the GitExecutable user preference