diff --git a/ci/run_conditional_tests.sh b/ci/run_conditional_tests.sh index 1f8affbc710e..36f2af877db7 100755 --- a/ci/run_conditional_tests.sh +++ b/ci/run_conditional_tests.sh @@ -54,7 +54,11 @@ elif [[ ${BUILD_TYPE} == "presubmit" ]]; then # For presubmit build, we want to know the difference from the # common commit in the target branch. if [ -n "${TARGET_BRANCH}" ]; then - git fetch origin "${TARGET_BRANCH}" --depth=200 || true + if [[ "${TEST_TYPE}" == "import_profile" ]]; then + git fetch origin "${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH}" || true + else + git fetch origin "${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH}" --depth=200 || true + fi fi GIT_DIFF_ARG="origin/${TARGET_BRANCH}..." diff --git a/ci/run_single_test.sh b/ci/run_single_test.sh index 16826476f26b..514cc5c2b16e 100755 --- a/ci/run_single_test.sh +++ b/ci/run_single_test.sh @@ -138,10 +138,14 @@ case ${TEST_TYPE} in BASELINE_CSV="${PROFILER_TEMP_DIR}/baseline_${PACKAGE_NAME}.csv" if [ -n "${TARGET_BRANCH}" ]; then - # Try upstream first (for forks), then origin - BASELINE_COMMIT=$(git merge-base HEAD "upstream/${TARGET_BRANCH}" 2>/dev/null || \ - git merge-base HEAD "origin/${TARGET_BRANCH}" 2>/dev/null || \ - git merge-base HEAD "${TARGET_BRANCH}" 2>/dev/null || true) + # Fetch history for the target branch without --depth=1 in case it was shallowly fetched + if [ -f "$(git rev-parse --git-dir)/shallow" ]; then + git fetch origin "${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH}" --unshallow 2>/dev/null || \ + git fetch origin "${TARGET_BRANCH}:refs/remotes/origin/${TARGET_BRANCH}" 2>/dev/null || true + fi + # Try origin first, then fallback to HEAD if everything else fails + BASELINE_COMMIT=$(git merge-base HEAD "origin/${TARGET_BRANCH}" 2>/dev/null || \ + git rev-parse HEAD) if [ -n "${BASELINE_COMMIT}" ]; then echo "Checking out baseline commit ${BASELINE_COMMIT} in a temporary worktree..." REPO_PREFIX=$(git rev-parse --show-prefix)