1

I am trying to write a fairly simple function (I thought).

I want a user to specify a path to a checked out git repo on his computer. (A git repo that requires authentication).

I then want to do a git pull on that folder to grab any changes.

My code looks like this:

    import git
    repo=git.cmd.Git(GIT_PATH)
    repo.pull()

This works perfectly on my Linux machine, it never asks for any credentials (I am guessing because ssh-agent has already unlocked the key and supplies credentials when my script needs it).

On Windows however, I can't get it to to work. I have installed putty and added the key to pageant. I can check out the repo using TortoiseGit for example and it works perfectly fine, but if I execute the code above on the Windows machine, I get:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    repo = git.repo.base.Repo.clone_from(GIT_PATH, "t
mp")
  File "C:\Python34\lib\site-packages\git\repo\base.py", line 849, in clone_from

   return cls._clone(Git(os.getcwd()), url, to_path, GitCmdObjectDB, progress,
**kwargs)
  File "C:\Python34\lib\site-packages\git\repo\base.py", line 800, in _clone
    finalize_process(proc)
  File "C:\Python34\lib\site-packages\git\util.py", line 154, in finalize_proces
s
    proc.wait()
  File "C:\Python34\lib\site-packages\git\cmd.py", line 309, in wait
    raise GitCommandError(self.args, status, self.proc.stderr.read())
git.exc.GitCommandError: 'git clone -v ssh://git@git.path/repo tmp' re
turned with exit code 128
stderr: 'Cloning into 'tmp'...
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Edit: I would like to add that I am not married to GitPython. If anyone knows of another library that would solve my problem, that would work as well.

pskaa
  • 21
  • 1
  • 3
  • Is your public key the same on your windows and linux ? Is it accessible from python (correct perms) – Cyrbil Oct 26 '15 at 10:16
  • Yes it is the same key. I guess the "Is it accessible from python" part is what I am having problems with. I dont know how I can make it more accessible in Windows other than importing it to pageant – pskaa Oct 26 '15 at 10:20
  • try reading the key in a python shell. `print open('mykey.pub').read()`. To see if you have enough permissions. – Cyrbil Oct 26 '15 at 10:22
  • You mean private key, right? I mean that is the one I need to provide. Anyhow, I am able to open and read that file – pskaa Oct 26 '15 at 10:28
  • Ensure your key is correctly installed ? `ssh -vvT git@git` – Cyrbil Oct 26 '15 at 10:39
  • That is part of my problem I guess. The Window machines don't have an SSH command. Putty and it's pageant is all they got. But if I use a Git client, TortoiseGit for example, I am able to check out the git repository using the key. – pskaa Oct 26 '15 at 11:33
  • It seems like gitpython find a git binary (the output you are seeing comes from git). From what I saw it uses `GIT_PYTHON_GIT_EXECUTABLE` environment variable to get it. You can get the binary used by gitpython with `repo.GIT_PYTHON_GIT_EXECUTABLE`. Also notice that setting `git.Git.USE_SHELL=True` [might be required on windows](https://github.com/gitpython-developers/GitPython/blob/master/git/cmd.py#L255) – Cyrbil Oct 26 '15 at 13:03

0 Answers0