Fix escape from submodule when repo was opened with --git-dir/--work-tree - #5904
Open
xooooooooox wants to merge 1 commit into
Open
Fix escape from submodule when repo was opened with --git-dir/--work-tree#5904xooooooooox wants to merge 1 commit into
xooooooooox wants to merge 1 commit into
Conversation
Entering a submodule clears the GIT_DIR/GIT_WORK_TREE env vars, but returning only restored the working directory. For repos opened via --git-dir/--work-tree (dotfile-style bare repos, e.g. yadm/vcsh), the parent repo's git dir cannot be rediscovered from the path alone, so escape failed with 'not a git repository' -- or silently switched to an enclosing repo when one existed above the worktree. The repo-path stack now records the env vars alongside the path (StringStack generalized to Stack[RepoLocation]), and switching back restores them. Failed switches restore the previous env vars so the repo we stay in keeps working. Fixes jesseduffield#1118
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.
PR Description
Fixes #1118.
When lazygit is opened against a dotfile-style bare repo via
--git-dir/--work-tree(the yadm/vcsh setup), entering a submodule and pressing escape failed to return to the parent repo:Root cause: the
--git-dir/--work-treeflags only survive as theGIT_DIR/GIT_WORK_TREEenv vars. Entering a submodule clears them (correctly — the submodule must not be read through the parent's git dir), but the repo-path stack records only the working directory, so escaping restores the cwd and nothing else.VerifyInGitRepothen runsgit rev-parsein a worktree whose git dir cannot be discovered from the path alone. Worse, if there happens to be a repo somewhere above the worktree, escape silently switches to that (wrong) repo instead of erroring.Fix: the repo-path stack now stores the location the repo was opened with — path plus the two env vars (
StringStackgeneralized toStack[RepoLocation]) — and switching back restores them. All other switch paths (recent repos, worktrees) keep the existing cleared-env semantics. A failed switch now also restores the previous env vars, so the repo we stay in keeps working.Normal repos push empty env fields (restore == clear), so behavior is unchanged outside the bare-repo case; nested submodules likewise.
Test: new integration test
submodule/enter_dotfile_bare_reporeproduces the bug on master (in the test sandbox it manifests as the silent wrong-repo switch, since the sandbox lives inside an enclosing repo) and passes with the fix.Please check if the PR fulfills these requirements
go generate ./...)