gpt4 book ai didi

permissions - WSL+samba+git : "error: insufficient permission for adding an object to repository database .git/objects"/git-clone/git-add permission errors

转载 作者:行者123 更新时间:2023-12-05 08:05:23 42 4
gpt4 key购买 nike

我正在使用 WSL1(Windows Linux 子系统)和 Ubuntu 20.04.1 LTS 开发 Win10。我有一个 Samba (1.0) 网络共享,我想通过我的 Ubuntu 终端在上面创建我的 git 存储库。

christian@my_pc:~/p/git_test$ ll
total 2048
drwxr-xr-x 1 christian christian 512 Jan 19 11:13 ./
drwxr-xr-x 1 christian christian 512 Jan 19 10:11 ../
-rwxr--r-- 1 christian christian 0 Jan 19 10:12 my_code_file.rb

我可以 git init 没有问题,但是,当我尝试 git add 一个文件时,我得到这个错误:

christian@my_pc:~/p/git_test$ git add my_code_file.rb
error: insufficient permission for adding an object to repository database .git/objects
error: my_code_file.rb: failed to insert into database
error: unable to index file 'my_code_file.rb'
fatal: adding files failed

然而,据我所知,权限是正确的。所有文件都属于 christian:christian。这棵树看起来像这样:

.git
├── [-rwxr--r--] HEAD
├── [drwxr-xr-x] branches
├── [-rwxr--r--] config
├── [-rwxr--r--] description
├── [drwxr-xr-x] hooks
│   ├── [-rwxr--r--] applypatch-msg.sample
│   ├── [-rwxr--r--] commit-msg.sample
│   ├── [-rwxr--r--] fsmonitor-watchman.sample
│   ├── [-rwxr--r--] post-update.sample
│   ├── [-rwxr--r--] pre-applypatch.sample
│   ├── [-rwxr--r--] pre-commit.sample
│   ├── [-rwxr--r--] pre-merge-commit.sample
│   ├── [-rwxr--r--] pre-push.sample
│   ├── [-rwxr--r--] pre-rebase.sample
│   ├── [-rwxr--r--] pre-receive.sample
│   ├── [-rwxr--r--] prepare-commit-msg.sample
│   └── [-rwxr--r--] update.sample
├── [drwxr-xr-x] info
│   └── [-rwxr--r--] exclude
├── [drwxr-xr-x] objects
│   ├── [drwxr-xr-x] e6
│   │   └── [-r-xr--r--] tmp_obj_mZzHwy
│   ├── [drwxr-xr-x] info
│   └── [drwxr-xr-x] pack
└── [drwxr-xr-x] refs
├── [drwxr-xr-x] heads
└── [drwxr-xr-x] tags

10 directories, 17 files

奇怪的是,在 git add my_code_file.rb 之后,我无法再删除 .git 目录,未经许可错误:

christian@my_pc:~/p/git_test$ rm -rf .git
rm: cannot remove '.git/objects/e6/tmp_obj_mZzHwy': Permission denied

似乎 git 创建了 tmp_obj_mZzHwy 没有给我删除它的权限,我想这不应该。

git add my_code_file.rb

之后的 .git 文件夹的权限
christian@my_pc:~/p/git_test$ ls -lahR .git
.git:
total 0
drwxr-xr-x 1 christian christian 512 Jan 19 11:14 .
drwxr-xr-x 1 christian christian 512 Jan 19 11:13 ..
drwxr-xr-x 1 christian christian 512 Jan 19 11:14 objects

.git/objects:
total 0
drwxr-xr-x 1 christian christian 512 Jan 19 11:14 .
drwxr-xr-x 1 christian christian 512 Jan 19 11:14 ..
drwxr-xr-x 1 christian christian 512 Jan 19 11:13 e6

.git/objects/e6:
total 1.0M
drwxr-xr-x 1 christian christian 512 Jan 19 11:13 .
drwxr-xr-x 1 christian christian 512 Jan 19 11:14 ..
-r-xr--r-- 1 christian christian 0 Jan 19 11:13 tmp_obj_mZzHwy

我正在使用的 Samba 共享在 Win10 上安装为驱动器(带字母 P:)。在我的 WSL Ubuntu 上,我通过 /etc/fstab 使用以下行安装它:

P:▸ /mnt/p▸ drvfs▸defaults,metadata,rw,exec,uid=christian,gid=christian,umask=22,fmask=11▸0 0

repo 的我的 .git/config

[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true

我已经尝试解决的问题:

  • chmod -R u+rwx .
  • git init --shared=all
  • 掩码 0000

在我的主目录(resp. 非 samba 驱动器)git init/add 工作没有问题。


更新

我发现 samba 共享没有正确挂载,元数据选项丢失 resp。每当我安装它时,都会被忽略。我认为这可能是问题所在!但是,我不清楚为什么它会被忽略,或者是否有强制执行它的方法?

TARGET                       SOURCE      FSTYPE      OPTIONS
/ rootfs wslfs rw,noatime
...
├─/mnt/p P: drvfs rw,noatime,uid=1000,gid=1000,case=off
└─/mnt/c C:\ drvfs rw,noatime,uid=1000,gid=1000,metadata,case=off

最佳答案

除了 WSL2,您可能还会遇到另一个错误,因为最近的 Git 中包含 built-in File System Monitor

在 Git 2.38(2022 年第 3 季度)中,内置的 fsmonitor 拒绝在网络安装的存储库上工作;引入了一个供用户覆盖的配置旋钮。

参见 commit 85dc0daEric DeCosta (edecosta-mw)(2022 年 8 月 11 日)。
(由 Junio C Hamano -- gitster -- 合并到 commit 0479138 ,2022 年 9 月 13 日)

fsmonitor: option to allow fsmonitor to run against network-mounted repos

Signed-off-by: Eric DeCosta

Though perhaps not common, there are use cases where users have large, network-mounted repos.
Having the ability to run fsmonitor against network paths would benefit those users.

Most modern Samba-based filers have the necessary support to enable fsmonitor on network-mounted repos.
As a first step towards enabling fsmonitor to work against network-mounted repos, introduce a configuration option, 'fsmonitor.allowRemote'.
Setting this option to true will override the default behavior (erroring-out) when a network-mounted repo is detected by fsmonitor.


这来自 With Git 2.37 (Q2 2022),它阐明了与网络驱动器的不兼容性:

See commit 3294ca6 , commit 53fcfbc , commit eb29901 , commit 00991e1 , commit 9915e08 , commit d6d58ff , commit caa9c37 , commit f954c7b , commit 7667f9d , commit b533708 , commit 95a4e78 , commit de7e0b5 , commit 6504cfd , commit 90a70fa , commit d060555 , commit 207534e , commit 802aa31 , commit 39664e9 , commit 8e8f4b8 , commit 9968ed7 , commit ddc5dac , commit d989b26 , commit 1e7be10 , commit a85ad67commit 5c58fbdcommit d33c804commit 62a62a2commit 49b398acommit 27b5d41commit 40f865d(2022 年 5 月 26 日)作者:Jeff Hostetler (Jeff-Hostetler)
请参阅 commit 852e2c8Junio C Hamano (gitster)(2022 年 3 月 25 日)。
(由 Junio C Hamano -- gitster -- 合并到 commit 9e496ff ,2022 年 6 月 10 日)

fsmonitor-settings: NTFS and FAT32 on MacOS are incompatible

Signed-off-by: Jeff Hostetler

On MacOS mark repos on NTFS or FAT32 volumes as incompatible.

The builtin FSMonitor used Unix domain sockets on MacOS for IPC with clients.
These sockets are kept in the .git directory.
Unix sockets are not supported by NTFS and FAT32, so the daemon cannot start up.

Test for this during our compatibility checking so that client commands do not keep trying to start the daemon.

full comment:

Remote working directories are problematic for FSMonitor.

The underlying file system on the server machine and/or the remotemount type (NFS, SAMBA, etc.) dictates whether notification eventsare available at all to remote client machines.

Kernel differences between the server and client machines alsodictate the how (buffering, frequency, de-dup) the events aredelivered to client machine processes.

A client machine (such as a laptop) may choose to suspend/resumeand it is unclear (without lots of testing) whether the watcher canresync after a resume.
We might be able to treat this as a normal"events were dropped by the kernel" event and do our normal "flushand resync" --or-- we might need to close the existing (zombie?)notification fd and create a new one.

In theory, the above issues need to be addressed whether we areusing the Hook or IPC API.

For the builtin FSMonitor, we create the Unix domain socket for theIPC in the .git directory.

If the working directory is remote,then the socket will be created on the remote file system.
This can fail if the remote file system does not support UDS file types(e.g. smbfs to a Windows server) or if the remote kernel does notallow a non-local process to bind() the socket.
(These problemscould be fixed by moving the UDS out of the .git directory and to awell-known local directory on the client machine, but care shouldbe taken to ensure that $HOME is actually local and not a managedfile share).

So (for now at least), mark remote working directories asincompatible.

FAT32 and NTFS working directories are problematic too.

The builtin FSMonitor uses a Unix domain socket in the .gitdirectory for IPC.
These Windows drive formats do not supportUnix domain sockets, so mark them as incompatible for the daemon.


在 Git 2.39(2022 年第 4 季度)中,默认情况下禁用在网络文件系统上的存储库上使用 fsmonitor。
添加旋钮以使其在 macOS 上可用。

参见 commit c4f9490Jeff King (peff)(2022 年 10 月 10 日)。
参见 commit 5aa9e32commit 25c2cabcommit 12fd27dcommit 8f44976commit 6beb268commit 508c1a5 (2022 年 10 月 4 日),作者 Eric DeCosta (edecosta-mw)
(由 Junio C Hamano -- gitster -- 合并到 commit 7b8cfe3 ,2022 年 10 月 17 日)

fsmonitor: add documentation for allowRemote and socketDir options

Signed-off-by: Eric DeCosta

Add documentation for 'fsmonitor.allowRemote' and 'fsmonitor.socketDir'.
Call-out experimental nature of 'fsmonitor.allowRemote' and limited filesystem support for 'fsmonitor.socketDir'.

git config 现在包含在其 man page 中:

fsmonitor.allowRemote

By default, the fsmonitor daemon refuses to work against network-mountedrepositories. Setting fsmonitor.allowRemote to true overrides thisbehavior. Only respected when core.fsmonitor is set to true.

git fsmonitor--daemon 现在包含在其 man page 中:

By default, the fsmonitor daemon refuses to work against network-mountedrepositories; this may be overridden by setting fsmonitor.allowRemote totrue. Note, however, that the fsmonitor daemon is not guaranteed to workcorrectly with all network-mounted repositories and such use is consideredexperimental.


Git 2.39(2022 年第 4 季度)修复了 macOS 上的 core.fsmonitor 不会注意到创建或修改的符号链接(symbolic link)的问题。

参见 commit ee0e7fcsrz_zumix (srz-zumix)(2022 年 11 月 8 日)。
(由 Junio C Hamano -- gitster -- 于 2022 年 11 月 23 日在 commit 8d7b35b 中合并)

fsmonitor--daemon: on macOS support symlink

Signed-off-by: srz_zumix
Signed-off-by: Taylor Blau

Resolves a problem where symbolic links were not showing up in diff when created or modified.

kFSEventStreamEventFlagItemIsSymlink is also treated as a file update.
This is because kFSEventStreamEventFlagItemIsFile is not included in FSEvents when creating or deleting symbolic links.
For example:

$ ln -snf t test
fsevent: '/path/to/dir/test', flags=0x40100 ItemCreated|ItemIsSymlink|
$ ln -snf ci test
fsevent: '/path/to/dir/test', flags=0x40200 ItemIsSymlink|ItemRemoved|
fsevent: '/path/to/dir/test', flags=0x40100 ItemCreated|ItemIsSymlink|

关于permissions - WSL+samba+git : "error: insufficient permission for adding an object to repository database .git/objects"/git-clone/git-add permission errors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65790476/

42 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com