@@ -118,20 +118,29 @@ case ${TEST_TYPE} in
118118 BASELINE_CSV=" ${PROFILER_TEMP_DIR} /baseline_${PACKAGE_NAME} .csv"
119119
120120 if [ -n " ${TARGET_BRANCH} " ]; then
121- # Suppress errors if branch isn't found
122- BASELINE_COMMIT=$( git merge-base HEAD " origin/${TARGET_BRANCH:- main} " 2> /dev/null || true)
121+ # Try upstream first (for forks), then origin
122+ BASELINE_COMMIT=$( git merge-base HEAD " upstream/${TARGET_BRANCH} " 2> /dev/null || \
123+ git merge-base HEAD " origin/${TARGET_BRANCH} " 2> /dev/null || \
124+ git merge-base HEAD " ${TARGET_BRANCH} " 2> /dev/null || true)
123125 if [ -n " ${BASELINE_COMMIT} " ]; then
124- echo " Checking out baseline commit ${BASELINE_COMMIT} ..."
125- git checkout ${BASELINE_COMMIT}
126- if [ -f setup.py ] || [ -f pyproject.toml ]; then
127- pip install -e .
128- python ${PROFILER_SCRIPT} --package ${PACKAGE_NAME} --iterations 11 --csv " ${BASELINE_CSV} "
126+ echo " Checking out baseline commit ${BASELINE_COMMIT} in a temporary worktree..."
127+ REPO_PREFIX=$( git rev-parse --show-prefix)
128+ WORKTREE_DIR=$( mktemp -d)
129+ rmdir " ${WORKTREE_DIR} "
130+ if git worktree add " ${WORKTREE_DIR} " " ${BASELINE_COMMIT} " 2> /dev/null; then
131+ (
132+ cd " ${WORKTREE_DIR} /${REPO_PREFIX} "
133+ if [ -f setup.py ] || [ -f pyproject.toml ]; then
134+ pip install -e .
135+ python " ${PROFILER_SCRIPT} " --package " ${PACKAGE_NAME} " --iterations 11 --csv " ${BASELINE_CSV} "
136+ fi
137+ )
138+ git worktree remove -f " ${WORKTREE_DIR} "
129139 else
130- echo " setup.py/pyproject.toml not found on baseline. Skipping baseline generation."
140+ echo " Failed to create git worktree for baseline. Skipping baseline generation."
131141 fi
132- git checkout -
133142 else
134- echo " Could not find baseline commit for origin/ ${TARGET_BRANCH:- main} . Skipping baseline generation."
143+ echo " Could not find baseline commit for ${TARGET_BRANCH:- main} . Skipping baseline generation."
135144 fi
136145 fi
137146
0 commit comments