Skip to content

Commit

Permalink
Merge pull request #7451 from nsoranzo/fix_circleci_PRs
Browse files Browse the repository at this point in the history
Fix shallow clone on CircleCI for PRs
  • Loading branch information
martenson committed Mar 4, 2019
2 parents d359c70 + c2c73f6 commit a5ff4ea
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,39 @@ jobs:
' >> ~/.ssh/known_hosts
# add the user ssh key and set correct perms
umask 077
echo "$CHECKOUT_KEY" > ~/.ssh/id_rsa
(umask 077; touch ~/.ssh/id_rsa)
chmod 0600 ~/.ssh/id_rsa
echo "$CHECKOUT_KEY" > ~/.ssh/id_rsa
# use git+ssh instead of https
git config --global url."ssh://git@github.com".insteadOf "https://github.com" || true
git config --global gc.auto 0 || true
# get shallow clone of single repo branch for speed purposes
git clone --depth=1 --single-branch -b $CIRCLE_BRANCH git@github.com:$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME ~/repo
# Shallow clone
git clone --depth=1 "${CIRCLE_REPOSITORY_URL}" .
if [ -n "$CIRCLE_TAG" ]
then
git fetch --depth=10 --force origin "refs/tags/${CIRCLE_TAG}"
elif [[ "$CIRCLE_BRANCH" =~ ^pull\/* ]]
then
# For PR from Fork
git fetch --depth=10 --force origin "$CIRCLE_BRANCH/head:remotes/origin/$CIRCLE_BRANCH"
else
git fetch --depth=10 --force origin "$CIRCLE_BRANCH:remotes/origin/$CIRCLE_BRANCH"
fi
if [ -n "$CIRCLE_TAG" ]
then
git reset --hard "$CIRCLE_SHA1"
git checkout -q "$CIRCLE_TAG"
elif [ -n "$CIRCLE_BRANCH" ]
then
git reset --hard "$CIRCLE_SHA1"
git checkout -q -B "$CIRCLE_BRANCH"
fi
git reset --hard "${CIRCLE_SHA1}"
- save_cache:
key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
paths:
Expand Down

0 comments on commit a5ff4ea

Please sign in to comment.