Search code examples
gitpython

Git.custom_environment not working for Repo.clone_from in docker


I have problem with using Git.custom_environment and Repo.clone_from methods. Running in a non-docker environment is successful and it fails to run under docker environment

gitpython version 3.1.9
python version 3.6.4
git version 2.24.3

mycode

Repo.clone_from(sourcecode, localpath, branch=branch, env=dict(GIT_SSH_COMMAND=git_ssh_cmd))

it's my fault or problem is the code?

Thank you.


Solution

  • I'm currently working on something similar to this. As far as I know, in a docker environment your git settings aren't initialized.

    Adding this snippet to the top of my dockerfile helped.

    RUN git config --global user.name "user"
    RUN git config --global user.email "user@email"
    

    Also make sure that when you clone you specify the ssh option -o "StrictHostKeyChecking=no" if you are using ssh.