Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 11 additions & 7 deletions cherry_picker/cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def __init__(
self.config = config
self.check_repo() # may raise InvalidRepoException

self.initial_state = self.get_state_and_verify()
"""The runtime state loaded from the config.

Used to verify that we resume the process from the valid
Expand Down Expand Up @@ -540,9 +539,10 @@ def abort_cherry_pick(self):
"""
run `git cherry-pick --abort` and then clean up the branch
"""
if self.initial_state != WORKFLOW_STATES.BACKPORT_PAUSED:
state = self.get_state_and_verify()
if state != WORKFLOW_STATES.BACKPORT_PAUSED:
raise ValueError(
f"One can only abort a paused process. Current state: {self.initial_state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
f"One can only abort a paused process. Current state: {state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
)

try:
Expand Down Expand Up @@ -572,8 +572,11 @@ def continue_cherry_pick(self):
open the PR
clean up branch
"""
if self.initial_state != WORKFLOW_STATES.BACKPORT_PAUSED:
raise ValueError("One can only continue a paused process.")
state = self.get_state_and_verify()
if state != WORKFLOW_STATES.BACKPORT_PAUSED:
raise ValueError(
f"One can only continue a paused process. Current state: {state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
)

cherry_pick_branch = get_current_branch()
if cherry_pick_branch.startswith("backport-"):
Expand Down Expand Up @@ -637,8 +640,9 @@ def check_repo(self):
"""
try:
validate_sha(self.config["check_sha"])
except ValueError:
raise InvalidRepoException()
self.get_state_and_verify()
except ValueError as ve:
raise InvalidRepoException(ve.args[0])

def get_state_and_verify(self):
"""Return the run progress state stored in the Git config.
Expand Down
2 changes: 1 addition & 1 deletion cherry_picker/test_cherry_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ class tested_state:
)
with mock.patch(
"cherry_picker.cherry_picker.validate_sha", return_value=True
), pytest.raises(ValueError, match=expected_msg_regexp):
), pytest.raises(InvalidRepoException, match=expected_msg_regexp):
cherry_picker = CherryPicker("origin", "xxx", [])


Expand Down