fix(gui): recent repos keep and reopen --git-dir/--work-tree repos (#5942) - #5947
Open
yzxcj797 wants to merge 1 commit into
Open
fix(gui): recent repos keep and reopen --git-dir/--work-tree repos (#5942)#5947yzxcj797 wants to merge 1 commit into
yzxcj797 wants to merge 1 commit into
Conversation
…esseduffield#5942) A repo whose git dir does not live at <work tree>/.git — opened with --git-dir/--work-tree (yadm) or found through core.worktree (vcsh) — fell out of repo switching: newRecentReposList kept an entry only when <path>/.git existed, so the next run in any other repo dropped it; and switching cleared GIT_DIR/GIT_WORK_TREE, so VerifyInGitRepo failed even while the entry survived. AppState gains RecentRepoLocations, one entry per recently-opened repo carrying the environment needed to reopen it (empty for every repo git finds from the work tree — the same RepoLocation mechanism jesseduffield#5910 built for the in-session repo-path stack). The legacy plain-path RecentRepos list is still written in parallel with the env-less repos, so an older lazygit reading the same state file keeps working; an older file is folded into the richer list on first write. updateRecentRepoList no longer skips dotfile repos (bare repos are still skipped: there is no work tree to change back to), records the process's GIT_DIR/GIT_WORK_TREE on the entry, and the menu's OnPress routes through switchToLocation, which restores that environment before chdir and re-verifies through git. Tests: a dotfile entry survives list rebuilds with its env intact, a legacy env-less entry without .git still ages out, and the legacy-list migration prepends the current repo with empty env.
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.
Closes #5942.
The two failures, per the issue
newRecentReposListkept an entry only if<path>/.gitexists. A dotfile repo's work tree has no.git, so the next run in any other repo dropped it from the list.OnPresscalledswitchTo(path), which clearsGIT_DIR/GIT_WORK_TREEand chdirs;VerifyInGitRepothen fails because nothing at the work tree's path leads to the git dir.The root cause is exactly the gap the 2020 comment in
updateRecentRepoListdescribed:AppState.RecentReposis[]string— nowhere to remember how the repo was found. #5910'sRepoLocation.GitLocationEnvVarsprovides the mechanism; this wires the recent-repos list to it.The fix
AppStategainsRecentRepoLocations []RecentRepoLocation(pkg/config/recent_repo_location.go): one entry per recently-opened repo carrying the environment needed to reopen it — empty for every repo git finds from the work tree.updateRecentRepoListno longer skips dotfile repos — bare repos are still skipped (no work tree to change back to) — and records the process'sGIT_DIR/GIT_WORK_TREEon the entry. Directory-less entries still age out.OnPressroutes throughswitchToLocation, which restores that environment before chdir and re-verifies through git — the exact path the repo-path stack already takes.Out of scope (noted for follow-up)
The startup path (
pkg/app/app.goopenRecentRepo) still walks the legacy list — the shared verify/direnv flow there runs before the gui exists, so wiring it deserves its own change with its own testing. With this PR, the entry at least survives in state and the menu can return to the repo within a session.Tests
Three in
pkg/gui/recent_repos_panel_test.go: a dotfile entry survives list rebuilds with its env intact (and a vanished directory still ages out), a legacy env-less entry without.gitstill ages out (preserving the old contract), and the legacy-list migration prepends the current repo with empty env. (No Go toolchain on this Windows machine — the compile gate is CI; the diff uses onlyos/path/filepath/testingand existing package types.)