Addon Manager: Complete migration away from GitPython

This commit is contained in:
Chris Hennes
2024-01-27 08:46:33 -06:00
committed by Chris Hennes
parent f301b763f6
commit c622e6ca42
4 changed files with 176 additions and 141 deletions

View File

@@ -34,19 +34,10 @@ import addonmanager_utilities as utils
from addonmanager_metadata import Version, UrlType, get_first_supported_freecad_version
from addonmanager_workers_startup import GetMacroDetailsWorker, CheckSingleUpdateWorker
from addonmanager_readme_viewer import ReadmeViewer
from addonmanager_git import GitManager, NoGitFound, GitFailed
from Addon import Addon
from change_branch import ChangeBranchDialog
have_git = False
try:
import git
if hasattr(git, "Repo"):
have_git = True
except ImportError:
git = None
translate = fci.translate
@@ -70,6 +61,10 @@ class PackageDetails(QtWidgets.QWidget):
self.worker = None
self.repo = None
self.status_update_thread = None
try:
self.git_manager = GitManager()
except NoGitFound:
self.git_manager = None
self.ui.buttonBack.clicked.connect(self.back.emit)
self.ui.buttonExecute.clicked.connect(lambda: self.execute.emit(self.repo))
@@ -183,14 +178,16 @@ class PackageDetails(QtWidgets.QWidget):
elif status == Addon.Status.NO_UPDATE_AVAILABLE:
detached_head = False
branch = repo.branch
if have_git and repo.repo_type != Addon.Kind.MACRO:
if self.git_manager and repo.repo_type != Addon.Kind.MACRO:
basedir = fci.getUserAppDataDir()
moddir = os.path.join(basedir, "Mod", repo.name)
if os.path.exists(os.path.join(moddir, ".git")):
gitrepo = git.Repo(moddir)
branch = gitrepo.head.ref.name
detached_head = gitrepo.head.is_detached
repo_path = os.path.join(moddir, ".git")
if os.path.exists(repo_path):
branch = self.git_manager.current_branch(repo_path)
if self.git_manager.detached_head(repo_path):
tag = self.git_manager.current_tag(repo_path)
branch = tag
detached_head = True
if detached_head:
installed_version_string += (
translate(
@@ -356,7 +353,7 @@ class PackageDetails(QtWidgets.QWidget):
return
# Can we actually switch branches? If not, return.
if not have_git:
if not self.git_manager:
return
# Is there a .git subdirectory? If not, return.
@@ -367,6 +364,7 @@ class PackageDetails(QtWidgets.QWidget):
# If all four above checks passed, then it's possible for us to switch
# branches, if there are any besides the one we are on: show the button
print("Showing the button")
self.ui.buttonChangeBranch.show()
def set_disable_button_state(self):