Skip to content
Merged
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
12 changes: 9 additions & 3 deletions update-pr-stack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ update_direct_target() {

if has_squash_commit "$BRANCH" "$TARGET_BRANCH"; then
echo "✓ $BRANCH already up-to-date; skipping"
return
return 0
fi

echo "Updating direct target $BRANCH (from $MERGED_BRANCH to $BASE_BRANCH)"
Expand Down Expand Up @@ -109,13 +109,16 @@ update_direct_target() {
# Create the label if it doesn't exist, then add it to the PR
gh label create "$CONFLICT_LABEL" --description "PR needs manual conflict resolution" --color "d73a4a" 2>/dev/null || true
log_cmd gh pr edit "$BRANCH" --add-label "$CONFLICT_LABEL"
return 1
else
log_cmd git merge --no-edit -s ours "$SQUASH_COMMIT"
log_cmd git update-ref MERGE_RESULT "HEAD^{tree}"
COMMIT_MSG="Merge updates from $BASE_BRANCH and squash commit"
CUSTOM_COMMIT=$(log_cmd git commit-tree MERGE_RESULT -p BEFORE_MERGE -p "origin/$MERGED_BRANCH" -p SQUASH_COMMIT -m "$COMMIT_MSG")
log_cmd git reset --hard "$CUSTOM_COMMIT"
fi

return 0
}

update_indirect_target() {
Expand Down Expand Up @@ -235,8 +238,11 @@ main() {
INITIAL_TARGETS=($(log_cmd gh pr list --base "$MERGED_BRANCH" --json headRefName --jq '.[].headRefName'))

for BRANCH in "${INITIAL_TARGETS[@]}"; do
update_direct_target "$BRANCH" "$TARGET_BRANCH"
update_branch_recursive "$BRANCH"
if update_direct_target "$BRANCH" "$TARGET_BRANCH"; then
update_branch_recursive "$BRANCH"
else
echo "⚠️ Skipping descendants of $BRANCH until conflicts are resolved"
fi
done

# Update base branches for direct target PRs
Expand Down