diff options
author | Jabasukuriputo Wang <wfjsw@users.noreply.github.com> | 2023-08-01 03:20:59 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-01 03:20:59 +0000 |
commit | 2f1d5b6b04fd38b1fca1b0193b800533398d91ca (patch) | |
tree | 7b04937b8d4f95a11d76617711eb4a25fb915a94 /modules/launch_utils.py | |
parent | c10633f93a646b06f62bf1b24adba52f539dd6b6 (diff) | |
download | stable-diffusion-webui-gfx803-2f1d5b6b04fd38b1fca1b0193b800533398d91ca.tar.gz stable-diffusion-webui-gfx803-2f1d5b6b04fd38b1fca1b0193b800533398d91ca.tar.bz2 stable-diffusion-webui-gfx803-2f1d5b6b04fd38b1fca1b0193b800533398d91ca.zip |
attempt to fix workspace status when doing git clone
Diffstat (limited to 'modules/launch_utils.py')
-rw-r--r-- | modules/launch_utils.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/modules/launch_utils.py b/modules/launch_utils.py index f77b577a..c7bb9370 100644 --- a/modules/launch_utils.py +++ b/modules/launch_utils.py @@ -139,6 +139,12 @@ def check_run_python(code: str) -> bool: return result.returncode == 0
+def git_fix_workspace(dir):
+ 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 git_clone(url, dir, name, commithash=None):
# TODO clone into temporary dir and move if successful
@@ -151,7 +157,23 @@ def git_clone(url, dir, name, commithash=None): 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)
+
+ if commithash is not None:
+ try:
+ 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)
+ except RuntimeError:
+ print(f"Unable to checkout {name} with hash {commithash}, attempting autofix...")
+ git_fix_workspace(dir)
+ 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)
+ else:
+ try:
+ run(f'"{git}" -C "{dir}" reset --hard FETCH_HEAD', f"Checking out latest commit for {name}...", f"Couldn't checkout latest commit for {name}", live=True)
+ except RuntimeError:
+ print(f"Unable to checkout {name}, attempting autofix...")
+ git_fix_workspace(dir)
+ run(f'"{git}" -C "{dir}" reset --hard FETCH_HEAD', f"Checking out latest commit for {name}...", f"Couldn't checkout latest commit for {name}", live=True)
+
+
return
run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}", live=True)
|