Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Include proxy env variables in git operations if set #1556

Merged
merged 3 commits into from
Dec 3, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow certain env variables to be inherited from the os
For now the allowed env variables are only those required by git to
work behind a HTTP(S) proxy (`HTTP_PROXY, `HTTPS_PROXY and `NO_PROXY`).

Signed-off-by: Hidde Beydals <hello@hidde.co>
  • Loading branch information
hiddeco committed Nov 25, 2018
commit eb371a249c7738b02c0108d4f296385ef71c0780
17 changes: 16 additions & 1 deletion git/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"strings"

Expand All @@ -18,6 +19,9 @@ import (
// If true, every git invocation will be echoed to stdout
const trace = false

// Env vars that are allowed to be inherited from the os
var allowedEnvVars = []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"}

func config(ctx context.Context, workingDir, user, email string) error {
for k, v := range map[string]string{
"user.name": user,
Expand Down Expand Up @@ -289,7 +293,18 @@ func execGitCmd(ctx context.Context, dir string, out io.Writer, args ...string)
}

func env() []string {
return []string{"GIT_TERMINAL_PROMPT=0"}
env := []string{"GIT_TERMINAL_PROMPT=0"}

// include allowed env vars from os
for _, k := range allowedEnvVars {
v, ex := os.LookupEnv(k)
if ex == false {
continue
}
env = append(env, k+"="+v)
}
hiddeco marked this conversation as resolved.
Show resolved Hide resolved

return env
}

// check returns true if there are changes locally.
Expand Down