Skip to content

Commit

Permalink
fix: use --depth on git fetch for PRs (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspin committed Apr 22, 2024
1 parent 490c7c4 commit c730ad3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions libcheckout
Expand Up @@ -226,15 +226,24 @@ function checkout::refbased() {
retry git clone --depth "${SEMAPHORE_GIT_DEPTH}" "${SEMAPHORE_GIT_URL}" "${SEMAPHORE_GIT_DIR}"
cd "${SEMAPHORE_GIT_DIR}" || exit

if ! retry git fetch origin +"${SEMAPHORE_GIT_REF}": 2>/dev/null; then
echo "Revision: ${SEMAPHORE_GIT_SHA} not found .... Exiting"
return 1
else
# Try fetching refs/objects with a depth.
if retry git fetch --depth "${SEMAPHORE_GIT_DEPTH}" origin +"${SEMAPHORE_GIT_REF}": 2>/dev/null; then
git checkout -qf FETCH_HEAD
echo "HEAD is now at ${SEMAPHORE_GIT_SHA}"

return 0
fi

# Fetch with depth failed, fallback to not using a depth.
if retry git fetch origin +"${SEMAPHORE_GIT_REF}": 2>/dev/null; then
git checkout -qf FETCH_HEAD
echo "HEAD is now at ${SEMAPHORE_GIT_SHA}"

return 0
fi

echo "Revision: ${SEMAPHORE_GIT_SHA} not found .... Exiting"
return 1
fi

if [ "${SEMAPHORE_GIT_REF_TYPE:-""}" = "tag" ]; then
Expand Down

0 comments on commit c730ad3

Please sign in to comment.