Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pulling from private repo #1489

Open
rogelioamancisidor opened this issue Sep 7, 2022 · 2 comments
Open

pulling from private repo #1489

rogelioamancisidor opened this issue Sep 7, 2022 · 2 comments

Comments

@rogelioamancisidor
Copy link

rogelioamancisidor commented Sep 7, 2022

I can clone from a private repo by specifying the path to he ssh key, like this:

git_dir = "git@github.com:user_id/repo_name.git"
save_at = './'
Repo.clone_from(git_dir, save_at, env={"GIT_SSH_COMMAND": 'ssh -o StrictHostKeyChecking=no  -i ./my_path/mykey'})

However, I this code cannot pull from the same private repo

repo = Repo(save_at)
ssh_cmd =  'ssh -o StrictHostKeyChecking=no  -i ./my_path/mykey'}
with repo.git.custom_environment(GIT_SSH_COMMAND=ssh_cmd):
    repo.remotes.origin.pull('master')

and throws the error

File "/usr/local/lib/python3.10/site-packages/git/remote.py", line 910, in pull
    res = self._get_fetch_info_from_stderr(proc, progress,
  File "/usr/local/lib/python3.10/site-packages/git/remote.py", line 750, in _get_fetch_info_from_stderr
    proc.wait(stderr=stderr_text)
  File "/usr/local/lib/python3.10/site-packages/git/cmd.py", line 502, in wait
    raise GitCommandError(remove_password_if_present(self.args), status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git pull -v origin master
  stderr: 'fatal: Could not read from remote repository.'

What am I missing here?

@Byron
Copy link
Member

Byron commented Sep 7, 2022

With the GIT_PYTHON_TRACE=1 and GIT_TRACE=1 environment variable set, you should see which commands are actually invoked and maybe get to the bottom of it.

Generally the approach of using GIT_SSH_COMMAND should work with custom_environment.

@rogelioamancisidor
Copy link
Author

rogelioamancisidor commented Sep 7, 2022

Can I set the environmental variables in the python code? My code runs in a kubernetes container so it will be to much of a trouble to declare those env variables in a secret so I can hopefully debug what is going on.

I updated the error message. Do you know what does GitCommandError(remove_password_if_present(self.args), status, errstr) mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants