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.
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]_
This is awesome! Thank You for exhaustive response!
Most helpful comment
Hi Daniel,
The code you have been using doesn't work as
clone_fromis a class method. Thus it doesn't know the state of the configuredRepoinstance referred to byrepo.Instead what you could do is to use the
envkeyword parameter ofclone_fromsuch as in this example:Last but not least, please be sure you are using git 2.3 or newer, as
GIT_SSH_COMMANDwas only recently introduced. Additional notes about theGIT_SSH_COMMANDenvironment variable can be found in the git-python docs.I hope that helps !