Skip to content

Commit 8ca4dbc

Browse files
author
Yuki Kobayashi
committed
Implement saving remaining backport branches to gitconfig
1 parent f872a12 commit 8ca4dbc

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

cherry_picker/cherry_picker.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ def remember_previous_branch(self):
165165
current_branch = get_current_branch()
166166
save_cfg_vals_to_git_cfg(previous_branch=current_branch)
167167

168+
def set_remaining_backports(self, branches):
169+
"""Save the remaining backport branches into Git config."""
170+
save_cfg_vals_to_git_cfg(remaining_backport=" ".join(branches))
171+
172+
def get_remaining_backports(self):
173+
"""Get the remaining backport branches from Git config."""
174+
branches = load_val_from_git_cfg("remaining_backport")
175+
if branches is None:
176+
return []
177+
return branches.split()
178+
179+
def pop_remaining_backports(self):
180+
"""Get one of the remaining backport branch and remove it."""
181+
branches = self.get_remaining_backports()
182+
branch = branches.pop(0)
183+
self.set_remaining_backports(branches)
184+
return branch
185+
168186
@property
169187
def upstream(self):
170188
"""Get the remote name to use for upstream branches
@@ -535,9 +553,14 @@ def backport(self):
535553
set_state(WORKFLOW_STATES.BACKPORT_STARTING)
536554
self.fetch_upstream()
537555
self.remember_previous_branch()
556+
self.set_remaining_backports(self.sorted_branches)
557+
self.process_remaining_backports()
558+
538559

560+
def process_remaining_backports(self):
539561
set_state(WORKFLOW_STATES.BACKPORT_LOOPING)
540-
for maint_branch in self.sorted_branches:
562+
while self.get_remaining_backports():
563+
maint_branch = self.pop_remaining_backports()
541564
set_state(WORKFLOW_STATES.BACKPORT_LOOP_START)
542565
click.echo(f"Now backporting '{self.commit_sha1}' into '{maint_branch}'")
543566

@@ -577,6 +600,7 @@ def backport(self):
577600
return # to preserve the correct state
578601
set_state(WORKFLOW_STATES.BACKPORT_LOOP_END)
579602
reset_stored_previous_branch()
603+
reset_stored_config_ref()
580604
reset_state()
581605

582606
def abort_cherry_pick(self):
@@ -669,16 +693,15 @@ def continue_cherry_pick(self):
669693
self.pause_after_committing(cherry_pick_branch)
670694
return # to preserve the correct state
671695

696+
self.process_remaining_backports()
697+
672698
else:
673699
click.echo(
674700
f"Current branch ({cherry_pick_branch}) is not a backport branch. "
675701
"Will not continue. \U0001F61B"
676702
)
677703
set_state(WORKFLOW_STATES.CONTINUATION_FAILED)
678704

679-
reset_stored_previous_branch()
680-
reset_stored_config_ref()
681-
reset_state()
682705

683706
def check_repo(self):
684707
"""

0 commit comments

Comments
 (0)