防止 git 在 Linux 中没有 chmod 权限的文件系统上失败

Prevent git from failing on filesystems without chmod permissions in Linux

我正尝试在权限非常有限的 samba 安装上初始化 git 重现。

尝试初始化我将收到:

$ git init .
error: chmod on /mnt/server/subfolder/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'

这令人惊讶,因为文件模式已全局设置为 false

$ git config --get core.filemode
false

一般来说,问题是 /mnt/server 是一个 samba 挂载到我访问权限非常有限的文件夹。 此外,我无法更改 /mnt/server 挂载的任何权限,因为我正在共享服务器上工作,多个用户需要在共享服务器上访问 /mnt/server 挂载。 所以像建议的那样更改安装权限 here 不是一个选项。

也像建议的那样创建符号链接 here 不起作用,因为符号链接在 samba 驱动器上未启用。

所以问题是如何防止 git 发生 chmod 错误或根本不执行 chmod? 这可能吗? 或者如何在环境中初始化 git?

有点老套的解决方案是:

在具有足够权限的目的地初始化空复制,即 mktemp -d。

$ tempdir = $(mktemp -d)
$ git init $tempdir
Initialized empty Git repository in /tmp/tmp.pREa198fnx/.git/

将创建的 .git 文件夹移动到目标位置。

$ mv $tempdir/.git /srv/server/sub/
mv: preserving times for './.git/branches': Operation not permitted
mv: preserving permissions for ‘./.git/branches’: Operation not permitted
mv: preserving times for './.git/hooks/applypatch-msg.sample': Operation not permitted
mv: preserving permissions for ‘./.git/hooks/applypatch-msg.sample’: Operation not permitted
mv: preserving times for './.git/hooks/commit-msg.sample': Operation not permitted
...

移动过程中会出现一些错误,但不会阻止 mv 移动文件。

最终 git 按预期工作:

$ echo "Foo" > bar.txt
$ git add bar.txt
$ git commit -m "Added Foobar"
[master (root-commit) e232039] bar.txt
 1 file changed, 1 insertion(+)
 create mode 100755 bar.txt
$ git status
On branch master
nothing to commit, working tree clean

branch 和 checkout 似乎有效,没有测试 push/pull。

仍然希望有一个更简洁的解决方案。