From 6ab049381a5dd6cba58c76e2cb525787421eb3ec Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Sun, 24 May 2026 20:03:23 -0700 Subject: [PATCH] jenkins: fetch refs before test commit rebase Refresh the PR ref and rebase target before checking out the Jenkins local branch. When REBASE_ONTO exists locally without its parents, git can replay almost the entire Node.js history instead of only the PR commits. Fixes: https://github.com/nodejs/build/issues/4345 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 --- jenkins/scripts/node-test-commit-pre.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/jenkins/scripts/node-test-commit-pre.sh b/jenkins/scripts/node-test-commit-pre.sh index 6c408672f..1816cab36 100755 --- a/jenkins/scripts/node-test-commit-pre.sh +++ b/jenkins/scripts/node-test-commit-pre.sh @@ -17,6 +17,27 @@ echo $GIT_COMMITTER_NAME echo $GIT_AUTHOR_NAME git rebase --abort || true + +# Refresh the refs used below in case the Jenkins checkout left a stale or +# shallow copy. If REBASE_ONTO is present locally without its parents, rebase +# can replay almost the entire Node.js history instead of only the PR commits. +fetch_from_origin() { + fetch_args="--no-tags" + if [ -f "$(git rev-parse --git-dir)/shallow" ]; then + fetch_args="${fetch_args} --unshallow" + fi + + git fetch ${fetch_args} origin "$@" +} + +if [ -n "${GIT_REMOTE_REF}" ]; then + fetch_from_origin "+${GIT_REMOTE_REF}:refs/remotes/origin/_jenkins_local_branch" +fi + +if [ -n "${REBASE_ONTO}" ]; then + fetch_from_origin "${REBASE_ONTO}" +fi + git checkout -f refs/remotes/origin/_jenkins_local_branch git config user.name git config user.email