Gitpython: Git.custom_environment not working for Repo.clone_from

Created on 19 Aug 2015  路  3Comments  路  Source: gitpython-developers/GitPython

Dear Sirs/Madams,

I have problem with using Git.custom_environment and Repo.clone_from methods.

My code:

ssh_cmd = 'ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i {}'.format(ssh_key_path)
with repo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd):
        repo.clone_from(url, dst_path, branch=branch})

_clone_from_ method not use custom ssh command.

it's my fault or problem is the code?

Thank you.

waiting for feedback

Most helpful comment

Hi Daniel,

The code you have been using doesn't work as clone_from is a class method. Thus it doesn't know the state of the configured Repo instance referred to by repo.

Instead what you could do is to use the env keyword parameter of clone_from such as in this example:

Repo.clone_from(url, dst_path, branch=branch, env=dict(GIT_SSH_COMMAND=ssh_cmd))

Last but not least, please be sure you are using git 2.3 or newer, as GIT_SSH_COMMAND was only recently introduced. Additional notes about the GIT_SSH_COMMAND environment variable can be found in the git-python docs.

I hope that helps !

All 3 comments

Hi Daniel,

The code you have been using doesn't work as clone_from is a class method. Thus it doesn't know the state of the configured Repo instance referred to by repo.

Instead what you could do is to use the env keyword parameter of clone_from such as in this example:

Repo.clone_from(url, dst_path, branch=branch, env=dict(GIT_SSH_COMMAND=ssh_cmd))

Last but not least, please be sure you are using git 2.3 or newer, as GIT_SSH_COMMAND was only recently introduced. Additional notes about the GIT_SSH_COMMAND environment variable can be found in the git-python docs.

I hope that helps !

You can watch the development stream on youtube.

_GitPython #20 [issue 339 - GIT_SSH_COMMAND and class-methods]_

thumb

This is awesome! Thank You for exhaustive response!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cool-RR picture cool-RR  路  4Comments

olethanh picture olethanh  路  6Comments

theckman picture theckman  路  6Comments

jon-armstrong picture jon-armstrong  路  7Comments

malford picture malford  路  3Comments