如何调试 git 凭证助手?

Bru*_*sky 5 git

我读过了:

\n\n\n\n

不幸的是,我无法让最基本的科学方法\xe2\x84\xa2 测试发挥作用。我已经使用我的替代命令来尝试记录 git 调用助手时发生的情况。不幸的是,我的命令没有记录任何内容。因此我被迫得出结论 git 没有调用它的助手。我能做些什么?

\n

whe*_*ler 1

我试图让 1Password CLI 将我的 GitHub 令牌移交给该gh命令,并将 Git 配置为将该gh命令用作凭据助手。但是当我从命令行运行并且它会生成正确的凭据时,我遇到了一个问题,但是当我在agh auth git-credential中出现以下内容时,仍然会提示我输入用户名和密码:~/.gitignoregit clone

[credential "https://github.com"]
    helper = /usr/bin/gh auth git-credential
Run Code Online (Sandbox Code Playgroud)

为了进行一些调试,我首先通过将环境变量设置为以下方式在 Git 中启用跟踪日志记录GIT_TRACEtrue

GIT_TRACE=true git clone https://github.com/wheelerlaw/some-private-repo
Run Code Online (Sandbox Code Playgroud)

这将产生如下所示的输出:

$ GIT_TRACE=true git clone https://github.com/Kong/khcp.git
15:19:00.344373 git.c:460               trace: built-in: git clone https://github.com/Kong/khcp.git
Cloning into 'khcp'...
15:19:00.347803 run-command.c:655       trace: run_command: git remote-https origin https://github.com/Kong/khcp.git
15:19:00.349893 git.c:750               trace: exec: git-remote-https origin https://github.com/Kong/khcp.git
15:19:00.349939 run-command.c:655       trace: run_command: git-remote-https origin https://github.com/Kong/khcp.git
15:19:00.625485 run-command.c:655       trace: run_command: '/usr/bin/gh auth git-credential get'
Run Code Online (Sandbox Code Playgroud)

但是,它不会显示传入/传出凭据助手的数据的任何调试输出。为此,我编写了一个小型 Python 脚本,充当凭证助手的包装器:

[credential "https://github.com"]
    helper = /usr/bin/gh auth git-credential
Run Code Online (Sandbox Code Playgroud)

然后,我修改了~/.gitconfig文件以调用 Python 脚本作为凭证助手:

[credential "https://github.com"]
    helper = /home/wheeler/wrapper.py
Run Code Online (Sandbox Code Playgroud)

现在,当我在git clone启用跟踪调试的情况下执行相同的命令时,我可以看到gitgh auth git-credential正在相互通信:

$ GIT_TRACE=true git clone https://github.com/Kong/khcp.git
15:54:33.973855 git.c:460               trace: built-in: git clone https://github.com/Kong/khcp.git
Cloning into 'khcp'...
15:54:33.987155 run-command.c:655       trace: run_command: git remote-https origin https://github.com/Kong/khcp.git
15:54:33.989509 git.c:750               trace: exec: git-remote-https origin https://github.com/Kong/khcp.git
15:54:33.989539 run-command.c:655       trace: run_command: git-remote-https origin https://github.com/Kong/khcp.git
15:54:34.191478 run-command.c:655       trace: run_command: '/home/wheeler/test.py get'
[TRACE]  ['/usr/bin/gh', 'auth', 'git-credential', 'get']
[TRACE]  protocol=https
[TRACE]  host=github.com
[TRACE]  Done sending input...
[TRACE]  Done receiving output...
[TRACE]  Return code: 1
Run Code Online (Sandbox Code Playgroud)

这帮助我意识到我需要将我的helper行设置为以下内容以允许gh命令从 1Password 获取令牌:

[credential "https://github.com"]
    helper = /usr/bin/op plugin run -- gh auth git-credential
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助