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
Open
Fix startup error when .git file is a symlink (e.g. when using repo tool)#5478howettl wants to merge 1 commit intojesseduffield:masterfrom
howettl wants to merge 1 commit intojesseduffield:masterfrom
Conversation
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
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 4 |
TIP This summary will be updated as you push new changes. Give us feedback
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.
Problem
Lazygit failed immediately when opening certain repositories (e.g. Android
repotool layouts with a symlinked.gitunder.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
GetRepoPathsForDirissued onegit rev-parsewith--path-format=absoluteand 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-treeargument 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 TestGetRepoPathsmake lintmake unit-test(ifNO_COLORbreaks style tests locally, useenv -u NO_COLOR make unit-test)Manual:
Notes
git --version: 2.43.0Please check if the PR fulfills these requirements
go generate ./...) N/ACloses #5421