@@ -106,9 +106,24 @@ jobs:
106106 return;
107107 }
108108
109+ // Get the number of commits in the PR
110+ // Note: per_page: 250 should be sufficient for most PRs
111+ // PRs with more than 250 commits will need manual rebasing
112+ const { data: commits } = await github.rest.pulls.listCommits({
113+ owner: context.repo.owner,
114+ repo: context.repo.repo,
115+ pull_number: context.issue.number,
116+ per_page: 250
117+ });
118+
119+ if (commits.length === 250) {
120+ core.warning('PR has 250 or more commits. The rebase may not work correctly for very large PRs.');
121+ }
122+
109123 core.setOutput('head_ref', pr.head.ref);
110124 core.setOutput('head_repo', pr.head.repo.full_name);
111125 core.setOutput('head_sha', pr.head.sha);
126+ core.setOutput('commit_count', commits.length);
112127
113128 - name : Checkout PR branch
114129 if : steps.check-auth.outputs.result == 'true'
@@ -137,20 +152,19 @@ jobs:
137152 set +e
138153 git remote add upstream https://github.com/eclipse-jdt/eclipse.jdt.debug.git
139154 git fetch upstream master
140- git fetch origin master
141155
142- # Find the merge-base between current branch and origin/master
143- FORK_POINT=$(git merge-base HEAD origin/master)
144- echo "Fork point: $FORK_POINT "
156+ # Get the number of commits in this PR from GitHub API
157+ PR_COMMIT_COUNT=${{ steps.pr-info.outputs.commit_count }}
158+ echo "PR has $PR_COMMIT_COUNT commits "
145159
146160 # Get current branch name
147161 CURRENT_BRANCH=$(git branch --show-current)
148162 echo "Current branch: $CURRENT_BRANCH"
149163
150- echo "Rebasing only PR commits onto upstream/master..."
151- # Use --onto to rebase only commits after the fork point
152- # This excludes fork-specific commits that are in origin/master
153- git rebase --onto upstream/master "$FORK_POINT" "$CURRENT_BRANCH"
164+ echo "Rebasing only the $PR_COMMIT_COUNT PR commits onto upstream/master..."
165+ # Rebase only the last N commits ( the actual PR commits) onto upstream/master
166+ # This excludes all fork-specific commits that came before the PR branch was created
167+ git rebase --onto upstream/master HEAD~${PR_COMMIT_COUNT}
154168 REBASE_EXIT_CODE=$?
155169
156170 if [ $REBASE_EXIT_CODE -ne 0 ]; then
@@ -218,14 +232,14 @@ jobs:
218232 \`\`\`bash
219233 git remote add upstream https://github.com/eclipse-jdt/eclipse.jdt.debug.git
220234 git fetch upstream master
221- git fetch origin master
222235
223- # Find the fork point (where your branch diverged from origin/master)
224- FORK_POINT=$(git merge-base HEAD origin/master)
236+ # Determine the number of commits in your PR
237+ # You can find this on the PR page under "Commits" tab
238+ # Example: if your PR has 3 commits, set PR_COMMIT_COUNT=3
239+ PR_COMMIT_COUNT=3
225240
226- # Rebase only your PR commits onto upstream/master (excluding fork commits)
227- # The third argument (HEAD) specifies to rebase everything from FORK_POINT to HEAD
228- git rebase --onto upstream/master $FORK_POINT HEAD
241+ # Rebase only your PR commits onto upstream/master
242+ git rebase --onto upstream/master HEAD~\${PR_COMMIT_COUNT}
229243
230244 # Resolve conflicts if any
231245 git rebase --continue
@@ -267,14 +281,14 @@ jobs:
267281 \`\`\`bash
268282 git remote add upstream https://github.com/eclipse-jdt/eclipse.jdt.debug.git
269283 git fetch upstream master
270- git fetch origin master
271284
272- # Find the fork point (where your branch diverged from origin/master)
273- FORK_POINT=$(git merge-base HEAD origin/master)
285+ # Determine the number of commits in your PR
286+ # You can find this on the PR page under "Commits" tab
287+ # Example: if your PR has 3 commits, set PR_COMMIT_COUNT=3
288+ PR_COMMIT_COUNT=3
274289
275- # Rebase only your PR commits onto upstream/master (excluding fork commits)
276- # The third argument (HEAD) specifies to rebase everything from FORK_POINT to HEAD
277- git rebase --onto upstream/master $FORK_POINT HEAD
290+ # Rebase only your PR commits onto upstream/master
291+ git rebase --onto upstream/master HEAD~\${PR_COMMIT_COUNT}
278292
279293 git push --force-with-lease
280294 \`\`\``;
0 commit comments