diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-08-08 18:49:47 +0000 |
---|---|---|
committer | AUTOMATIC1111 <16777216c@gmail.com> | 2023-08-08 18:49:47 +0000 |
commit | 54c3e5c913b17622bed4ff4d03df488b80611e21 (patch) | |
tree | 94f91922b3d0e6142837f6873ac9c12ba79d3f61 /modules/launch_utils.py | |
parent | 5a0db84b6c7322082c7532df11a29a95a59a612b (diff) | |
parent | 70c63c1208d33bf02e15c4e310bac83f12ee8625 (diff) | |
download | stable-diffusion-webui-gfx803-54c3e5c913b17622bed4ff4d03df488b80611e21.tar.gz stable-diffusion-webui-gfx803-54c3e5c913b17622bed4ff4d03df488b80611e21.tar.bz2 stable-diffusion-webui-gfx803-54c3e5c913b17622bed4ff4d03df488b80611e21.zip |
Merge branch 'dev' into refiner
Diffstat (limited to 'modules/launch_utils.py')
-rw-r--r-- | modules/launch_utils.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/modules/launch_utils.py b/modules/launch_utils.py index f77b577a..5be30a18 100644 --- a/modules/launch_utils.py +++ b/modules/launch_utils.py @@ -139,6 +139,27 @@ def check_run_python(code: str) -> bool: return result.returncode == 0
+def git_fix_workspace(dir, name):
+ run(f'"{git}" -C "{dir}" fetch --refetch --no-auto-gc', f"Fetching all contents for {name}", f"Couldn't fetch {name}", live=True)
+ run(f'"{git}" -C "{dir}" gc --aggressive --prune=now', f"Pruning {name}", f"Couldn't prune {name}", live=True)
+ return
+
+
+def run_git(dir, name, command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live, autofix=True):
+ try:
+ return run(f'"{git}" -C "{dir}" {command}', desc=desc, errdesc=errdesc, custom_env=custom_env, live=live)
+ except RuntimeError:
+ pass
+
+ if not autofix:
+ return None
+
+ print(f"{errdesc}, attempting autofix...")
+ git_fix_workspace(dir, name)
+
+ return run(f'"{git}" -C "{dir}" {command}', desc=desc, errdesc=errdesc, custom_env=custom_env, live=live)
+
+
def git_clone(url, dir, name, commithash=None):
# TODO clone into temporary dir and move if successful
@@ -146,12 +167,14 @@ def git_clone(url, dir, name, commithash=None): if commithash is None:
return
- current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}", live=False).strip()
+ current_hash = run_git(dir, name, 'rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}", live=False).strip()
if current_hash == commithash:
return
- run(f'"{git}" -C "{dir}" fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}")
- run(f'"{git}" -C "{dir}" checkout {commithash}', f"Checking out commit for {name} with hash: {commithash}...", f"Couldn't checkout commit {commithash} for {name}", live=True)
+ run_git('fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}")
+
+ run_git('checkout', f"Checking out commit for {name} with hash: {commithash}...", f"Couldn't checkout commit {commithash} for {name}", live=True)
+
return
run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}", live=True)
|