1

I have a Docker image, which should pull the repo from git repository (hint about the token is taken from pretty similar question)

  1. If i use in Dockerfile

    RUN git clone https://TOKEN@github.com/company/project.git /folder

Then it works fine.

  1. If i try to put cloning process into the separate file: Dockerfile:

    CMD [ "/update.sh" ]

update.sh:

if [ -f /folder/.git ]; then
    git clone https://TOKEN@github.com/company/project.git /folder
else
    git -C /folder pull
fi

then i receive a very strange error:

fatal: Not a git repository (or any of the parent directories): .git

All answers that my google-fu was able to found was about "i'm receiving fatal: Not a git repository when running git pull" - which makes sense if you're pulling from the wrong directory. But in my case, git clone produces the "fatal: Not a git repository" error, which is super confusing.

Vitalii Vasylenko
  • 4,776
  • 5
  • 40
  • 64

1 Answers1

2

Two things:

  1. You need to use -d instead of -f because .git is a directory not a file
  2. You have your if and else clauses backwards. Right now you're trying to clone the git repository if .git exists when you actually want to clone it if .git doesn't exist.
Powerlord
  • 87,612
  • 17
  • 125
  • 175