Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2017-08-31 02:35:43 +0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2017-08-31 02:35:43 +0300
commiteef6a88c6add094c6af83f4f164311d3dbbfbfb1 (patch)
tree1963e2f1534771e53d72f21d1d966e78f4c641f1
parentda3303ce30284d688b993abed51a3ba7e7d93cb7 (diff)
parent8beef3284f2fc754289bc3c9f18376dfac7ebb6a (diff)
Merge branch 'fix-command-env' into 'master'
Restore support for custom environment variables See merge request !319
-rw-r--r--CHANGELOG.md2
-rw-r--r--internal/helper/command.go6
-rw-r--r--internal/helper/command_test.go38
3 files changed, 24 insertions, 22 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1b24a7c3e..827c70c51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ UNRELEASED
https://gitlab.com/gitlab-org/gitaly/merge_requests/312
- Use bufio.Reader instead of bufio.Scanner for lines.Send
https://gitlab.com/gitlab-org/gitaly/merge_requests/303
+- Restore support for custom environment variables
+ https://gitlab.com/gitlab-org/gitaly/merge_requests/319
v0.34.0
diff --git a/internal/helper/command.go b/internal/helper/command.go
index 06b9a59e3..10a8e436b 100644
--- a/internal/helper/command.go
+++ b/internal/helper/command.go
@@ -82,12 +82,10 @@ func NewCommand(ctx context.Context, cmd *exec.Cmd, stdin io.Reader, stdout, std
command := &Command{Cmd: cmd, startTime: time.Now(), context: ctx}
// Explicitly set the environment for the command
- cmd.Env = []string{
- "GIT_TERMINAL_PROMPT=0",
- }
+ env = append(env, "GIT_TERMINAL_PROMPT=0")
// Export env vars
- cmd.Env = exportEnvironment(cmd.Env)
+ cmd.Env = exportEnvironment(env)
if dir, ok := objectdirhandler.ObjectDir(ctx); ok {
cmd.Env = append(cmd.Env, fmt.Sprintf("GIT_OBJECT_DIRECTORY=%s", dir))
diff --git a/internal/helper/command_test.go b/internal/helper/command_test.go
index 574d001f2..25ddc7491 100644
--- a/internal/helper/command_test.go
+++ b/internal/helper/command_test.go
@@ -5,10 +5,13 @@ import (
"context"
"os"
"os/exec"
+ "strings"
"testing"
+
+ "github.com/stretchr/testify/require"
)
-func TestNewCommand_Env(t *testing.T) {
+func TestNewCommandTZEnv(t *testing.T) {
oldTZ := os.Getenv("TZ")
defer os.Setenv("TZ", oldTZ)
@@ -16,21 +19,20 @@ func TestNewCommand_Env(t *testing.T) {
buff := &bytes.Buffer{}
cmd, err := NewCommand(context.Background(), exec.Command("env"), nil, buff, nil)
- if err != nil {
- t.Fatal(err)
- }
- if err = cmd.Wait(); err != nil {
- t.Fatal(err)
- }
-
- found := false
- split := bytes.Split(buff.Bytes(), []byte("\n"))
- for _, line := range split {
- if bytes.Compare(line, []byte("TZ=foobar")) == 0 {
- found = true
- }
- }
- if !found {
- t.Errorf("TZ not set to `foobar`")
- }
+
+ require.NoError(t, err)
+ require.NoError(t, cmd.Wait())
+
+ require.Contains(t, strings.Split(buff.String(), "\n"), "TZ=foobar")
+}
+
+func TestNewCommandExtraEnv(t *testing.T) {
+ extraVar := "FOOBAR=123456"
+ buff := &bytes.Buffer{}
+ cmd, err := NewCommand(context.Background(), exec.Command("/usr/bin/env"), nil, buff, nil, extraVar)
+
+ require.NoError(t, err)
+ require.NoError(t, cmd.Wait())
+
+ require.Contains(t, strings.Split(buff.String(), "\n"), extraVar)
}