问题
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.
来源:https://stackoverflow.com/questions/33343091/authentication-in-gitpython