Repository: jesseduffield/lazygit (language: go)

Issue:
Not working properly with $GIT_DIR and $GIT_WORK_TREE environment vars
Lazygit is messed up when `$GIT_DIR` and `$GIT_WORK_TREE` is defined and *not* launched with `--git-dir` and `--work-tree` arguments.

Commits and files are displayed correctly but it's not possible to stage a file (or to run other commands), because the work-tree prefix is missing in the file's path (e.g. it tries to run `git add file` instead of `git add worktree/file` because worktree is undefined) 

The issue can be fixed by explicitly defining the arguments: `lazygit --git-dir=$GIT_DIR --work-tree=$GIT_WORK_TREE`.



Discussion / hints:
This should be an easy fix i.e. in https://github.com/jesseduffield/lazygit/blob/12bad5f45211a5177c810c5db6380291bf5b85ef/pkg/app/entry_point.go#L71 we need to Chdir to the worktree path when the CLI arg is passed or when the env var is set.

Would you be up to raising a PR for this @intrntbrn ?

Fix patch:
diff --git a/pkg/app/entry_point.go b/pkg/app/entry_point.go
index d1b573a71b9..fb19f06f6c6 100644
--- a/pkg/app/entry_point.go
+++ b/pkg/app/entry_point.go
@@ -180,10 +180,10 @@ func parseCliArgsAndEnvVars() *cliArgs {
 	useConfigDir := ""
 	flaggy.String(&useConfigDir, "ucd", "use-config-dir", "override default config directory with provided directory")
 
-	workTree := ""
+	workTree := os.Getenv("GIT_WORK_TREE")
 	flaggy.String(&workTree, "w", "work-tree", "equivalent of the --work-tree git argument")
 
-	gitDir := ""
+	gitDir := os.Getenv("GIT_DIR")
 	flaggy.String(&gitDir, "g", "git-dir", "equivalent of the --git-dir git argument")
 
 	customConfigFile := ""


Test patch: