8000 Remove `initial_state` as it gets out of sync with what's in .git/con… · python/cherry-picker@b471da1 · GitHub
[go: up one dir, main page]

Skip to content

Commit b471da1

Browse files
authored
Remove initial_state as it gets out of sync with what's in .git/config (#88)
Run get_state_and_verify() as part of check_repo()
1 parent e4f927d commit b471da1

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

cherry_picker/cherry_picker.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ def __init__(
119119
self.config = config
120120
self.check_repo() # may raise InvalidRepoException
121121

122-
self.initial_state = self.get_state_and_verify()
123122
"""The runtime state loaded from the config.
124123
125124
Used to verify that we resume the process from the valid
@@ -540,9 +539,10 @@ def abort_cherry_pick(self):
540539
"""
541540
run `git cherry-pick --abort` and then clean up the branch
542541
"""
543-
if self.initial_state != WORKFLOW_STATES.BACKPORT_PAUSED:
542+
state = self.get_state_and_verify()
543+
if state != WORKFLOW_STATES.BACKPORT_PAUSED:
544544
raise ValueError(
545-
f"One can only abort a paused process. Current state: {self.initial_state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
545+
f"One can only abort a paused process. Current state: {state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
546546
)
547547

548548
try:
@@ -572,8 +572,11 @@ def continue_cherry_pick(self):
572572
open the PR
573573
clean up branch
574574
"""
575-
if self.initial_state != WORKFLOW_STATES.BACKPORT_PAUSED:
576-
raise ValueError("One can only continue a paused process.")
575+
state = self.get_state_and_verify()
576+
if state != WORKFLOW_STATES.BACKPORT_PAUSED:
577+
raise ValueError(
578+
f"One can only continue a paused process. Current state: {state}. Expected state: {WORKFLOW_STATES.BACKPORT_PAUSED}"
579+
)
577580

578581
cherry_pick_branch = get_current_branch()
579582
if cherry_pick_branch.startswith("backport-"):
@@ -637,8 +640,9 @@ def check_repo(self):
637640
"""
638641
try:
639642
validate_sha(self.config["check_sha"])
640-
except ValueError:
641-
raise InvalidRepoException()
643+
self.get_state_and_verify()
644+
except ValueError as ve:
645+
raise InvalidRepoException(ve.args[0])
642646

643647
def get_state_and_verify(self):
644648
"""Return the run progress state stored in the Git config.

cherry_picker/test_cherry_picker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ class tested_state:
862862
)
863863
with mock.patch(
864864
"cherry_picker.cherry_picker.validate_sha", return_value=True
865-
), pytest.raises(ValueError, match=expected_msg_regexp):
865+
), pytest.raises(InvalidRepoException, match=expected_msg_regexp):
866866
cherry_picker = CherryPicker("origin", "xxx", [])
867867

868868

0 commit comments

Comments
 (0)
0