Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent git from failing on filesystems without chmod permissions in Linux

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?

like image 559
Kound Avatar asked Nov 27 '25 23:11

Kound


1 Answers

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.

like image 114
Kound Avatar answered Nov 30 '25 12:11

Kound



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!