diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-01-13 15:33:56 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-01-14 09:46:55 +0300 |
commit | c493db4a247c18c125aa5eca7758bf863f4bd6e5 (patch) | |
tree | 47462b4e0eea0b2ee1402a49ce27c6b22ba40cbe | |
parent | 2dae9653551e40bfb4406ed9c928a5419e096e42 (diff) |
git: Drop unused SafeCmdWithEnv() function
The `git.SafeCmdWithEnv()` function is not used anymore, so let's drop
it.
-rw-r--r-- | internal/git/command.go | 4 | ||||
-rw-r--r-- | internal/git/hooks_options_test.go | 6 | ||||
-rw-r--r-- | internal/git/safecmd.go | 8 | ||||
-rw-r--r-- | internal/git/safecmd_test.go | 33 |
4 files changed, 3 insertions, 48 deletions
diff --git a/internal/git/command.go b/internal/git/command.go index 72a7f8516..b3e5e9719 100644 --- a/internal/git/command.go +++ b/internal/git/command.go @@ -34,8 +34,8 @@ func (cf *CommandFactory) gitPath() string { return cf.cfg.Git.BinPath } -// unsafeCmdWithEnv creates a git.unsafeCmd with the given args, environment, and Repository -func (cf *CommandFactory) unsafeCmdWithEnv(ctx context.Context, extraEnv []string, stream cmdStream, repo repository.GitRepo, args ...string) (*command.Command, error) { +// unsafeCmd creates a git.unsafeCmd with the given args, environment, and Repository +func (cf *CommandFactory) unsafeCmd(ctx context.Context, extraEnv []string, stream cmdStream, repo repository.GitRepo, args ...string) (*command.Command, error) { args, env, err := cf.argsAndEnv(repo, args...) if err != nil { return nil, err diff --git a/internal/git/hooks_options_test.go b/internal/git/hooks_options_test.go index 4117d4c1e..a1ff757c7 100644 --- a/internal/git/hooks_options_test.go +++ b/internal/git/hooks_options_test.go @@ -35,12 +35,6 @@ func TestWithRefHook(t *testing.T) { }, }, { - name: "SafeCmdWithEnv", - fn: func() (*command.Command, error) { - return SafeCmdWithEnv(ctx, nil, testRepo, nil, subCmd, opt) - }, - }, - { name: "SafeStdinCmd", fn: func() (*command.Command, error) { return SafeStdinCmd(ctx, testRepo, nil, subCmd, opt) diff --git a/internal/git/safecmd.go b/internal/git/safecmd.go index 045bd845f..af3536413 100644 --- a/internal/git/safecmd.go +++ b/internal/git/safecmd.go @@ -355,12 +355,6 @@ func handleOpts(ctx context.Context, sc Cmd, cc *cmdCfg, opts []CmdOpt) error { // SafeCmd creates a command.Command with the given args and Repository. It // validates the arguments in the command before executing. func SafeCmd(ctx context.Context, repo repository.GitRepo, globals []GlobalOption, sc Cmd, opts ...CmdOpt) (*command.Command, error) { - return SafeCmdWithEnv(ctx, nil, repo, globals, sc, opts...) -} - -// SafeCmdWithEnv creates a command.Command with the given args, environment, and Repository. It -// validates the arguments in the command before executing. -func SafeCmdWithEnv(ctx context.Context, env []string, repo repository.GitRepo, globals []GlobalOption, sc Cmd, opts ...CmdOpt) (*command.Command, error) { cc := &cmdCfg{} if err := handleOpts(ctx, sc, cc, opts); err != nil { @@ -372,7 +366,7 @@ func SafeCmdWithEnv(ctx context.Context, env []string, repo repository.GitRepo, return nil, err } - return NewCommandFactory().unsafeCmdWithEnv(ctx, append(env, cc.env...), cmdStream{ + return NewCommandFactory().unsafeCmd(ctx, cc.env, cmdStream{ In: cc.stdin, Out: cc.stdout, Err: cc.stderr, diff --git a/internal/git/safecmd_test.go b/internal/git/safecmd_test.go index 95a9d509a..4c39aae44 100644 --- a/internal/git/safecmd_test.go +++ b/internal/git/safecmd_test.go @@ -340,11 +340,6 @@ func TestSafeCmdValid(t *testing.T) { // ignore first 3 indeterministic args (executable path and repo args) require.Equal(t, tt.expectArgs, cmd.Args()[3:]) - cmd, err = SafeCmdWithEnv(ctx, nil, testRepo, tt.globals, tt.subCmd, opts...) - require.NoError(t, err) - // ignore first 3 indeterministic args (executable path and repo args) - require.Equal(t, tt.expectArgs, cmd.Args()[3:]) - cmd, err = SafeStdinCmd(ctx, testRepo, tt.globals, tt.subCmd, opts...) require.NoError(t, err) require.Equal(t, tt.expectArgs, cmd.Args()[3:]) @@ -365,34 +360,6 @@ func TestSafeCmdValid(t *testing.T) { } } -func TestSafeCmdWithEnv(t *testing.T) { - testRepo, _, cleanup := testhelper.NewTestRepo(t) - defer cleanup() - - ctx, cancel := testhelper.Context() - defer cancel() - - reenableGitCmd := disableGitCmd() - defer reenableGitCmd() - - globals := []GlobalOption{ - Flag{Name: "--aaaa-bbbb"}, - } - - subCmd := SubCmd{Name: "update-ref"} - endOfOptions := "--end-of-options" - expectArgs := []string{"-c", "core.hooksPath=" + hooks.Path(config.Config), "--aaaa-bbbb", "update-ref", endOfOptions} - - env := []string{"TEST_VAR1=1", "TEST_VAR2=2"} - - opts := []CmdOpt{WithRefTxHook(ctx, &gitalypb.Repository{}, config.Config)} - cmd, err := SafeCmdWithEnv(ctx, env, testRepo, globals, subCmd, opts...) - require.NoError(t, err) - // ignore first 3 indeterministic args (executable path and repo args) - require.Equal(t, expectArgs, cmd.Args()[3:]) - require.Subset(t, cmd.Env(), env) -} - func disableGitCmd() testhelper.Cleanup { oldBinPath := config.Config.Git.BinPath config.Config.Git.BinPath = "/bin/echo" |