Git - fall back when --show-superproject-working-tree fails#317226
Open
yogeshwaran-c wants to merge 1 commit into
Open
Git - fall back when --show-superproject-working-tree fails#317226yogeshwaran-c wants to merge 1 commit into
--show-superproject-working-tree fails#317226yogeshwaran-c wants to merge 1 commit into
Conversation
Some Windows git builds (notably MSYS2 git) internally spawn an `ls-tree` helper to resolve `--show-superproject-working-tree`. When VS Code runs `git rev-parse --git-dir --git-common-dir --show-superproject-working-tree` via `cp.spawn`, that helper can fail (`fatal: ls-tree returned unexpected return code 127`) even though the same command succeeds when run from the terminal and the first two flags resolve normally. The non-zero exit causes `getRepositoryDotGit` to throw and the repository never opens. Detect this case and retry without `--show-superproject-working-tree`. Repositories now open as before; they will not be recognized as submodules in this configuration, which matches the pre-regression behavior. Fixes microsoft#260851
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression where MSYS2 git on Windows fails to open repositories because --show-superproject-working-tree spawns an ls-tree helper that errors out in VS Code's subprocess environment. The fix wraps the combined rev-parse call with a fallback that retries without the superproject flag when the initial invocation throws a GitError.
Changes:
- Extract the
rev-parse --git-dir --git-common-dir [--show-superproject-working-tree]logic into a helperrunRevParseDotGit. - On
GitError, retry without--show-superproject-working-treeso the repository still opens (at the cost of submodule detection).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #260851. When the user configures
git.pathto point at MSYS2 git on Windows, opening a folder that contains a valid.gitdirectory fails with The folder currently open doesn't have a git repository starting in 1.103. The repo was working in 1.102.3.Details
@lszomoru bisected this to 6c8a25a, which appended
--show-superproject-working-treeto the existinggit rev-parse --git-dir --git-common-dirinvocation ingetRepositoryDotGit.The user's trace log shows that when VS Code spawns MSYS2 git with the new flag, git writes
.git\n.git\nto stdout for the first two flags, but then exits with code 128 andfatal: ls-tree returned unexpected return code 127on stderr:Internally,
--show-superproject-working-treeruns anls-treehelper as a child process. When MSYS2 git is spawned by VS Code (versus run from the terminal), the subprocess environment cannot locate that helper and it fails — even though the repository has no superproject. The same command works correctly when the user runs it in the terminal.Because the non-zero exit code makes
_execthrow aGitError,getRepositoryDotGitnever returns and the repository fails to open even though--git-dirand--git-common-dirresolved correctly.This change catches the
GitErrorfrom the combined invocation and retries with just the two original flags. The superproject detection (used to classify a repo assubmoduleinRepository.kind) is best-effort; falling back to the pre-regression behavior is strictly better than failing to open the repository at all.Test plan
rev-parsecall succeeds on the first try, no retry).rev-parseitself still propagate.