Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional error messaging to payu clone #431 #435

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading