permissionswindows-subsystem-for-linuxsambagit-add

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


I'm working on Win10 using the WSL1 (Windows Linux Subsystem) with Ubuntu 20.04.1 LTS. I have a Samba (1.0) Network Share on which I want to create my git repository via my Ubuntu Terminal.

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

I can git init without a problem, however, as soon as I try to git add a file, I get this error:

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

The permissions, however, are all right, as far as I can tell. All files belong to christian:christian. The tree looks like this:

.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

Whats strange is, that after git add my_code_file.rb I am no longer able to delete the .git dir, without permission error:

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

It seems git creates the tmp_obj_mZzHwy without giving me permission to delete it, which shouldn't be I guess.

Here again the permissions for the .git Folder after the git add my_code_file.rb

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

The Samba Share on which I am working is mounted as drive (with letter P:) on Win10. On my WSL Ubuntu I mount it via /etc/fstab with following line:

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

My .git/config for the repo

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

What I already tried to fix the problem:

On my home dir (resp. non-samba drive) git init/add works without problems.


Update

I found out that the samba share is not mounted properly, the metadata option is missing resp. gets ignored whenever I mount it. I think this might be the problem! However, its not clear to me, why it's ignored or if there is a way to force it?

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

Solution

  • Solution: Upgrade to WSL2

    As I found out, the solution was to Upgrade from WSL1 to WSL2, there mounting works correctly. I'm able to git-add or git-clone without permission errors now.

    Open a PowerShell to see your current version:

    PS C:\Users\christian> wsl -l -v
      NAME      STATE           VERSION
    * Ubuntu    Stopped         1
    

    In case its 1 you can upgrade it, but check the WSL2 requirements first (just to be safe).

    Upgrade Guide

    Excerpt from Guide/Steps I had to do:

    Just to provide complete information, here also the mount options /etc/fstab

    P:      /mnt/p  drvfs   rw,noatime,uid=christian,gid=christian,metadata,case=off        0 0
    

    Compared to

    christian@my_pc:~$ findmnts
    ...
    ├─/mnt/p                        P:           9p          rw,noatime,dirsync,aname=drvfs;path=P:;uid=1000;gid=1000;metadata;case=off;symlinkroot=/mnt/,mmap,access=client,msize=65536,trans=fd,rfd=3,wfd=3
    └─/mnt/c                        C:\          9p          rw,noatime,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;uid=1000;gid=1000;metadata;case=off;symlinkroot=/mnt/,mmap,access=client,msize=65536,trans=fd,rfd=8,wfd=8