Skip to content

Commit

Permalink
Better error message when cherry_picker is called in wrong state
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Feb 13, 2024
1 parent 19634f2 commit b199f43
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,12 @@ def cherry_pick_cli(

click.echo("\U0001F40D \U0001F352 \u26CF")

chosen_config_path, config = load_config(config_path)

try:
chosen_config_path, config = load_config(config_path)
except ValueError as exc:
click.echo("You're not inside a Git tree right now! \U0001F645", err=True)
click.echo(exc, err=True)
sys.exit(-1)
try:
cherry_picker = CherryPicker(
pr_remote,
Expand All @@ -808,8 +812,11 @@ def cherry_pick_cli(
config=config,
chosen_config_path=chosen_config_path,
)
except InvalidRepoException:
click.echo(f"You're not inside a {config['repo']} repo right now! \U0001F645")
except InvalidRepoException as exc:
click.echo(
f"You're not inside a {config['repo']} repo right now! \U0001F645", err=True
)
click.echo(exc, err=True)
sys.exit(-1)
except ValueError as exc:
ctx.fail(exc)
Expand Down Expand Up @@ -994,7 +1001,12 @@ def load_config(path=None):
def get_sha1_from(commitish):
"""Turn 'commitish' into its sha1 hash."""
cmd = ["git", "rev-parse", commitish]
return subprocess.check_output(cmd).strip().decode("utf-8")
try:
return (
subprocess.check_output(cmd, stderr=subprocess.PIPE).strip().decode("utf-8")
)
except subprocess.CalledProcessError as exc:
raise ValueError(exc.stderr.strip().decode("utf-8"))

Check warning on line 1009 in cherry_picker/cherry_picker.py

View check run for this annotation

Codecov / codecov/patch

cherry_picker/cherry_picker.py#L1008-L1009

Added lines #L1008 - L1009 were not covered by tests


def reset_stored_config_ref():
Expand Down

0 comments on commit b199f43

Please sign in to comment.