Checkout: Destination path '.' already exists

git

#1

I’m experiencing consistent issues with checkout and workDir. Most recently, during checkout phase, I see the following:

set -e
mkdir -p ~/.ssh

echo '
<github-key>
' >> ~/.ssh/known_hosts

(umask 077; touch ~/.ssh/id_rsa)
chmod 0600 ~/.ssh/id_rsa
(cat <<EOF > ~/.ssh/id_rsa
$CHECKOUT_KEY
EOF
)

if [ -e /root/.git ]
then
  cd /root
else
  mkdir -p /root
  cd /root
  git clone $CIRCLE_REPOSITORY_URL .
fi

git fetch --force origin feature/branch-name:remotes/origin/feature/branch-name

git reset --hard $CIRCLE_SHA1
git checkout -q -B $CIRCLE_BRANCH
git reset --hard $CIRCLE_SHA1

fatal: destination path '.' already exists and is not an empty directory.
Exited with code 128

Circle.yml:

version: 2
executorType: docker
containerInfo:
  - image: ubuntu:14.04
    cmd: ["/bin/bash"] # specify if image does not already have Command set

stages:
  build:
    workDir: /root
    environment:
      PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${HOME}/.yarn/bin:/bin"
    steps:
      - type: shell
        shell: /bin/bash
        command: |
            apt-get -y update -qq
            # need to install git before checkout
            apt-get -y install git curl -qq

      - type: checkout

      - type: shell
        shell: /bin/bash
        command: |
            curl -sL https://deb.nodesource.com/setup_6.x | bash
            apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg
            echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
            apt-get -y update -qq
            apt-get -y install -qq nodejs yarn=0.18.1-1

I can run the local build successfully with circleci-builder build from the root of my project. Am I setting my workDir incorrectly? Is it possible to set workDir after checkout? I really just want the workDir to be the root of my own project. However, the directory obviously won’t exist until the project is checked out.

Appreciate any help.


#2

Don’t use /root as the workDir - specify a directory that does not yet exist.

That also means you will need to specify pwd: / (or similar) to run a step before checkout.


#3

Thank you, @rohara!


#4

Marking this as solved so that this thread is useful for others in the future. Let me know if Ryan’s post was not a complete solution.


#5