[英]Python PyTest running GitPython under Tox in Ubuntu Docker image: commit fails with Committer/Author identity unknown
问答(我发布这个是为了防止其他人掉进这个小众兔子洞——因为我花了一段时间才弄明白)。
场景:您已决定运行一个单元测试,该单元测试“播放”使用 GitPython 创建本地 git 存储库。 您的测试在运行 Ubuntu docker 映像的 GitHub 操作中的 Tox 中运行 - 它具有包含 user.name 和 user.email 的 correct.gitconfig 文件。 如果您使用 GitPython 的 GitConfigParser 或者只是阅读 git.config.get_config_path 中的文件,您甚至可以看到这个正确的配置。
在以上所有看起来不错的情况下,您运行测试,其中包含如下内容:
with open(os.path.join(remote_repo.working_dir, 'readme.md'), 'w') as file:
file.write('# Remote\n')
remote_repo.git.add(A=True)
remote_repo.git.commit(m=commit_text)
在 GH 中失败,例如:
raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
E git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
E cmdline: git commit -m Initial commit
E stderr: 'Author identity unknown
E
E *** Please tell me who you are.
E
E Run
E
E git config --global user.email "you@example.com"
E git config --global user.name "Your Name"
E
E to set your account's default identity.
E Omit --global to set the identity only in this repository.
E
E fatal: unable to auto-detect email address (got '**********.(none)')'
编辑答案移动了下面的答案。
我尝试了很多东西......但是最后一次调用 remote_repo.git.config('--global', 'user.name', 'some user') 的绝望尝试失败了,消息是 '$HOME' 不是设置 - 这最终把我带到了......
解决方案:将以下内容添加到 tox.ini 的 testenv 部分[在评论后编辑] :
[testenv]
passenv = HOME
...
说明: Tox 没有设置 HOME 环境变量,而且如果设置了 HOME,GitPython 的 repo.git.commit 命令似乎只会读取配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.