Skip to content

Commit 014b2aa

Browse files
Better error message when cherry_picker is called in wrong state (#119)
Co-authored-by: Łukasz Langa <[email protected]>
1 parent 0a5c565 commit 014b2aa

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[flake8]
22
extend-ignore = C408,E203,F841,W503
3-
max-complexity = 10
3+
max-complexity = 12
44
max-line-length = 88

cherry_picker/cherry_picker.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,12 @@ def cherry_pick_cli(
798798

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

801-
chosen_config_path, config = load_config(config_path)
802-
801+
try:
802+
chosen_config_path, config = load_config(config_path)
803+
except ValueError as exc:
804+
click.echo("You're not inside a Git tree right now! \U0001F645", err=True)
805+
click.echo(exc, err=True)
806+
sys.exit(-1)
803807
try:
804808
cherry_picker = CherryPicker(
805809
pr_remote,
@@ -813,7 +817,7 @@ def cherry_pick_cli(
813817
chosen_config_path=chosen_config_path,
814818
)
815819
except InvalidRepoException as ire:
816-
click.echo(ire.args[0])
820+
click.echo(ire.args[0], err=True)
817821
sys.exit(-1)
818822
except ValueError as exc:
819823
ctx.fail(exc)
@@ -1015,7 +1019,12 @@ def load_config(path=None):
10151019
def get_sha1_from(commitish):
10161020
"""Turn 'commitish' into its sha1 hash."""
10171021
cmd = ["git", "rev-parse", commitish]
1018-
return subprocess.check_output(cmd).strip().decode("utf-8")
1022+
try:
1023+
return (
1024+
subprocess.check_output(cmd, stderr=subprocess.PIPE).strip().decode("utf-8")
1025+
)
1026+
except subprocess.CalledProcessError as exc:
1027+
raise ValueError(exc.stderr.strip().decode("utf-8"))
10191028

10201029

10211030
def reset_stored_config_ref():

0 commit comments

Comments
 (0)