Limit Jenkins fallback git checkouts

This commit is contained in:
2026-05-13 20:24:58 +08:00
parent be53a90f77
commit 2277b37888
9 changed files with 43 additions and 21 deletions

View File

@@ -51,7 +51,11 @@ fetch_source_branch() {
fi
echo "[jenkins-checkout-source] 尝试 Git 远端: ${remote_url:-origin}"
git fetch --tags --prune origin "+refs/heads/${SOURCE_BRANCH}:refs/remotes/origin/${SOURCE_BRANCH}"
if [[ -z "${COMMIT_HASH}" ]]; then
git fetch --no-tags --prune --depth=1 origin "+refs/heads/${SOURCE_BRANCH}:refs/remotes/origin/${SOURCE_BRANCH}"
else
git fetch --no-tags --prune origin "+refs/heads/${SOURCE_BRANCH}:refs/remotes/origin/${SOURCE_BRANCH}"
fi
}
add_git_remote_candidate "${GIT_REMOTE_URL}"
@@ -76,8 +80,8 @@ else
fi
fi
if [[ "$(git rev-parse --is-shallow-repository 2>/dev/null || echo false)" == "true" ]]; then
git fetch --unshallow --tags || true
if [[ -n "${COMMIT_HASH}" && "$(git rev-parse --is-shallow-repository 2>/dev/null || echo false)" == "true" ]]; then
git fetch --unshallow --no-tags origin "+refs/heads/${SOURCE_BRANCH}:refs/remotes/origin/${SOURCE_BRANCH}" || true
fi
git cat-file -e "refs/remotes/origin/${SOURCE_BRANCH}^{commit}"