Skip to content

Commit

Permalink
Forward complete environment when running git
Browse files Browse the repository at this point in the history
Prevents errors when some git hooks depend on environment variables

Fixes #108
  • Loading branch information
chriscz authored and ejoffe committed Oct 14, 2021
1 parent a7e6992 commit 38576f6
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions git/realgit/realcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,13 @@ func (c *gitcmd) GitWithEditor(argStr string, output *string, editorCmd string)
args := strings.Split(argStr, " ")
cmd := exec.Command("git", args...)
cmd.Dir = c.rootdir
envVarsToDerive := []string{
"SSH_AUTH_SOCK",
"SSH_AGENT_PID",
"HOME",
"XDG_CONFIG_HOME",
}

cmd.Env = []string{fmt.Sprintf("EDITOR=%s", editorCmd)}
for _, env := range envVarsToDerive {
envval := os.Getenv(env)
if envval != "" {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", env, envval))
for _, env := range os.Environ() {
parts := strings.SplitN(env, "=", 2)

if parts[1] != "" && strings.ToUpper(parts[0]) != "EDITOR" {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", parts[0], parts[1]))
}
}

Expand Down

0 comments on commit 38576f6

Please sign in to comment.