Skip to content

Commit ed7fe50

Browse files
feat(tooling): Improve backporting script (#9638)
Fix remote detection Fix merge commit handling Improve script output
1 parent 836ba8d commit ed7fe50

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tooling/mirror-community-pull-request.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ gh --version 1>/dev/null 2>&1 || { echo "❌ gh is not installed. Please install
5454
# Check jq is installed
5555
jq --version 1>/dev/null 2>&1 || { echo "❌ jq is not installed. Please install jq."; exit 1; }
5656
# Check there are no local changes
57-
git diff --exit-code || { echo "❌ There are local changes. Please commit or stash them."; exit 1; }
57+
git diff --quiet --exit-code || { echo "❌ There are local changes. Please commit or stash them."; exit 1; }
5858

5959
#
6060
# Fetch PR information.
@@ -67,7 +67,7 @@ if [ -z "$PR_DATA" ]; then
6767
exit 1
6868
fi
6969
# Parse PR details
70-
FORK_REPO=$(echo "$PR_DATA" | jq -r '(.headRepository.nameWithOwner // (.headRepositoryOwner.login + "/" + .headRepository.name)) // empty')
70+
FORK_REPO=$(echo "$PR_DATA" | jq -r '(.headRepository.nameWithOwner | select(. != "" and . != null)) // (.headRepositoryOwner.login + "/" + .headRepository.name) // empty')
7171
FORK_BRANCH=$(echo "$PR_DATA" | jq -r '.headRefName // empty')
7272
PR_TITLE=$(echo "$PR_DATA" | jq -r '.title // empty')
7373
PR_AUTHOR=$(echo "$PR_DATA" | jq -r '.author.login // empty')
@@ -127,12 +127,12 @@ echo "- Cherry-picking and signing commits from PR"
127127
for COMMIT in $PR_COMMITS; do
128128
echo " - Cherry-picking $COMMIT"
129129
# Check if this is a merge commit
130-
CHERRY_PICK_ARGS="-S"
130+
CHERRY_PICK_ARGS=("-S")
131131
PARENT_COUNT=$(git rev-list --parents -n 1 "$COMMIT" 2>/dev/null | wc -w)
132132
if [ "$PARENT_COUNT" -gt 2 ]; then
133-
CHERRY_PICK_ARGS="$CHERRY_PICK_ARGS -m 1"
133+
CHERRY_PICK_ARGS+=("-m" "1")
134134
fi
135-
if ! git cherry-pick "$CHERRY_PICK_ARGS" "$COMMIT"; then
135+
if ! git cherry-pick "${CHERRY_PICK_ARGS[@]}" "$COMMIT"; then
136136
# Check if it's an empty commit
137137
if ! git diff --cached --quiet || ! git diff --quiet; then
138138
echo "❌ Failed to cherry-pick merge commit $COMMIT"

0 commit comments

Comments
 (0)