我们有一个本地托管的 Gitlab 存储库,我正在尝试使用以下脚本通过 ssh 使用 gitpython 自动推送和拉取:
LOCAL_REPO_PATH = "/path/to/repository"
repo = Repo(LOCAL_REPO_PATH)
origin = repo.remotes[0]
origin.pull()
# Do some automated changes
index = repo.index
index.add(["*"])
index.commit("Removed/Added stuff")
author = Actor("Script","[email protected] /cdn-cgi/l/email-protection)
committer = Actor("Script","[email protected] /cdn-cgi/l/email-protection)
origin.push()
仓库的配置是
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@gitlab.<repo url>:<owner username>/<repository name>.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
每当我尝试运行它时,它都会到达 origin.pull() 并停止执行以请求[电子邮件受保护] /cdn-cgi/l/email-protection采用以下格式:
Password:
Password:
Password:
git@gitlab.<url>'s password:
git@gitlab.<url>'s password:
git@gitlab.<url>'s password:
密码输入错误6次后,会抛出此错误
Traceback (most recent call last):
File "git-test.py", line 15, in <module>
origin.pull()
File "/usr/local/lib/python3.8/dist-packages/git/remote.py", line 910, in pull
res = self._get_fetch_info_from_stderr(proc, progress,
File "/usr/local/lib/python3.8/dist-packages/git/remote.py", line 750, in _get_fetch_info_from_stderr
proc.wait(stderr=stderr_text)
File "/usr/local/lib/python3.8/dist-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
stderr: 'fatal: Could not read from remote repository.'
有什么方法可以在没有 git 用户密码的情况下自动执行此操作吗?
Edit 1
我问了一个新问题here https://stackoverflow.com/questions/73284447/git-push-pull-over-ssh-to-locally-hosted-gitlab-as-root-requires-gitgitlab-pass,因为我已经缩小了问题的范围。