使用gitPython推送到git时发生协议错误

问题描述 投票:0回答:1

我正在尝试在Windows上使用GitPython 3.0.3推送到远程git repo。我这样做:

repo = Repo(config['gitRepo'])
repo.git.add(A=True)
repo.index.commit("test")

with repo.git.custom_environment(GIT_SSH='F:\\nf\\rr.bat'):
    repo.remotes.origin.push()

rr.bat的内容是:

ssh -p 8022 -i  C:\Users\zikasak\.ssh\id_rsa -oIdentitiesOnly=yes -oStrictHostKeyChecking=no -oUserKnownHostsFile=C:\Users\zikasak\.ssh\known_hosts "$@"

但是我收到此错误消息:

Cmd('git') failed due to: exit code(128)
cmdline: git push --porcelain origin
stderr: 'fatal: protocol error: bad line length character: ?
F:
Pseudo-terminal will not be allocated because stdin is not a terminal.
Permission denied, please try again.
Permission denied, please try again.
$@: Permission denied (password,publickey).'
python git gitpython
1个回答
0
投票
您好,尝试使用变量代替bat文件,请参见以下示例:

repo = Repo(config['gitRepo']) repo.git.add(A=True) repo.index.commit("test") ssh_cmd = '''ssh -p 8022 -i C:\Users\zikasak\.ssh\id_rsa -oIdentitiesOnly=yes -oStrictHostKeyChecking=no -oUserKnownHostsFile=C:\Users\zikasak\.ssh\known_hosts "$@"''' with repo.git.custom_environment(GIT_SSH=ssh_cmd): repo.remotes.origin.push()

© www.soinside.com 2019 - 2024. All rights reserved.