git-credential-manager icon indicating copy to clipboard operation
git-credential-manager copied to clipboard

WSL & Worktree issue : Not a git repositiory

Open OdysseusOperator opened this issue 11 months ago • 3 comments

Git is set up, just like this: https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-git

I am using WSL Ubuntu 24.04. Windows and Linux both have Git in Version 2.47.1 This error doesn't appear on Windows, just from WSL.


Steps to reproduce: (Works with all repos i think) Open Wsl. make a dir to work in and cd into it. git clone https://github.com/routerdieb/java11TxtTimebox main cd main git worktree add ../test123 cd .. cd test123 git pull (or git push doesnt matter here)

OdysseusOperator avatar Dec 12 '24 06:12 OdysseusOperator

 git push --set-upstream origin test123
fatal: not a git repository: /mnt/d/code2dash_wsl/main/.git/worktrees/test123

Unhandled Exception: System.InvalidOperationException: StandardError has not been redirected.
   at System.Diagnostics.Process.get_StandardError()
   at GitCredentialManager.ChildProcess.get_StandardError()
   at GitCredentialManager.GitProcess.CreateGitException(ChildProcess git, String message, ITrace2 trace2)
   at GitCredentialManager.GitProcessConfiguration.Enumerate(GitConfigurationLevel level, GitConfigurationEnumerationCallback cb)
   at GitCredentialManager.GitConfigurationExtensions.Enumerate(IGitConfiguration config, GitConfigurationEnumerationCallback cb)
   at GitCredentialManager.Settings.<GetSettingValues>d__6.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at GitCredentialManager.Settings.TryGetSetting(String envarName, String section, String property, String& value)
   at GitCredentialManager.Settings.GetTrace2Settings()
   at GitCredentialManager.Trace2.Initialize(DateTimeOffset startTime)
   at GitCredentialManager.Program.AppMain(Object o)
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart(Object obj)
Username for 'https://github.com':

OdysseusOperator avatar Dec 12 '24 06:12 OdysseusOperator

The issue arises due to mixing UNIX and Win32 executable using absolute paths. The native (Linux) Git creates WSL/*NIX notation (/mnt/d/code2dash_wsl/…). GCM (or its Git companion) in such a scenario only knows Win32 paths (D:/code2dash_wsl/…).

While the Exception is (just) bad error handling, the underlying issue persists. You can mitigate this by using a relative path references in /mnt/d/code2dash_wsl/test123/.git: gitdir: ../main/.git/worktrees/test123 That is also the way Git submodules handle references to their respective Git directory.

The subsequent (forward) resolution to the origin Git directory is also using relative paths (See contents of /mnt/d/code2dash_wsl/main/.git/worktrees/test123/commondir). Backward resolution of the worktree folder could still become problematic without further adjustment. But GCM luckily does not care about that. :smile:

becm avatar Jan 15 '25 16:01 becm

Starting with Git v2.48 there is now an option to use relative paths when using worktrees.

becm avatar Jan 21 '25 22:01 becm