Skip to content

fix(gui): recent repos keep and reopen --git-dir/--work-tree repos (#5942) - #5947

Open
yzxcj797 wants to merge 1 commit into
jesseduffield:masterfrom
yzxcj797:fix/recent-repos-dotfile-5942
Open

fix(gui): recent repos keep and reopen --git-dir/--work-tree repos (#5942)#5947
yzxcj797 wants to merge 1 commit into
jesseduffield:masterfrom
yzxcj797:fix/recent-repos-dotfile-5942

Conversation

@yzxcj797

Copy link
Copy Markdown

Closes #5942.

The two failures, per the issue

  1. The entry disappears from the menu. newRecentReposList kept an entry only if <path>/.git exists. A dotfile repo's work tree has no .git, so the next run in any other repo dropped it from the list.
  2. Even while the entry survives, switching fails. The menu's OnPress called switchTo(path), which clears GIT_DIR/GIT_WORK_TREE and chdirs; VerifyInGitRepo then 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 updateRecentRepoList described: AppState.RecentRepos is []string — nowhere to remember how the repo was found. #5910's RepoLocation.GitLocationEnvVars provides the mechanism; this wires the recent-repos list to it.

The fix

  • AppState gains RecentRepoLocations []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.
  • The legacy plain-path list is still written in parallel with the env-less repos, so an older lazygit reading the same state file keeps working (rollback-safe); a state file last written by an older version is folded into the richer list on first write.
  • updateRecentRepoList no longer skips dotfile repos — bare repos are still skipped (no work tree to change back to) — and records the process's GIT_DIR/GIT_WORK_TREE on the entry. Directory-less entries still age out.
  • The menu's OnPress routes through switchToLocation, 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.go openRecentRepo) 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 .git still 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 only os/path/filepath/testing and existing package types.)

…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.
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.

Recent repos menu can't return to a repo opened with --git-dir/--work-tree (dotfile repos)

1 participant