git status does not work properly with Virtualbox Shared Folders
Asked Answered
L

3

5

Details

  • Host Machine: macOS Sierra
  • Guest Machine: Ubuntu 64bits 16.04 LTS
  • Virtualbox: 5.1.14

On the host the repository is only local for now. Initialized and have several [local] commits without a single push to remote.

Symptoms

On my host machine I have parent folder with a Git repository on it. I have shared parent folder with the guest machine, after login on the VM the folder is in /media/sf_parent.

In a terminal I do cd /media/sf_parent at the moment the content seems to be properly shared. But when I change to the repo folder I tried to do a git status and the output is as everything single file in the repository is tracked but modified.

The strange part is that the git log delivers the last commit I have made on host. I tried to visually compare both "versions" of the repository folder with ls and they the same value for "update date" and "file size" but have different values for "owner", "group" and "permissions".


What could be the problem?

Maybe Virtualbox somehow does not support this?

Might be the conflict on filesystem level with "owner" and "permissions"?

Lenticularis answered 28/3, 2017 at 11:1 Comment(0)
L
9

With the help of git config I was able to resolve this problem as I suspected and @g19fanatic suggested this problem seems to be related with "user permissions".

After reading a lot of the properties on the page I tested this two:

git config core.filemode false
git config core.ignorecase false

PS: Their are both true as default.

Restarted the VM and it worked, now working tree is synced between host and guest.

Lenticularis answered 29/3, 2017 at 11:59 Comment(2)
Thanks. This seems to fix my shared git directory problem (between Windows and Linux), which is claimed to be not possible by many (like #54410855)Rhymester
On Ubuntu, simply becoming root and executing the desired git commands solved the issue for me. sudo should also work.Gstring
C
1

linux user administration is your problem. Your vm doesn't know what/who the group/users are from your host machine and vice/versa. The can be fixed by using separate authentication servers for user accounts but that answer is out of scope for StackOverflow.

One git way to fix this would be to host a bare repository on the shared folder and clone locally to the VM. push/pull changes as necessary

from host

cd shared/folder
mkdir <repo name>.git    #.git isn't really needed but is typical
cd <repo name>.git
git init --bare

cd <current repo location>
git remote add origin <path to repo.git folder>
git push --all

from vm

cd ~
git clone <path to shared folder bare repo.git>

be sure to set the username and email address when on the VM so that the commits are attributed to the correct people (using git config)

Cheatham answered 28/3, 2017 at 11:47 Comment(1)
if already had the code in the remote I would not need the shared folder... but what you state on the first line goes along with my suspicion.Lenticularis
H
1

flush cache to disk solved my problem:

echo 3 > /proc/sys/vm/drop_caches
Hildehildebrand answered 15/12, 2020 at 9:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.