Skip to content

Git - fall back when --show-superproject-working-tree fails#317226

Open
yogeshwaran-c wants to merge 1 commit into
microsoft:mainfrom
yogeshwaran-c:fix/git-msys2-superproject-260851
Open

Git - fall back when --show-superproject-working-tree fails#317226
yogeshwaran-c wants to merge 1 commit into
microsoft:mainfrom
yogeshwaran-c:fix/git-msys2-superproject-260851

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

Summary

Fixes #260851. When the user configures git.path to point at MSYS2 git on Windows, opening a folder that contains a valid .git directory 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-tree to the existing git rev-parse --git-dir --git-common-dir invocation in getRepositoryDotGit.

The user's trace log shows that when VS Code spawns MSYS2 git with the new flag, git writes .git\n.git\n to stdout for the first two flags, but then exits with code 128 and fatal: ls-tree returned unexpected return code 127 on stderr:

> git rev-parse --git-dir --git-common-dir --show-superproject-working-tree [65ms]
fatal: ls-tree returned unexpected return code 127
Error:Failed to execute git {
  "exitCode": 128,
  "gitCommand": "rev-parse",
  "stdout": ".git\n.git\n",
  "stderr": "fatal: ls-tree returned unexpected return code 127\n"
}

Internally, --show-superproject-working-tree runs an ls-tree helper 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 _exec throw a GitError, getRepositoryDotGit never returns and the repository fails to open even though --git-dir and --git-common-dir resolved correctly.

This change catches the GitError from the combined invocation and retries with just the two original flags. The superproject detection (used to classify a repo as submodule in Repository.kind) is best-effort; falling back to the pre-regression behavior is strictly better than failing to open the repository at all.

Test plan

  • On a non-affected platform, repository opens unchanged (the combined rev-parse call succeeds on the first try, no retry).
  • When the combined call throws, the fallback retry executes and uses the resulting stdout.
  • Errors from the fallback rev-parse itself still propagate.
  • User with MSYS2 git on Windows confirms that opening a repository now succeeds (cannot reproduce locally without MSYS2 git on Windows).

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
Copilot AI review requested due to automatic review settings May 19, 2026 01:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 helper runRevParseDotGit.
  • On GitError, retry without --show-superproject-working-tree so the repository still opens (at the cost of submodule detection).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for MSYS2 Git breaks in version 1.103 (The folder currently open doesn't have a git repository)

3 participants