我最初的答案结果证明即使对我自己也不是很有用,所以我仔细研究了一下,发现了一个 hack(虽然有点复杂)。
所以,我git
在 MSYS2 下使用,并且我想使用credential-cache
, 来暂时记住我的密码(而且我还没有看到这样的用例wincred
或其他适用于 Windows 的方法)。
基本上,这需要在https://github.com/git/git/blob/55144cc/builtin/credential-cache--daemon.c#L239中进行破解- 而不是die
-ing 在该行中,我们想继续.
所以,首先,我们要git
在 MSYS2 下构建。
因此,我们需要构建git
在 MSYS2 中使用的实际。首先,检查版本:
$ git --version
git version 2.33.0
$ pacman -Ss git | grep installed # msys/git 2.33.0-1 (VCS) [installed]
然后,按照https://www.msys2.org/wiki/Creating-Packages/,我们可以这样做:
$ git clone "https://github.com/msys2/MSYS2-packages"
$ cd MSYS2-packages/
$ cd git
$ makepkg -sCLf
==> Making package: git 2.33.0-1 (Thu, Sep 23, 2021 12:47:33 PM)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Installing missing dependencies...
...
make[1]: Entering directory '/c/src/MSYS2-packages/git/src/git-2.33.0'
make[1]: 'GIT-VERSION-FILE' is up to date.
make[1]: Leaving directory '/c/src/MSYS2-packages/git/src/git-2.33.0'
sed -e '1s|#!.*/sh|#!/bin/sh|' git-subtree.sh >git-subtree
chmod +x git-subtree
make: Leaving directory '/c/src/MSYS2-packages/git/src/git-2.33.0/contrib/subtree'
==> Starting check()...
注意这里:
- 这个构建过程首先以 ASCIIDOC/XMLTO 部分结束,这在我的机器上需要半小时
- 然后它会在一个需要更长时间的部分结束
*** prove ***
,但可以用 Ctrl-C 中断,并且构建的可执行文件不会被删除。
所以,现在我们想在源代码中做一个 hack;笔记:
- 如果我们在源代码中进行hack,我们不想使用
makepkg -sCLf
,因为这将删除源目录(以及所有构建的 .exe 工件),然后在构建之前重建它
因此,我们使用 hack 进行破解sed
,然后构建:
$ sed -i 's/die(_(permissions_advice), dir);/fprintf(stderr, "Permissions on cached credentials socket directory %s are too loose, but HACK: going on\\n", dir);/' ./src/git-2.33.0/builtin/credential-cache--daemon.c
$ (cd src/git-2.33.0/; make)
CC builtin/credential-cache--daemon.o
LINK git.exe
...
SUBDIR templates
在这一点上,请注意,黑客最终至少包含三个可执行文件,可以通过以下方式确认:
$ grep -ao ....HACK........ ./src/git-2.33.0/git-credential-cache--daemon.exe
$ grep -ao ....HACK........ ./src/git-2.33.0/git-credential-cache.exe
$ grep -ao ....HACK........ ./src/git-2.33.0/git.exe
...在替换所有三个之后,我只能让它工作:
# backup the original files:
$ mv /usr/lib/git-core/git-credential-cache--daemon.exe /usr/lib/git-core/__git-credential-cache--daemon_orig.exe
$ mv -v /usr/lib/git-core/git-credential-cache.exe /usr/lib/git-core/__git-credential-cache__orig.exe
$ mv -v /usr/bin/git.exe /usr/bin/__git_orig.exe
$ mv -v /usr/lib/git-core/git.exe /usr/lib/git-core/__git_orig.exe
# copy over the hacked files:
cp -v ./src/git-2.33.0/git-credential-cache--daemon.exe /usr/lib/git-core/
cp -v ./src/git-2.33.0/git-credential-cache.exe /usr/lib/git-core/
cp -v ./src/git-2.33.0/git.exe /usr/bin/
cp -v ./src/git-2.33.0/git.exe /usr/lib/git-core/
在这一点上,credential-cache
我也开始在 MSYS2 上工作(在有限的时间内缓存密码);只是它在启动时转储了被黑的行:
$ git pull
Password for 'https://user@git.mysite.com':
Permissions on cached credentials socket directory /home/user/.cache/git/credential are too loose, but HACK: going on
Already up to date.
# second pull, password is cached
$ git pull
Already up to date.
有点棘手,但似乎有效。
PS:一个棘手的事情是,我最初die
只用printf
to替换stdout
,但一直失败;事实证明,stdout
它用于进程间通信,并且要成功,显然答案ok\0
是stdout
三个字节;所以解决方案是打印通知stderr
。
(原答案):
虽然没有完全按照要求回答问题,但这是我能找到的最合适的问题,将其记录为答案:
我git
在Windows 10的MSYS2下使用,目前有以下版本:
$ git --version
git version 2.32.0
我通常只想让 git 在有限的时间内(可能 10 分钟左右)缓存我的密码,然后忘记它;而且我还没有看到wincred
在该用例中使用或其他特定于 Windows 的凭据管理器。
话虽这么说,但对我来说有一个“简单的解决方法”——基本上,凭证管理器第一次运行就可以了;只有在随后的使用中,我才得到:
$ git push
Password for 'http://user@githost.example.com':
fatal: The permissions on your socket directory are too loose; other
users may be able to read your cached credentials. Consider running:
chmod 0700 /home/user/.cache/git/credential
fatal: cache daemon did not start:
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
...
因此,基本上,解决方法是删除credential
目录 - 此后,凭据缓存管理器就像第一次一样运行,并在有限的时间内缓存密码 - 就像我想要的那样:
$ rm -rf ~/.cache/git/credential
# note below, the very first pull still asks for a password:
$ git pull
Password for 'http://user@githost.example.com':
Already up to date.
# ... but the second pull does not, it uses credentials cache
$ git pull
Already up to date.
对我来说已经足够了,我猜:)
编辑:不是真的,我在此之后立即体验到,如果您尝试拉入另一个选项卡,错误就会返回。