mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
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>
36 lines
688 B
Go
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)
|
|
}
|