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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-11-08 15:18:27 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-11-08 16:01:24 +0300
commit19593012e0beec38efce71407aa92fc9cddea775 (patch)
tree255f3f4b7c05a7e4669ff929826897e3c3dcdb23
parent55dc1422fe58525f9607c8c08e2f105be4717442 (diff)
git: Drop unused `NewWithDir()` function
The `NewWithDir()` function had been used to set up Git commands in a specific worktree. As the only caller that used this has been converted to use `WithWorktree()` instead this function is not required anymore. Remove it.
-rw-r--r--internal/git/command_factory.go20
-rw-r--r--internal/git/command_factory_test.go50
-rw-r--r--internal/git/gittest/intercepting_command_factory.go7
-rw-r--r--internal/git/gittest/intercepting_command_factory_test.go11
4 files changed, 3 insertions, 85 deletions
diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go
index 551921074..a6f0810e7 100644
--- a/internal/git/command_factory.go
+++ b/internal/git/command_factory.go
@@ -25,8 +25,6 @@ type CommandFactory interface {
New(ctx context.Context, repo repository.GitRepo, sc Cmd, opts ...CmdOpt) (*command.Command, error)
// NewWithoutRepo creates a command without a target repository.
NewWithoutRepo(ctx context.Context, sc Cmd, opts ...CmdOpt) (*command.Command, error)
- // NewWithDir creates a command without a target repository that would be executed in dir directory.
- NewWithDir(ctx context.Context, dir string, sc Cmd, opts ...CmdOpt) (*command.Command, error)
// GetExecutionEnvironment returns parameters required to execute Git commands.
GetExecutionEnvironment(context.Context) ExecutionEnvironment
// HooksPath returns the path where Gitaly's Git hooks reside.
@@ -240,23 +238,12 @@ func (cf *ExecCommandFactory) Collect(metrics chan<- prometheus.Metric) {
// New creates a new command for the repo repository.
func (cf *ExecCommandFactory) New(ctx context.Context, repo repository.GitRepo, sc Cmd, opts ...CmdOpt) (*command.Command, error) {
- return cf.newCommand(ctx, repo, "", sc, opts...)
+ return cf.newCommand(ctx, repo, sc, opts...)
}
// NewWithoutRepo creates a command without a target repository.
func (cf *ExecCommandFactory) NewWithoutRepo(ctx context.Context, sc Cmd, opts ...CmdOpt) (*command.Command, error) {
- return cf.newCommand(ctx, nil, "", sc, opts...)
-}
-
-// NewWithDir creates a new command.Command whose working directory is set
-// to dir. Arguments are validated before the command is being run. It is
-// invalid to use an empty directory.
-func (cf *ExecCommandFactory) NewWithDir(ctx context.Context, dir string, sc Cmd, opts ...CmdOpt) (*command.Command, error) {
- if dir == "" {
- return nil, errors.New("no 'dir' provided")
- }
-
- return cf.newCommand(ctx, nil, dir, sc, opts...)
+ return cf.newCommand(ctx, nil, sc, opts...)
}
// GetExecutionEnvironment returns parameters required to execute Git commands.
@@ -387,7 +374,7 @@ func (cf *ExecCommandFactory) GitVersion(ctx context.Context) (Version, error) {
// command will be run in the context of that repository. Note that this sets up arguments and
// environment variables for git, but doesn't run in the directory itself. If a directory
// is given, then the command will be run in that directory.
-func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.GitRepo, dir string, sc Cmd, opts ...CmdOpt) (*command.Command, error) {
+func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.GitRepo, sc Cmd, opts ...CmdOpt) (*command.Command, error) {
config, err := cf.combineOpts(ctx, sc, opts)
if err != nil {
return nil, err
@@ -428,7 +415,6 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.Gi
command, err := command.New(ctx, append([]string{execEnv.BinaryPath}, args...), append(
config.commandOpts,
- command.WithDir(dir),
command.WithEnvironment(env),
command.WithCommandName("git", sc.Subcommand()),
command.WithCgroup(cf.cgroupsManager, repo),
diff --git a/internal/git/command_factory_test.go b/internal/git/command_factory_test.go
index 45a2b8e2e..26b570564 100644
--- a/internal/git/command_factory_test.go
+++ b/internal/git/command_factory_test.go
@@ -97,56 +97,6 @@ func TestExecCommandFactory_globalGitConfigIgnored(t *testing.T) {
}
}
-func TestExecCommandFactory_NewWithDir(t *testing.T) {
- cfg := testcfg.Build(t)
-
- gitCmdFactory, cleanup, err := git.NewExecCommandFactory(cfg)
- require.NoError(t, err)
- defer cleanup()
-
- t.Run("no dir specified", func(t *testing.T) {
- ctx := testhelper.Context(t)
-
- _, err := gitCmdFactory.NewWithDir(ctx, "", nil, nil)
- require.Error(t, err)
- require.Contains(t, err.Error(), "no 'dir' provided")
- })
-
- t.Run("runs in dir", func(t *testing.T) {
- repoPath := testhelper.TempDir(t)
-
- gittest.Exec(t, cfg, "init", repoPath)
- gittest.Exec(t, cfg, "-C", repoPath, "commit", "--allow-empty", "-m", "initial commit")
- ctx := testhelper.Context(t)
-
- var stderr bytes.Buffer
- cmd, err := gitCmdFactory.NewWithDir(ctx, repoPath, git.SubCmd{
- Name: "rev-parse",
- Args: []string{"master"},
- }, git.WithStderr(&stderr))
- require.NoError(t, err)
-
- revData, err := io.ReadAll(cmd)
- require.NoError(t, err)
-
- require.NoError(t, cmd.Wait(), stderr.String())
-
- require.Equal(t, "99ed180822d96f70810847eba6d0d168c582258d", text.ChompBytes(revData))
- })
-
- t.Run("doesn't runs in non existing dir", func(t *testing.T) {
- ctx := testhelper.Context(t)
-
- var stderr bytes.Buffer
- _, err := gitCmdFactory.NewWithDir(ctx, "non-existing-dir", git.SubCmd{
- Name: "rev-parse",
- Args: []string{"master"},
- }, git.WithStderr(&stderr))
- require.Error(t, err)
- require.Contains(t, err.Error(), "no such file or directory")
- })
-}
-
func TestCommandFactory_ExecutionEnvironment(t *testing.T) {
testhelper.Unsetenv(t, "GITALY_TESTING_GIT_BINARY")
testhelper.Unsetenv(t, "GITALY_TESTING_BUNDLED_GIT_PATH")
diff --git a/internal/git/gittest/intercepting_command_factory.go b/internal/git/gittest/intercepting_command_factory.go
index dd9cc5e46..d4fed3a86 100644
--- a/internal/git/gittest/intercepting_command_factory.go
+++ b/internal/git/gittest/intercepting_command_factory.go
@@ -119,13 +119,6 @@ func (f *InterceptingCommandFactory) NewWithoutRepo(ctx context.Context, sc git.
)...)
}
-// NewWithDir creates a new Git command in the given directory using the intercepting script.
-func (f *InterceptingCommandFactory) NewWithDir(ctx context.Context, dir string, sc git.Cmd, opts ...git.CmdOpt) (*command.Command, error) {
- return f.interceptingCommandFactory.NewWithDir(ctx, dir, sc, append(
- opts, git.WithEnv(f.realCommandFactory.GetExecutionEnvironment(ctx).EnvironmentVariables...),
- )...)
-}
-
// GetExecutionEnvironment returns the execution environment of the intercetping command factory.
// The Git binary path will point to the intercepting script, while environment variables will
// point to the intercepted Git installation.
diff --git a/internal/git/gittest/intercepting_command_factory_test.go b/internal/git/gittest/intercepting_command_factory_test.go
index b6f332dbc..a8a8a5fd9 100644
--- a/internal/git/gittest/intercepting_command_factory_test.go
+++ b/internal/git/gittest/intercepting_command_factory_test.go
@@ -33,17 +33,6 @@ func TestInterceptingCommandFactory(t *testing.T) {
require.Equal(t, expectedString, stdout.String())
})
- t.Run("NewWithDir", func(t *testing.T) {
- var stdout bytes.Buffer
- cmd, err := factory.NewWithDir(ctx, repoPath, git.SubCmd{
- Name: "rev-parse",
- Args: []string{"something"},
- }, git.WithStdout(&stdout))
- require.NoError(t, err)
- require.NoError(t, cmd.Wait())
- require.Equal(t, expectedString, stdout.String())
- })
-
t.Run("NewWithoutRepo", func(t *testing.T) {
var stdout bytes.Buffer
cmd, err := factory.NewWithoutRepo(ctx, git.SubCmd{