From e1b8ef048aeb615250d7547fc828b48920ca73e8 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 8 Aug 2026 09:26:14 +0200 Subject: [PATCH] Add a worktree loader test for being in a submodule A submodule's git dir doesn't live inside its working tree, and `git worktree list` reports it by its git dir. Lazygit compares that against the working tree path, so it recognizes neither the current nor the main worktree, and the UI ends up claiming we're in a linked worktree. Co-Authored-By: Claude Opus 5 (1M context) --- .../git_commands/worktree_loader_test.go | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pkg/commands/git_commands/worktree_loader_test.go b/pkg/commands/git_commands/worktree_loader_test.go index 151f20e8c..6f612bbd9 100644 --- a/pkg/commands/git_commands/worktree_loader_test.go +++ b/pkg/commands/git_commands/worktree_loader_test.go @@ -192,6 +192,48 @@ branch refs/heads/mybranch-worktree }, expectedErr: "", }, + { + testName: "In a submodule", + repoPaths: &RepoPaths{ + repoPath: "/path/to/repo/mysubmodule", + worktreePath: "/path/to/repo/mysubmodule", + repoGitDirPath: "/path/to/repo/.git/modules/mysubmodule", + worktreeGitDirPath: "/path/to/repo/.git/modules/mysubmodule", + }, + before: func(runner *oscommands.FakeCmdObjRunner, fs afero.Fs, getRevParseArgs argFn) { + // A submodule's git dir doesn't live inside its working tree, and + // `git worktree list` reports the git dir rather than the working + // tree it belongs to. + runner.ExpectGitArgs([]string{"worktree", "list", "--porcelain"}, + `worktree /path/to/repo/.git/modules/mysubmodule +HEAD d85cc9d281fa6ae1665c68365fc70e75e82a042d +branch refs/heads/mybranch +`, + nil) + + gitArgs := append(append([]string{"-C", "/path/to/repo/.git/modules/mysubmodule"}, getRevParseArgs()...), "--absolute-git-dir") + runner.ExpectGitArgs(gitArgs, "/path/to/repo/.git/modules/mysubmodule", nil) + + _ = fs.MkdirAll("/path/to/repo/.git/modules/mysubmodule", 0o755) + }, + expectedWorktrees: []*models.Worktree{ + { + /* EXPECTED: + IsMain: true, + IsCurrent: true, + ACTUAL: */ + IsMain: false, + IsCurrent: false, + Path: "/path/to/repo/.git/modules/mysubmodule", + IsPathMissing: false, + GitDir: "/path/to/repo/.git/modules/mysubmodule", + Branch: "mybranch", + Head: "d85cc9d281fa6ae1665c68365fc70e75e82a042d", + Name: "mysubmodule", + }, + }, + expectedErr: "", + }, { testName: "Detached HEAD worktree", repoPaths: &RepoPaths{