jesseduffield.lazygit/pkg/env/env.go
Stefan Haller 34d41b5d51 Don't let our repo answer for a different one
GIT_DIR and GIT_WORK_TREE tell git where our repo is, and every command
we run inherits them — including the ones we point at a submodule or
another worktree. git resolves those against our repo instead, and says
nothing about it: with GIT_DIR set, `git -C mysub log -1` reports the
superproject's commit. So opening lazygit with --git-dir/--work-tree
quietly broke resolving submodule conflicts, stashing and resetting a
submodule, and detaching another worktree; the worktree list came back
claiming every worktree shared our git dir.

Drop the two variables from the commands that address another repo.

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

36 lines
688 B
Go

package env
import (
"os"
)
// This package encapsulates accessing/mutating the ENV of the program.
// The variables with which git can be told where a repo is, rather than having
// it find out from the working directory.
const (
GitDirEnvVar = "GIT_DIR"
GitWorkTreeEnvVar = "GIT_WORK_TREE"
)
func GetGitDirEnv() string {
return os.Getenv(GitDirEnvVar)
}
func SetGitDirEnv(value string) {
os.Setenv(GitDirEnvVar, value)
}
func GetWorkTreeEnv() string {
return os.Getenv(GitWorkTreeEnvVar)
}
func SetWorkTreeEnv(value string) {
os.Setenv(GitWorkTreeEnvVar, value)
}
func UnsetGitLocationEnvVars() {
_ = os.Unsetenv(GitDirEnvVar)
_ = os.Unsetenv(GitWorkTreeEnvVar)
}