diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go index 68286b3125581f6a096eff6131a5ab1f222f635a..24b284673d47d7f9bf82e21fe3a2b1247f412ed2 100644 --- a/internal/git/command_factory.go +++ b/internal/git/command_factory.go @@ -19,7 +19,6 @@ import ( "gitlab.com/gitlab-org/gitaly/v16/internal/git/trace2hooks" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage" - "gitlab.com/gitlab-org/gitaly/v16/internal/helper/perm" "gitlab.com/gitlab-org/gitaly/v16/internal/log" "gitlab.com/gitlab-org/gitaly/v16/internal/tracing" "gitlab.com/gitlab-org/labkit/correlation" @@ -434,17 +433,6 @@ func (cf *ExecCommandFactory) GitVersion(ctx context.Context) (Version, error) { return gitVersion, nil } -// scratchDir returns a location within Gitaly's runtime directory to spawn Git processes that do -// not operate in the context of a repository. The directory is created once if it does not exist. -func (cf *ExecCommandFactory) scratchDir() (string, error) { - dir := cf.cfg.GitScratchDir() - if err := os.Mkdir(dir, perm.PrivateDir); err != nil && !errors.Is(err, os.ErrExist) { - return "", fmt.Errorf("create scratch dir: %w", err) - } - - return dir, nil -} - // newCommand creates a new command.Command for the given git command. If a repo is given, then the // 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 @@ -471,20 +459,12 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo storage.Repos } env = append(alternates.Env(repoPath, repo.GetGitObjectDirectory(), repo.GetGitAlternateObjectDirectories()), env...) - } else { - // If the Git command is running outside the context of a repo, we restrict it to a fixed scratch - // directory here. - repoPath, err = cf.scratchDir() - if err != nil { - return nil, err - } } if config.worktreePath != "" { args = append([]string{"-C", config.worktreePath}, args...) - } else { - // Ensure Git doesn't traverse upwards to find a Git repository. - env = append([]string{fmt.Sprintf("GIT_CEILING_DIRECTORIES=%s", repoPath)}, env...) + } else if repoPath != "" { + args = append([]string{"--git-dir", repoPath}, args...) } execEnv := cf.GetExecutionEnvironment(ctx) @@ -521,7 +501,6 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo storage.Repos commandOpts = append( commandOpts, - command.WithDir(repoPath), command.WithEnvironment(env), command.WithCommandName("git", sc.Name), command.WithCgroup(cf.cgroupsManager, cgroupsAddCommandOpts...), diff --git a/internal/gitaly/config/config.go b/internal/gitaly/config/config.go index 14613a2fd2e46c9d5efd83a5ea6847f3ae73ba7a..c9e228a61a4c326dc30161d8de29dfa4eec86ee5 100644 --- a/internal/gitaly/config/config.go +++ b/internal/gitaly/config/config.go @@ -944,12 +944,6 @@ func (cfg *Cfg) InternalSocketPath() string { return filepath.Join(cfg.InternalSocketDir(), "intern") } -// GitScratchDir is a fixed directory for running Git commands that don't operate -// against a repository. -func (cfg *Cfg) GitScratchDir() string { - return filepath.Join(cfg.RuntimeDir, "git-scratch") -} - func (cfg *Cfg) validateBinDir() error { if len(cfg.BinDir) == 0 { return fmt.Errorf("bin_dir: is not set") diff --git a/internal/gitaly/service/repository/fsck_test.go b/internal/gitaly/service/repository/fsck_test.go index 749c113a60e16fdc16f5316afed8f9699097ae4c..283be0d5e236db96f0c9f3f8c21dfa232d64aa20 100644 --- a/internal/gitaly/service/repository/fsck_test.go +++ b/internal/gitaly/service/repository/fsck_test.go @@ -82,7 +82,7 @@ func TestFsck(t *testing.T) { setupData := setupData{ repo: repo, requireResponse: func(actual *gitalypb.FsckResponse) { - require.Regexp(t, "(?s)^fatal: not a git repository .+\n$", string(actual.Error)) + require.Regexp(t, "^fatal: not a git repository: '.+'\n$", string(actual.Error)) }, }