Skip to content

Commit

Permalink
Better error message when cherry_picker is called in wrong state (#119)
Browse files Browse the repository at this point in the history
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
  • Loading branch information
serhiy-storchaka and ambv authored Jan 15, 2025
1 parent 0a5c565 commit 014b2aa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
extend-ignore = C408,E203,F841,W503
max-complexity = 10
max-complexity = 12
max-line-length = 88
17 changes: 13 additions & 4 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,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 @@ -813,7 +817,7 @@ def cherry_pick_cli(
chosen_config_path=chosen_config_path,
)
except InvalidRepoException as ire:
click.echo(ire.args[0])
click.echo(ire.args[0], err=True)
sys.exit(-1)
except ValueError as exc:
ctx.fail(exc)
Expand Down Expand Up @@ -1015,7 +1019,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"))


def reset_stored_config_ref():
Expand Down

0 comments on commit 014b2aa

Please sign in to comment.