mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
Refactor repo_paths.go to use git rev-parse
This changes GetRepoPaths() to pull information from `git rev-parse` instead of effectively reimplementing git's logic for pathfinding. This change fixes issues with bare repos, esp. versioned homedir use cases, by aligning lazygit's path handling to what git itself does. This change also enables lazygit to run from arbitrary subdirectories of a repository, including correct handling of symlinks, including "deep" symlinks into a repo, worktree, a repo's submodules, etc. Integration tests are now resilient against unintended side effects from the host's environment variables. Of necessity, $PATH and $TERM are the only env vars allowed through now.
This commit is contained in:
committed by
Stefan Haller
parent
74d937881e
commit
3d9f1e02e5
@ -19,6 +19,9 @@ import (
|
||||
type Shell struct {
|
||||
// working directory the shell is invoked in
|
||||
dir string
|
||||
// passed into each command
|
||||
env []string
|
||||
|
||||
// when running the shell outside the gui we can directly panic on failure,
|
||||
// but inside the gui we need to close the gui before panicking
|
||||
fail func(string)
|
||||
@ -26,14 +29,15 @@ type Shell struct {
|
||||
randomFileContentIndex int
|
||||
}
|
||||
|
||||
func NewShell(dir string, fail func(string)) *Shell {
|
||||
return &Shell{dir: dir, fail: fail}
|
||||
func NewShell(dir string, env []string, fail func(string)) *Shell {
|
||||
return &Shell{dir: dir, env: env, fail: fail}
|
||||
}
|
||||
|
||||
func (self *Shell) RunCommand(args []string) *Shell {
|
||||
return self.RunCommandWithEnv(args, []string{})
|
||||
}
|
||||
|
||||
// Run a command with additional environment variables set
|
||||
func (self *Shell) RunCommandWithEnv(args []string, env []string) *Shell {
|
||||
output, err := self.runCommandWithOutputAndEnv(args, env)
|
||||
if err != nil {
|
||||
@ -58,7 +62,7 @@ func (self *Shell) runCommandWithOutput(args []string) (string, error) {
|
||||
|
||||
func (self *Shell) runCommandWithOutputAndEnv(args []string, env []string) (string, error) {
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
cmd.Env = append(os.Environ(), env...)
|
||||
cmd.Env = append(self.env, env...)
|
||||
cmd.Dir = self.dir
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
@ -461,8 +465,8 @@ func (self *Shell) CopyFile(source string, destination string) *Shell {
|
||||
return self
|
||||
}
|
||||
|
||||
// NOTE: this only takes effect before running the test;
|
||||
// the test will still run in the original directory
|
||||
// The final value passed to Chdir() during setup
|
||||
// will be the directory the test is run from.
|
||||
func (self *Shell) Chdir(path string) *Shell {
|
||||
self.dir = filepath.Join(self.dir, path)
|
||||
|
||||
|
Reference in New Issue
Block a user