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

问题描述 投票:0回答:1

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

尝试初始化,我将收到:

$ 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?

linux git permission-denied
1个回答
0
投票

有点骇人听闻的解决方法是:

在具有足够许可权(即mktemp -d的情况下,按指定的意愿初始化一个空的repro]

$ 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

分支和结帐似乎可以正常工作,没有测试推/拉。

仍然会喜欢更干净的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.