Skip to content

Commit

Permalink
Merge pull request #435 from ACCESS-NRI/431-Recover-from-incomplete-c…
Browse files Browse the repository at this point in the history
…heckout

Recover from an incomplete checkout in payu clone #431
  • Loading branch information
jo-basevi committed Apr 10, 2024
2 parents 28d7744 + c98b0ad commit 91f2831
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion payu/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import warnings
from pathlib import Path
from typing import Optional
import shutil

from ruamel.yaml import YAML, CommentedMap
import git

from payu.fsops import read_config, DEFAULT_CONFIG_FNAME, list_archive_dirs
from payu.laboratory import Laboratory
from payu.metadata import Metadata, UUID_FIELD, METADATA_FILENAME
from payu.git_utils import GitRepository, git_clone
from payu.git_utils import GitRepository, git_clone, PayuBranchError


NO_CONFIG_FOUND_MESSAGE = """No configuration file found on this branch.
Expand Down Expand Up @@ -241,6 +242,13 @@ def clone(repository: str,
# Resolve directory to an absolute path
control_path = directory.resolve()

if control_path.exists():
raise PayuBranchError(
f"Directory path `{control_path}` already exists. "
"Clone to a different path, or cd into the existing directory " +
"and use `payu checkout` if it is the same git repository"
)

# git clone the repository
repo = git_clone(repository, control_path, branch)

Expand Down Expand Up @@ -275,6 +283,16 @@ def clone(repository: str,
lab_path=lab_path,
is_new_experiment=True,
parent_experiment=parent_experiment)
except PayuBranchError as e:
# Remove directory if incomplete checkout
shutil.rmtree(control_path)
msg = (
"Incomplete checkout. To run payu clone again, modify/remove " +
"the checkout new branch flag: --new-branch/-b, or " +
"checkout existing branch flag: --branch/-B " +
f"\n Checkout error: {e}"
)
raise PayuBranchError(msg)
finally:
# Change back to original working directory
os.chdir(owd)
Expand Down

0 comments on commit 91f2831

Please sign in to comment.