aoh
aoh

Reputation: 1160

Git not working with Ubuntu → Windows Samba shared directory

I am running a Virtual Box Ubuntu VM where I set up my git repository. I then used Samba to create a shared folder and have the following configuration in smb.conf

path = /home/allan/git_repo
valid users = allan
read only = no
hide dot files = no

When I navigate to the appropriate network location (\\192.168.65.101\git_repo) I see all of my files and folders there, including my .git folder which seems to contain everything that I need.

If I navigate to the network location in my bash terminal (MINGW64) I find that it is not recognized as a git repository. A simple command like git rev-parse HEAD returns fatal: Not a git repository (or any of the parent directories): .git On the other hand, navigating a sub-directory level down causes some sort of recognition (e.g. I can run git rev-parse HEAD and get the valid response). There are plenty of functions though for which I need to be at the upper directory so I'm confused what is happening and how I can solve this issue.

Upvotes: 1

Views: 848

Answers (1)

VonC
VonC

Reputation: 1324387

Make sure to not execute your git command in the .git folder itself.

If should be execute in the parent folder of the .git/.

Also, make sure to use the latest version of Git for Windows, as it has a better support of \\... path.
See also "git tries to stat //HEAD when searching for a repo, leading to huge delays on Cygwin".


Git 2.24 (Q4 2019) will recognize that, On Windows, the root level of UNC share is now allowed to be used just like any other directory.

See commit 5cf7b3b, commit e2683d5, commit d17f212 (24 Aug 2019) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit b57a88a, 30 Sep 2019)

setup_git_directory(): handle UNC root paths correctly

When working in the root directory of a file share (this is only possible in Git Bash and Powershell, but not in CMD), the current directory is reported without a trailing slash.

This is different from Unix and standard Windows directories: both / and C:\ are reported with a trailing slash as current directories.

If a Git worktree is located there, Git is not quite prepared for that:
while it does manage to find the .git directory/file, it returns as length of the top-level directory's path one more than the length of the current directory, and setup_git_directory_gently() would then return an undefined string as prefix.

In practice, this undefined string usually points to NUL bytes, and does not cause much harm. Under rare circumstances that are really involved to reproduce (and not reliably so), the reported prefix could be a suffix string of Git's exec path, though.

More specifically, git-for-windows/git issue 1320 reported git status fails in UNC path at root of Windows share.

fatal: Not a git repository (or any of the parent directories): .git

Fix .git/ discovery at the root of UNC shares

A very common assumption in Git's source code base is that offset_1st_component() returns either 0 for relative paths, or 1 for absolute paths that start with a slash.
In other words, the return value is either 0 or points just after the dir separator.

This assumption is not fulfilled when calling offset_1st_component() e.g. on UNC paths on Windows, e.g. "//my-server/my-share".
In this case, offset_1st_component() returns the length of the entire string (which is correct, because stripping the last "component" would not result in a valid directory), yet the return value still does not point just after a dir separator.

This assumption is most prominently seen in the setup_git_directory_gently_1() function, where we want to append a ".git" component and simply assume that there is already a dir separator.
In the UNC example given above, this assumption is incorrect.

As a consequence, Git will fail to handle a worktree at the top of a UNC share correctly.

Let's fix this by adding a dir separator specifically for that case: we found that there is no first component in the path and it does not end in a dir separator? Then add it.

Upvotes: 2

Related Questions