Skip to content

Commit 8113ae0

Browse files
committed
esp/ci: Automatically skip 'already applied' commits from release branch when sycning
1 parent dd74b6c commit 8113ae0

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

llvm/utils/git/cherry-pick-range.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,36 @@ def _git_cherry_pick_continue_no_editor(repo: Any) -> None:
159159
os.environ[k] = v
160160

161161

162+
def _has_staged_changes(repo: Any) -> bool:
163+
"""Return True if the index has staged changes relative to HEAD."""
164+
try:
165+
repo.git.diff("--cached", "--quiet")
166+
return False
167+
except GitCommandError:
168+
return True
169+
170+
162171
def _wip_br_finish(
163172
repo: Any,
164173
failed_full_hash: str,
165174
dest_base_short: str,
166175
sync_tag_target_short: str,
167-
) -> str:
168-
"""Complete WIP pick, create sync_fail branch at HEAD, then drop that commit on current branch."""
176+
) -> str | None:
177+
"""Complete WIP pick, create sync_fail branch at HEAD, then drop that commit on current branch.
178+
179+
If staging leaves nothing to commit, skip the cherry-pick and return None so the caller
180+
can advance the sync tag and continue with remaining commits.
181+
"""
169182
if repo.working_tree_dir is None:
170183
_die("bare repository: --wip-br is not supported")
171184
repo.git.add("-u")
185+
if not _has_staged_changes(repo):
186+
try:
187+
repo.git.cherry_pick("--skip")
188+
except GitCommandError as e:
189+
_print_git_command_error(e)
190+
_die("git cherry-pick --skip failed after empty staged index")
191+
return None
172192
try:
173193
_git_cherry_pick_continue_no_editor(repo)
174194
except GitCommandError as e:
@@ -404,10 +424,18 @@ def main() -> None:
404424
args.wip_br
405425
and _cherry_pick_in_progress(repo)
406426
):
407-
_write_failed_pick_head(repo, commit)
408427
wip = _wip_br_finish(
409428
repo, commit, dest_base_short, sync_tag_target_short
410429
)
430+
if wip is None:
431+
print(
432+
f"cherry-pick of {commit[:12]} produced no staged changes after "
433+
f"git add -u; skipped commit and continuing.",
434+
)
435+
picked_count += 1
436+
_advance_sync_tag(repo, tag, commit)
437+
continue
438+
_write_failed_pick_head(repo, commit)
411439
print(
412440
f"Created WIP branch {wip!r} (it keeps the conflict cherry-pick). "
413441
f"Removed that commit from the current branch (git reset --hard HEAD~1). "

0 commit comments

Comments
 (0)