Skip to content

Fix startup error when .git file is a symlink (e.g. when using repo tool)#5478

Open
howettl wants to merge 1 commit intojesseduffield:masterfrom
howettl:feature/crash-at-launch-using-repo
Open

Fix startup error when .git file is a symlink (e.g. when using repo tool)#5478
howettl wants to merge 1 commit intojesseduffield:masterfrom
howettl:feature/crash-at-launch-using-repo

Conversation

@howettl
Copy link
Copy Markdown

@howettl howettl commented Apr 6, 2026

Problem

Lazygit failed immediately when opening certain repositories (e.g. Android repo tool layouts with a symlinked .git under .repo/projects/...). The process exited with:

Error getting repo paths: 'git ... rev-parse ... --show-superproject-working-tree' failed: ... BUG: submodule.c:2455: returned path string doesn't match cwd?

Cause

GetRepoPathsForDir issued one git rev-parse with --path-format=absolute and the following arguments: --show-toplevel, --absolute-git-dir, --git-common-dir, --is-bare-repository, and --show-superproject-working-tree.

In this class of checkouts (worktree in one place, git dir elsewhere, e.g. repo tool), combining the superproject flag with the path flags can make Git abort the entire invocation with BUG: submodule.c:2455, so lazygit never receives the four lines needed for basic path resolution.

Solution

Make two separate calls to rev-parse. The first one omits the --show-superproject-working-tree argument and allows us to capture the info needed for basic path resolution.

The second call exclusively passes --show-superproject-working-tree, and we can handle an error output here appropriately, by falling back to the non-submodule rule (filepath.Dir(repoGitDirPath)).

Testing

  • go test ./pkg/commands/git_commands/ -run TestGetRepoPaths
  • make lint
  • make unit-test (if NO_COLOR breaks style tests locally, use
    env -u NO_COLOR make unit-test)

Manual:

  • opened lazygit directly into a submodule
  • opened lazygit to a parent repository and internally navigated into a submodule
  • opened lazygit with a "standard" git layout (no symlink'd .git file)
  • opened lazygit with a repo clone that uses a symlink'd .git

Notes

git --version: 2.43.0

Please check if the PR fulfills these requirements

  • [x ] Cheatsheets are up-to-date (run go generate ./...) N/A
  • [ x] Code has been formatted (see here)
  • [x ] Tests have been added/updated (see here for the integration test guide)
  • [x ] Text is internationalised (see here) N/A
  • [x ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see here) N/A
  • [x ] Docs have been updated if necessary N/A
  • [x ] You've read through your own file changes for silly mistakes etc

Closes #5421

GetRepoPathsForDir used one rev-parse with --show-superproject-working-tree
together with the path flags. In checkouts such as Android repo tool (symlinked
.git under .repo/projects/...), Git can abort that entire invocation with
BUG: submodule.c:2455, so lazygit never gets the worktree / git-dir lines.

Run the superproject query in a second rev-parse. If it errors or returns empty
output, treat the checkout as non-submodule for repoPath (parent of git common
dir). Add a unit test for the superproject failure fallback.

Made-with: Cursor
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 4 duplication

Metric Results
Complexity 0
Duplication 4

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

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.

Error at launch with symlink .git file

1 participant