Add the ability to specify commit ID /tag or branch when installing nodes

This commit is contained in:
chenyijian 2024-12-24 19:07:27 +08:00
parent 171496c2ca
commit af114ecccc
2 changed files with 30 additions and 7 deletions

View File

@ -200,15 +200,22 @@ class Ctx:
cm_ctx = Ctx() cm_ctx = Ctx()
def parse_node(node: str):
if '@@' in node:
name, commit = node.split('@@', 1)
else:
name, commit = node, None
return name, commit
def install_node(node_name, is_all=False, cnt_msg=''): def install_node(node_name, is_all=False, cnt_msg=''):
node_name, commit_id = parse_node(node_name)
if core.is_valid_url(node_name): if core.is_valid_url(node_name):
# install via urls # install via urls
res = core.gitclone_install([node_name]) res = core.gitclone_install([node_name],commits = [commit_id])
if not res: if not res:
print(f"[bold red]ERROR: An error occurred while installing '{node_name}'.[/bold red]") print(f"[bold red]ERROR: An error occurred while installing '{node_name}'.[/bold red]")
else: else:
print(f"{cnt_msg} [INSTALLED] {node_name:50}") print(f"{cnt_msg} [INSTALLED] {node_name:50} => {commit_id}")
else: else:
node_path, node_item = cm_ctx.lookup_node_path(node_name) node_path, node_item = cm_ctx.lookup_node_path(node_name)
@ -218,11 +225,11 @@ def install_node(node_name, is_all=False, cnt_msg=''):
elif os.path.exists(node_path + '.disabled'): elif os.path.exists(node_path + '.disabled'):
enable_node(node_name) enable_node(node_name)
else: else:
res = core.gitclone_install(node_item['files'], instant_execution=True, msg_prefix=f"[{cnt_msg}] ") res = core.gitclone_install(node_item['files'], instant_execution=True, msg_prefix=f"[{cnt_msg}] ", commits=[commit_id])
if not res: if not res:
print(f"[bold red]ERROR: An error occurred while installing '{node_name}'.[/bold red]") print(f"[bold red]ERROR: An error occurred while installing '{node_name}'.[/bold red]")
else: else:
print(f"{cnt_msg} [INSTALLED] {node_name:50}") print(f"{cnt_msg} [INSTALLED] {node_name:50} => {commit_id}")
def reinstall_node(node_name, is_all=False, cnt_msg=''): def reinstall_node(node_name, is_all=False, cnt_msg=''):

View File

@ -584,9 +584,16 @@ def is_valid_url(url):
return False return False
def gitclone_install(files, instant_execution=False, msg_prefix=''): def gitclone_install(files, instant_execution=False, msg_prefix='', commits=None):
print(f"{msg_prefix}Install: {files}") print(f"{msg_prefix}Install: {files}:{commits}")
for url in files: if commits is None:
commits = [None] * len(files)
if len(files) != len(commits):
print("Error: The number of files and commit IDs must match.")
return False
for url, commit_id in zip(files, commits):
if not is_valid_url(url): if not is_valid_url(url):
print(f"Invalid git url: '{url}'") print(f"Invalid git url: '{url}'")
return False return False
@ -605,6 +612,15 @@ def gitclone_install(files, instant_execution=False, msg_prefix=''):
return False return False
else: else:
repo = git.Repo.clone_from(url, repo_path, recursive=True, progress=GitProgress()) repo = git.Repo.clone_from(url, repo_path, recursive=True, progress=GitProgress())
if commit_id:
print(f"Checkout commit: {commit_id}")
try:
# Try checking out as a commit, branch, or tag
repo.git.checkout(commit_id)
except Exception as checkout_error:
print(f"Error checking out {commit_id}: {checkout_error}")
return False
repo.git.clear_cache() repo.git.clear_cache()
repo.close() repo.close()