mirror of
https://git.datalinker.icu/ltdrdata/ComfyUI-Manager
synced 2025-12-10 06:34:24 +08:00
Move to git_utils
This commit is contained in:
parent
4e44c26beb
commit
19be1f85da
@ -437,35 +437,6 @@ def setup_environment():
|
|||||||
git.Git().update_environment(GIT_PYTHON_GIT_EXECUTABLE=config['default']['git_exe'])
|
git.Git().update_environment(GIT_PYTHON_GIT_EXECUTABLE=config['default']['git_exe'])
|
||||||
|
|
||||||
|
|
||||||
def is_git_repo(path: str) -> bool:
|
|
||||||
""" Check if the path is a git repository. """
|
|
||||||
try:
|
|
||||||
# Try to create a Repo object from the path
|
|
||||||
_ = git.Repo(path).git_dir
|
|
||||||
return True
|
|
||||||
except git.exc.InvalidGitRepositoryError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def get_commit_hash(fullpath):
|
|
||||||
git_head = os.path.join(fullpath, '.git', 'HEAD')
|
|
||||||
if os.path.exists(git_head):
|
|
||||||
with open(git_head) as f:
|
|
||||||
line = f.readline()
|
|
||||||
|
|
||||||
if line.startswith("ref: "):
|
|
||||||
ref = os.path.join(fullpath, '.git', line[5:].strip())
|
|
||||||
if os.path.exists(ref):
|
|
||||||
with open(ref) as f2:
|
|
||||||
return f2.readline().strip()
|
|
||||||
else:
|
|
||||||
return "unknown"
|
|
||||||
else:
|
|
||||||
return line
|
|
||||||
|
|
||||||
return "unknown"
|
|
||||||
|
|
||||||
|
|
||||||
setup_environment()
|
setup_environment()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
32
glob/git_utils.py
Normal file
32
glob/git_utils.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import git
|
||||||
|
|
||||||
|
|
||||||
|
def is_git_repo(path: str) -> bool:
|
||||||
|
""" Check if the path is a git repository. """
|
||||||
|
try:
|
||||||
|
# Try to create a Repo object from the path
|
||||||
|
_ = git.Repo(path).git_dir
|
||||||
|
return True
|
||||||
|
except git.exc.InvalidGitRepositoryError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_commit_hash(fullpath):
|
||||||
|
git_head = os.path.join(fullpath, '.git', 'HEAD')
|
||||||
|
if os.path.exists(git_head):
|
||||||
|
with open(git_head) as f:
|
||||||
|
line = f.readline()
|
||||||
|
|
||||||
|
if line.startswith("ref: "):
|
||||||
|
ref = os.path.join(fullpath, '.git', line[5:].strip())
|
||||||
|
if os.path.exists(ref):
|
||||||
|
with open(ref) as f2:
|
||||||
|
return f2.readline().strip()
|
||||||
|
else:
|
||||||
|
return "unknown"
|
||||||
|
else:
|
||||||
|
return line
|
||||||
|
|
||||||
|
return "unknown"
|
||||||
@ -5,7 +5,7 @@ import os
|
|||||||
|
|
||||||
import toml
|
import toml
|
||||||
|
|
||||||
from git_helper import is_git_repo, get_commit_hash
|
from git_utils import is_git_repo, get_commit_hash
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user