2

I am trying to initialize a git repro on a samba mount with very limited permissions.

Trying to init I will receive:

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

Which is surprising as filemode is already globally set to false

$ git config --get core.filemode
false

The Problem in general is that /mnt/server is a samba mount to a folder to which I have very limited access. Also I am not able to change any permission for the /mnt/server mount as I am working on shared server with on which several users need the access to the /mnt/server mount. So changing mounting permission like suggested here is not an option.

Also creating a symlink like suggested here does not work, as symlinks are not enabled on the samba drive.

So the question is how to prevent git from failing a chmod error or prevent it from doing chmod at all? Is this possible? Or how do I init a git in the environment?

Kound
  • 1,835
  • 1
  • 17
  • 30

1 Answers1

2

A bit hacky solution is:

Init the an empty repro at destiantion with sufficient permission i.e. mktemp -d.

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

Move the created .git folder to target destination.

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

There will some error during moving but it won't stop mv from moving the files.

In the end the git works as expected:

$ 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 and checkout seems to work to, didn't test push/pull.

Would still appreciate a cleaner solution.

Kound
  • 1,835
  • 1
  • 17
  • 30
  • I don't think there is a nicer one, other than building a Git binary that has the "test whether chmod +x/-x works" code snipped out (this is easy as there's already a compile-time ifdef). – torek Dec 05 '19 at 17:32
  • Just do `$ mv $tempdir/.git /srv/server/sub/ 2>/dev/null` and the errors are gone too :D – hob Apr 21 '23 at 11:56