Files
Stefan HallerandClaude Opus 5 f141fcc570 Open the repo when lazygit is started in its .git dir
Running lazygit in a .git dir got you told you were in a bare repo,
which you weren't: the worktree was sitting right there, one directory
up. git's own convention is that a git dir called .git belongs to the
directory holding it — that's how `git worktree list` names the main
worktree — so ask that directory, and if it is a worktree, open the repo
we were really being asked about.

The git dirs that aren't called .git keep the answer they had. A linked
worktree's and a submodule's do have a worktree, but nothing we look at
says where, so we would be guessing; a bare repo's has none to find.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 11:15:01 +02:00

35 lines
896 B
Go

package misc
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var StartInGitDir = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Start lazygit in a repo's .git dir, and have it open the repo",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(cfg *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.CreateFileAndAdd("blah", "original content\n")
shell.Commit("initial commit")
shell.UpdateFile("blah", "updated content\n")
// this is where lazygit will start
shell.Chdir(".git")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Commits().
Lines(
Contains("initial commit"),
)
// we're in the work tree the .git belongs to, not in the .git itself
t.Views().Files().
IsFocused().
Lines(
Contains(" M blah"),
)
},
})