Skip to content

Commit

Permalink
fallback to fetch without depth
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaspin committed Apr 19, 2024
1 parent 9339563 commit b96f70b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions libcheckout
Original file line number Diff line number Diff line change
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 --depth "${SEMAPHORE_GIT_DEPTH}" 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 b96f70b

Please sign in to comment.