gitkraken / vscode-gitlens

Supercharge Git inside VS Code and unlock untapped knowledge within each repository — Visualize code authorship at a glance via Git blame annotations and CodeLens, seamlessly navigate and explore Git repositories, gain valuable insights via rich visualizations and powerful comparison commands, and so much more
http://gitkraken.com/gitlens
Other
8.99k stars 1.33k forks source link

Git worktrees not recognized as git repo within dev container #2818

Open Kushalkr opened 1 year ago

Kushalkr commented 1 year ago

Description

On VSCode, opening a dev container within worktrees doesn't recognize files as part of a git repo.

Steps to reproduce

  1. Clone a repository with .devcontainer directory (I used this one)
  2. Make a worktree from the main branch using Gitlens' worktree feature using the option highlighted below (I named my worktree as test): image
  3. Switch to the test worktree (in the current window or a new one) when VScode prompts you to.
  4. Click on the bottom left to open the remote connection options and click on Reopen in Container(Note: You need Docker installed for this) as shown below: image
  5. The dev container takes a while to build. Once done open a new terminal window (Click the + on the TERMINAL tab) inside the container.
  6. Run any git command which will give you the following error: image

GitLens Version

14.1.1

VS Code Version

Version: 1.80.1 (Universal) Commit: 74f6148eb9ea00507ec113ec51c489d6ffb4b771 Date: 2023-07-12T17:20:23.298Z Electron: 22.3.14 ElectronBuildId: 21893604 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Darwin x64 22.5.0

Git Version

git version 2.34.1

Logs, Screenshots, Screen Captures, etc

Logs attached gitlens_git.log gitlens.log

eamodio commented 1 year ago

Can you please add more detail as to the issue you are experiencing and/or the steps to reproduce it?

Also, if this issue is reproducible, can you please enable debug logging by running from GitLens: Enable Debug Logging from the Command Palette (F1 or ctrl/cmd+shift+p). This will enable logging to the GitLens and GitLens (Git) channel in the Output pane.

Once enabled, please reproduce the issue, and attach the log from the both GitLens and GitLens (Git) channels.

Thank you!

Kushalkr commented 1 year ago

Hello! Thank you for reaching out! I've update the description and included some steps to reproduce. Hope this helps!

mp-chet commented 4 months ago

I've just encountered the same problem in my setup. This is not a bug in GitLens but in the user's devcontainer configuration. In order for Git (and, by extension, GitLens) to work correctly, both the worktree and the original working copy must be mounted into the devcontainer.

That's because the .git file inside the worktree refers to a path under the original working copy. If Git is unable to access that path, it cannot find the associated repository metadata.

pedromsfernandes commented 2 months ago

I am having exactly the same problem. @mp-chet, your explanation makes sense. Did you manage to make it work by editing the devcontainer?

mp-chet commented 2 months ago

For my specific use case, I decided to clone a separate working copy after all.

I made that choice because it would feel wrong to commit a highly user-specific bit of devcontainer configuration into a shared Git repository used by many other people. Unfortunately, devcontainer config files are not composable...

pedromsfernandes commented 2 months ago

Yeah, fair point. For what it's worth, I found this feature request in the devcontainers repo. Let's hope it's picked up: devcontainers/cli#796