diff options
68 files changed, 110 insertions, 110 deletions
diff --git a/doc/serverside_git_usage.md b/doc/serverside_git_usage.md index a3d36e7c7..dafa58993 100644 --- a/doc/serverside_git_usage.md +++ b/doc/serverside_git_usage.md @@ -33,7 +33,7 @@ altered. #### Executing Git commands -When executing Git, developers should always use the `git.SafeCmd()` and sibling +When executing Git, developers should always use the `git.NewCommand()` and sibling interfaces. These make sure Gitaly is protected against command injection, the correct `git` is used, and correct setup for observable command invocations are used. When working with `git(1)` in Ruby, please be sure to read the diff --git a/internal/git/catfile/batch.go b/internal/git/catfile/batch.go index 772e01f06..fe52ed339 100644 --- a/internal/git/catfile/batch.go +++ b/internal/git/catfile/batch.go @@ -46,7 +46,7 @@ func newBatchProcess(ctx context.Context, locator storage.Locator, repo reposito ctx = correlation.ContextWithCorrelation(ctx, "") ctx = opentracing.ContextWithSpan(ctx, nil) - batchCmd, err := git.SafeCmd(ctx, repo, nil, + batchCmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "cat-file", Flags: []git.Option{ diff --git a/internal/git/catfile/batchcheck.go b/internal/git/catfile/batchcheck.go index 261b50a6f..8c2a8d8d3 100644 --- a/internal/git/catfile/batchcheck.go +++ b/internal/git/catfile/batchcheck.go @@ -32,7 +32,7 @@ func newBatchCheck(ctx context.Context, locator storage.Locator, repo repository ctx = correlation.ContextWithCorrelation(ctx, "") ctx = opentracing.ContextWithSpan(ctx, nil) - batchCmd, err := git.SafeCmd(ctx, repo, nil, + batchCmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "cat-file", Flags: []git.Option{ diff --git a/internal/git/config.go b/internal/git/config.go index fefa597cb..3e497c63e 100644 --- a/internal/git/config.go +++ b/internal/git/config.go @@ -80,7 +80,7 @@ func (repo RepositoryConfig) Add(ctx context.Context, name, value string, opts C return err } - cmd, err := SafeCmd(ctx, repo.repo, nil, SubCmd{ + cmd, err := NewCommand(ctx, repo.repo, nil, SubCmd{ Name: "config", Flags: append(opts.buildFlags(), Flag{Name: "--add"}), Args: []string{name, value}, @@ -148,7 +148,7 @@ func (repo RepositoryConfig) GetRegexp(ctx context.Context, nameRegexp string, o func (repo RepositoryConfig) getRegexp(ctx context.Context, nameRegexp string, opts ConfigGetRegexpOpts) ([]byte, error) { var stderr bytes.Buffer - cmd, err := SafeCmd(ctx, repo.repo, nil, + cmd, err := NewCommand(ctx, repo.repo, nil, SubCmd{ Name: "config", // '--null' is used to support proper parsing of the multiline config values @@ -250,7 +250,7 @@ func (opts ConfigUnsetOpts) buildFlags() []Option { } func (repo RepositoryConfig) Unset(ctx context.Context, name string, opts ConfigUnsetOpts) error { - cmd, err := SafeCmd(ctx, repo.repo, nil, SubCmd{ + cmd, err := NewCommand(ctx, repo.repo, nil, SubCmd{ Name: "config", Flags: opts.buildFlags(), Args: []string{name}, diff --git a/internal/git/hooks_options_test.go b/internal/git/hooks_options_test.go index feeee4a63..c41940d86 100644 --- a/internal/git/hooks_options_test.go +++ b/internal/git/hooks_options_test.go @@ -29,9 +29,9 @@ func TestWithRefHook(t *testing.T) { fn func() (*command.Command, error) }{ { - name: "SafeCmd", + name: "NewCommand", fn: func() (*command.Command, error) { - return SafeCmd(ctx, testRepo, nil, subCmd, opt) + return NewCommand(ctx, testRepo, nil, subCmd, opt) }, }, } { diff --git a/internal/git/log/commit.go b/internal/git/log/commit.go index 8653f0323..2e3032e80 100644 --- a/internal/git/log/commit.go +++ b/internal/git/log/commit.go @@ -62,7 +62,7 @@ func GetCommitCatfileWithTrailers(ctx context.Context, repo *gitalypb.Repository // We use the commit ID here instead of revision. This way we still get // trailers if the revision is not a SHA but e.g. a tag name. - showCmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + showCmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "show", Args: []string{commit.Id}, Flags: []git.Option{ diff --git a/internal/git/log/last_commit.go b/internal/git/log/last_commit.go index 4cc596618..fdbb9611c 100644 --- a/internal/git/log/last_commit.go +++ b/internal/git/log/last_commit.go @@ -13,7 +13,7 @@ import ( // LastCommitForPath returns the last commit which modified path. func LastCommitForPath(ctx context.Context, batch catfile.Batch, repo *gitalypb.Repository, revision string, path string, options *gitalypb.GlobalOptions) (*gitalypb.GitCommit, error) { - cmd, err := git.SafeCmd(ctx, repo, git.ConvertGlobalOptions(options), git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, git.ConvertGlobalOptions(options), git.SubCmd{ Name: "log", Flags: []git.Option{git.Flag{Name: "--format=%H"}, git.Flag{Name: "--max-count=1"}}, Args: []string{revision}, @@ -32,7 +32,7 @@ func LastCommitForPath(ctx context.Context, batch catfile.Batch, repo *gitalypb. // GitLogCommand returns a Command that executes git log with the given the arguments func GitLogCommand(ctx context.Context, repo *gitalypb.Repository, revisions []string, paths []string, options *gitalypb.GlobalOptions, extraArgs ...git.Option) (*command.Command, error) { - return git.SafeCmd(ctx, repo, git.ConvertGlobalOptions(options), git.SubCmd{ + return git.NewCommand(ctx, repo, git.ConvertGlobalOptions(options), git.SubCmd{ Name: "log", Flags: append([]git.Option{git.Flag{Name: "--pretty=%H"}}, extraArgs...), Args: revisions, diff --git a/internal/git/objectpool/fetch.go b/internal/git/objectpool/fetch.go index 48f8c3df3..ea49c223c 100644 --- a/internal/git/objectpool/fetch.go +++ b/internal/git/objectpool/fetch.go @@ -50,7 +50,7 @@ func (o *ObjectPool) FetchFromOrigin(ctx context.Context, origin *gitalypb.Repos git.WithDisabledHooks(), } - getRemotes, err := git.SafeCmd(ctx, o, nil, git.SubCmd{Name: "remote"}, opts...) + getRemotes, err := git.NewCommand(ctx, o, nil, git.SubCmd{Name: "remote"}, opts...) if err != nil { return err } @@ -69,7 +69,7 @@ func (o *ObjectPool) FetchFromOrigin(ctx context.Context, origin *gitalypb.Repos var setOriginCmd *command.Command if originExists { - setOriginCmd, err = git.SafeCmd(ctx, o, nil, git.SubCmd{ + setOriginCmd, err = git.NewCommand(ctx, o, nil, git.SubCmd{ Name: "remote", Args: []string{"set-url", sourceRemote, originPath}, }, opts...) @@ -77,7 +77,7 @@ func (o *ObjectPool) FetchFromOrigin(ctx context.Context, origin *gitalypb.Repos return err } } else { - setOriginCmd, err = git.SafeCmd(ctx, o, nil, git.SubCmd{ + setOriginCmd, err = git.NewCommand(ctx, o, nil, git.SubCmd{ Name: "remote", Args: []string{"add", sourceRemote, originPath}, }, opts...) @@ -95,7 +95,7 @@ func (o *ObjectPool) FetchFromOrigin(ctx context.Context, origin *gitalypb.Repos } refSpec := fmt.Sprintf("+refs/*:%s/*", sourceRefNamespace) - fetchCmd, err := git.SafeCmd(ctx, o, nil, + fetchCmd, err := git.NewCommand(ctx, o, nil, git.SubCmd{ Name: "fetch", Flags: []git.Option{git.Flag{Name: "--quiet"}}, @@ -119,7 +119,7 @@ func (o *ObjectPool) FetchFromOrigin(ctx context.Context, origin *gitalypb.Repos return err } - packRefs, err := git.SafeCmd(ctx, o, nil, git.SubCmd{ + packRefs, err := git.NewCommand(ctx, o, nil, git.SubCmd{ Name: "pack-refs", Flags: []git.Option{git.Flag{Name: "--all"}}, }) @@ -144,7 +144,7 @@ const danglingObjectNamespace = "refs/dangling" // an object is still used anywhere, so the only safe thing to do is to // assume that every object _is_ used. func rescueDanglingObjects(ctx context.Context, repo repository.GitRepo) error { - fsck, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + fsck, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "fsck", Flags: []git.Option{git.Flag{Name: "--connectivity-only"}, git.Flag{Name: "--dangling"}}, }) @@ -193,7 +193,7 @@ func repackPool(ctx context.Context, pool repository.GitRepo) error { git.ConfigPair{Key: "pack.writeBitmapHashCache", Value: "true"}, } - repackCmd, err := git.SafeCmd(ctx, pool, repackArgs, git.SubCmd{ + repackCmd, err := git.NewCommand(ctx, pool, repackArgs, git.SubCmd{ Name: "repack", Flags: []git.Option{git.Flag{Name: "-aidb"}}, }) @@ -224,7 +224,7 @@ func (o *ObjectPool) logStats(ctx context.Context, when string) error { } } - forEachRef, err := git.SafeCmd(ctx, o, nil, git.SubCmd{ + forEachRef, err := git.NewCommand(ctx, o, nil, git.SubCmd{ Name: "for-each-ref", Flags: []git.Option{git.Flag{Name: "--format=%(objecttype)"}}, Args: []string{danglingObjectNamespace}, diff --git a/internal/git/objectpool/link.go b/internal/git/objectpool/link.go index 22a5c75e5..36b4907be 100644 --- a/internal/git/objectpool/link.go +++ b/internal/git/objectpool/link.go @@ -185,7 +185,7 @@ func (o *ObjectPool) Unlink(ctx context.Context, repo *gitalypb.Repository) erro // this function not suitable for general usage, and scoped to this package. // To be corrected in: https://gitlab.com/gitlab-org/gitaly/issues/1430 func (o *ObjectPool) setConfig(ctx context.Context, key, value string) error { - cmd, err := git.SafeCmd(ctx, o, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, o, nil, git.SubCmd{ Name: "config", Flags: []git.Option{git.ConfigPair{Key: key, Value: value}}, }) diff --git a/internal/git/remote.go b/internal/git/remote.go index 4026a3a01..db6fcbeb8 100644 --- a/internal/git/remote.go +++ b/internal/git/remote.go @@ -119,7 +119,7 @@ func (repo RepositoryRemote) Add(ctx context.Context, name, url string, opts Rem } stderr := bytes.Buffer{} - cmd, err := SafeCmd(ctx, repo.repo, nil, + cmd, err := NewCommand(ctx, repo.repo, nil, SubSubCmd{ Name: "remote", Action: "add", @@ -158,7 +158,7 @@ func (repo RepositoryRemote) Remove(ctx context.Context, name string) error { } var stderr bytes.Buffer - cmd, err := SafeCmd(ctx, repo.repo, nil, + cmd, err := NewCommand(ctx, repo.repo, nil, SubSubCmd{ Name: "remote", Action: "remove", @@ -214,7 +214,7 @@ func (repo RepositoryRemote) SetURL(ctx context.Context, name, url string, opts } var stderr bytes.Buffer - cmd, err := SafeCmd(ctx, repo.repo, nil, + cmd, err := NewCommand(ctx, repo.repo, nil, SubSubCmd{ Name: "remote", Action: "set-url", diff --git a/internal/git/remote/remote.go b/internal/git/remote/remote.go index defb0f5e4..787af75e4 100644 --- a/internal/git/remote/remote.go +++ b/internal/git/remote/remote.go @@ -12,7 +12,7 @@ import ( //Remove removes the remote from repository func Remove(ctx context.Context, cfg config.Cfg, repo repository.GitRepo, name string) error { - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubSubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubSubCmd{ Name: "remote", Action: "remove", Args: []string{name}, @@ -27,7 +27,7 @@ func Remove(ctx context.Context, cfg config.Cfg, repo repository.GitRepo, name s // Exists will always return a boolean value, but should only be depended on // when the error value is nil func Exists(ctx context.Context, cfg config.Cfg, repo repository.GitRepo, name string) (bool, error) { - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{Name: "remote"}, git.WithRefTxHook(ctx, helper.ProtoRepoFromRepo(repo), cfg), ) diff --git a/internal/git/repository.go b/internal/git/repository.go index 25f1abc67..babd66a18 100644 --- a/internal/git/repository.go +++ b/internal/git/repository.go @@ -128,7 +128,7 @@ func NewRepository(repo repository.GitRepo) *LocalRepository { // in the Repository. It validates the arguments in the command before // executing. func (repo *LocalRepository) command(ctx context.Context, globals []GlobalOption, cmd SubCmd, opts ...CmdOpt) (*command.Command, error) { - return SafeCmd(ctx, repo.repo, globals, cmd, opts...) + return NewCommand(ctx, repo.repo, globals, cmd, opts...) } // WriteBlob writes a blob to the repository's object database and @@ -450,7 +450,7 @@ func (repo *LocalRepository) FetchRemote(ctx context.Context, remoteName string, return err } - cmd, err := SafeCmd(ctx, repo.repo, opts.Global, + cmd, err := NewCommand(ctx, repo.repo, opts.Global, SubCmd{ Name: "fetch", Flags: opts.buildFlags(), diff --git a/internal/git/safecmd.go b/internal/git/safecmd.go index 8c4e29dce..18ee25eca 100644 --- a/internal/git/safecmd.go +++ b/internal/git/safecmd.go @@ -353,9 +353,9 @@ func handleOpts(ctx context.Context, sc Cmd, cc *cmdCfg, opts []CmdOpt) error { return nil } -// SafeCmd creates a command.Command with the given args and Repository. It +// NewCommand 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) { +func NewCommand(ctx context.Context, repo repository.GitRepo, globals []GlobalOption, sc Cmd, opts ...CmdOpt) (*command.Command, error) { cc := &cmdCfg{} if err := handleOpts(ctx, sc, cc, opts); err != nil { diff --git a/internal/git/safecmd_test.go b/internal/git/safecmd_test.go index 3b0b2ba2d..ba70b677c 100644 --- a/internal/git/safecmd_test.go +++ b/internal/git/safecmd_test.go @@ -199,7 +199,7 @@ func TestGlobalOption(t *testing.T) { } } -func TestSafeCmdInvalidArg(t *testing.T) { +func TestNewCommandInvalidArg(t *testing.T) { for _, tt := range []struct { globals []GlobalOption subCmd Cmd @@ -231,7 +231,7 @@ func TestSafeCmdInvalidArg(t *testing.T) { errMsg: `invalid sub command action "-invalid": invalid argument`, }, } { - _, err := SafeCmd( + _, err := NewCommand( context.Background(), &gitalypb.Repository{}, tt.globals, @@ -243,7 +243,7 @@ func TestSafeCmdInvalidArg(t *testing.T) { } } -func TestSafeCmdValid(t *testing.T) { +func TestNewCommandValid(t *testing.T) { testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t) defer cleanup() @@ -335,7 +335,7 @@ func TestSafeCmdValid(t *testing.T) { t.Run(tt.desc, func(t *testing.T) { opts := []CmdOpt{WithRefTxHook(ctx, &gitalypb.Repository{}, config.Config)} - cmd, err := SafeCmd(ctx, testRepo, tt.globals, tt.subCmd, opts...) + cmd, err := NewCommand(ctx, 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:]) @@ -404,7 +404,7 @@ func TestNewCommandWithDir(t *testing.T) { }) } -func TestSafeCmd(t *testing.T) { +func TestNewCommand(t *testing.T) { t.Run("stderr is empty if no error", func(t *testing.T) { repo, _, cleanup := testhelper.NewTestRepoWithWorktree(t) defer cleanup() @@ -413,7 +413,7 @@ func TestSafeCmd(t *testing.T) { defer cancel() var stderr bytes.Buffer - cmd, err := SafeCmd(ctx, repo, nil, + cmd, err := NewCommand(ctx, repo, nil, SubCmd{ Name: "rev-parse", Args: []string{"master"}, @@ -439,7 +439,7 @@ func TestSafeCmd(t *testing.T) { defer cancel() var stderr bytes.Buffer - cmd, err := SafeCmd(ctx, repo, nil, SubCmd{ + cmd, err := NewCommand(ctx, repo, nil, SubCmd{ Name: "rev-parse", Args: []string{"invalid-ref"}, }, diff --git a/internal/git/stats/git.go b/internal/git/stats/git.go index cc8abe59b..c6932060f 100644 --- a/internal/git/stats/git.go +++ b/internal/git/stats/git.go @@ -17,7 +17,7 @@ import ( func LogObjectsInfo(ctx context.Context, repo repository.GitRepo) { logger := ctxlogrus.Extract(ctx) - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "count-objects", Flags: []git.Option{git.Flag{Name: "--verbose"}}, }) diff --git a/internal/git/stats/profile.go b/internal/git/stats/profile.go index be25c16d7..e0cb96f09 100644 --- a/internal/git/stats/profile.go +++ b/internal/git/stats/profile.go @@ -62,7 +62,7 @@ func UnpackedObjects(repoPath string) (int64, error) { // LooseObjects returns the number of loose objects that are not in a packfile. func LooseObjects(ctx context.Context, repository repository.GitRepo) (int64, error) { - cmd, err := git.SafeCmd(ctx, repository, nil, git.SubCmd{Name: "count-objects", Flags: []git.Option{git.Flag{Name: "--verbose"}}}) + cmd, err := git.NewCommand(ctx, repository, nil, git.SubCmd{Name: "count-objects", Flags: []git.Option{git.Flag{Name: "--verbose"}}}) if err != nil { return 0, err } diff --git a/internal/git/subcommand.go b/internal/git/subcommand.go index 27b96e05c..662b39906 100644 --- a/internal/git/subcommand.go +++ b/internal/git/subcommand.go @@ -16,7 +16,7 @@ type gitCommand struct { opts []GlobalOption } -// gitCommands is a curated list of Git command names for special git.SafeCmd +// gitCommands is a curated list of Git command names for special git.NewCommand // validation logic var gitCommands = map[string]gitCommand{ "apply": gitCommand{ diff --git a/internal/git/updateref/updateref.go b/internal/git/updateref/updateref.go index 69aacd6d2..e20a40b78 100644 --- a/internal/git/updateref/updateref.go +++ b/internal/git/updateref/updateref.go @@ -51,7 +51,7 @@ func New(ctx context.Context, repo repository.GitRepo, opts ...UpdaterOpt) (*Upd txOption = git.WithDisabledHooks() } - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "update-ref", Flags: []git.Option{git.Flag{Name: "-z"}, git.Flag{Name: "--stdin"}}, diff --git a/internal/gitaly/service/cleanup/internalrefs/cleaner.go b/internal/gitaly/service/cleanup/internalrefs/cleaner.go index 8e75649da..6c11e5ad4 100644 --- a/internal/gitaly/service/cleanup/internalrefs/cleaner.go +++ b/internal/gitaly/service/cleanup/internalrefs/cleaner.go @@ -133,7 +133,7 @@ func (c *Cleaner) processEntry(ctx context.Context, oldSHA, newSHA string) error // action). It is consulted once per line in the object map. Git is optimized // for ref -> SHA lookups, but we want the opposite! func buildLookupTable(ctx context.Context, repo *gitalypb.Repository) (map[string][]string, error) { - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: []git.Option{git.ValueFlag{Name: "--format", Value: "%(objectname) %(refname)"}}, Args: internalRefs, diff --git a/internal/gitaly/service/commit/count_commits.go b/internal/gitaly/service/commit/count_commits.go index 76f9fb7ed..7b7df9e6f 100644 --- a/internal/gitaly/service/commit/count_commits.go +++ b/internal/gitaly/service/commit/count_commits.go @@ -45,7 +45,7 @@ func (s *server) CountCommits(ctx context.Context, in *gitalypb.CountCommitsRequ } globals := git.ConvertGlobalOptions(in.GetGlobalOptions()) - cmd, err := git.SafeCmd(ctx, in.Repository, globals, subCmd) + cmd, err := git.NewCommand(ctx, in.Repository, globals, subCmd) if err != nil { if _, ok := status.FromError(err); ok { return nil, err diff --git a/internal/gitaly/service/commit/count_diverging_commits.go b/internal/gitaly/service/commit/count_diverging_commits.go index 89fb4cd07..2e23210f0 100644 --- a/internal/gitaly/service/commit/count_diverging_commits.go +++ b/internal/gitaly/service/commit/count_diverging_commits.go @@ -59,7 +59,7 @@ func buildRevListCountCmd(from, to string, maxCount int) git.SubCmd { } func findLeftRightCount(ctx context.Context, repo *gitalypb.Repository, from, to string, maxCount int) (int32, int32, error) { - cmd, err := git.SafeCmd(ctx, repo, nil, buildRevListCountCmd(from, to, maxCount)) + cmd, err := git.NewCommand(ctx, repo, nil, buildRevListCountCmd(from, to, maxCount)) if err != nil { return 0, 0, fmt.Errorf("git rev-list cmd: %v", err) } diff --git a/internal/gitaly/service/commit/find_commit_test.go b/internal/gitaly/service/commit/find_commit_test.go index ce49ad7f1..ab7a27a94 100644 --- a/internal/gitaly/service/commit/find_commit_test.go +++ b/internal/gitaly/service/commit/find_commit_test.go @@ -299,7 +299,7 @@ func benchmarkFindCommit(withCache bool, b *testing.B) { // get a list of revisions - logCmd, err := git.SafeCmd(ctx, testRepo, nil, + logCmd, err := git.NewCommand(ctx, testRepo, nil, git.SubCmd{Name: "log", Flags: []git.Option{git.Flag{Name: "--format=format:%H"}}}) require.NoError(b, err) @@ -346,7 +346,7 @@ func TestFindCommitWithCache(t *testing.T) { // get a list of revisions - logCmd, err := git.SafeCmd(ctx, testRepo, nil, + logCmd, err := git.NewCommand(ctx, testRepo, nil, git.SubCmd{Name: "log", Flags: []git.Option{git.Flag{Name: "--format=format:%H"}}}) require.NoError(t, err) diff --git a/internal/gitaly/service/commit/find_commits.go b/internal/gitaly/service/commit/find_commits.go index f135f0cec..4646a3c98 100644 --- a/internal/gitaly/service/commit/find_commits.go +++ b/internal/gitaly/service/commit/find_commits.go @@ -50,7 +50,7 @@ func (s *server) FindCommits(req *gitalypb.FindCommitsRequest, stream gitalypb.C func (s *server) findCommits(ctx context.Context, req *gitalypb.FindCommitsRequest, stream gitalypb.CommitService_FindCommitsServer) error { globals := git.ConvertGlobalOptions(req.GetGlobalOptions()) - logCmd, err := git.SafeCmd(ctx, req.GetRepository(), globals, getLogCommandSubCmd(req)) + logCmd, err := git.NewCommand(ctx, req.GetRepository(), globals, getLogCommandSubCmd(req)) if err != nil { return fmt.Errorf("error when creating git log command: %v", err) } diff --git a/internal/gitaly/service/commit/isancestor.go b/internal/gitaly/service/commit/isancestor.go index 6bff2ac62..a6ecd28a1 100644 --- a/internal/gitaly/service/commit/isancestor.go +++ b/internal/gitaly/service/commit/isancestor.go @@ -30,7 +30,7 @@ func commitIsAncestorName(ctx context.Context, repo *gitalypb.Repository, ancest "childSha": childID, }).Debug("commitIsAncestor") - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{Name: "merge-base", + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{Name: "merge-base", Flags: []git.Option{git.Flag{Name: "--is-ancestor"}}, Args: []string{ancestorID, childID}}) if err != nil { if _, ok := status.FromError(err); ok { diff --git a/internal/gitaly/service/commit/languages.go b/internal/gitaly/service/commit/languages.go index 642d8ac69..4f867bc28 100644 --- a/internal/gitaly/service/commit/languages.go +++ b/internal/gitaly/service/commit/languages.go @@ -111,7 +111,7 @@ func (s *server) lookupRevision(ctx context.Context, repo *gitalypb.Repository, func checkRevision(ctx context.Context, repo *gitalypb.Repository, revision string) (string, error) { var stdout, stderr bytes.Buffer - revParse, err := git.SafeCmd(ctx, repo, nil, + revParse, err := git.NewCommand(ctx, repo, nil, git.SubCmd{Name: "rev-parse", Args: []string{revision}}, git.WithStdout(&stdout), git.WithStderr(&stderr), @@ -134,7 +134,7 @@ func checkRevision(ctx context.Context, repo *gitalypb.Repository, revision stri } func disambiguateRevision(ctx context.Context, repo *gitalypb.Repository, revision string) (string, error) { - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: []git.Option{git.Flag{Name: "--format=%(refname)"}}, Args: []string{"**/" + revision}, diff --git a/internal/gitaly/service/commit/list_files.go b/internal/gitaly/service/commit/list_files.go index 90429d148..a66f48fff 100644 --- a/internal/gitaly/service/commit/list_files.go +++ b/internal/gitaly/service/commit/list_files.go @@ -68,7 +68,7 @@ func validateListFilesRequest(in *gitalypb.ListFilesRequest) error { } func listFiles(repo *gitalypb.Repository, revision string, stream gitalypb.CommitService_ListFilesServer) error { - cmd, err := git.SafeCmd(stream.Context(), repo, nil, git.SubCmd{Name: "ls-tree", + cmd, err := git.NewCommand(stream.Context(), repo, nil, git.SubCmd{Name: "ls-tree", Flags: []git.Option{git.Flag{Name: "-z"}, git.Flag{Name: "-r"}, git.Flag{Name: "--full-tree"}, git.Flag{Name: "--full-name"}}, PostSepArgs: []string{revision}, }) diff --git a/internal/gitaly/service/commit/list_last_commits_for_tree.go b/internal/gitaly/service/commit/list_last_commits_for_tree.go index c7cac99f2..080ef1b88 100644 --- a/internal/gitaly/service/commit/list_last_commits_for_tree.go +++ b/internal/gitaly/service/commit/list_last_commits_for_tree.go @@ -123,7 +123,7 @@ func newLSTreeParser(in *gitalypb.ListLastCommitsForTreeRequest, stream gitalypb } globals := git.ConvertGlobalOptions(in.GetGlobalOptions()) - cmd, err := git.SafeCmd(stream.Context(), in.GetRepository(), globals, git.SubCmd{ + cmd, err := git.NewCommand(stream.Context(), in.GetRepository(), globals, git.SubCmd{ Name: "ls-tree", Flags: []git.Option{git.Flag{Name: "-z"}, git.Flag{Name: "--full-name"}}, Args: []string{in.GetRevision(), path}, diff --git a/internal/gitaly/service/commit/raw_blame.go b/internal/gitaly/service/commit/raw_blame.go index 9c8100c81..60897fcca 100644 --- a/internal/gitaly/service/commit/raw_blame.go +++ b/internal/gitaly/service/commit/raw_blame.go @@ -21,7 +21,7 @@ func (s *server) RawBlame(in *gitalypb.RawBlameRequest, stream gitalypb.CommitSe revision := string(in.GetRevision()) path := string(in.GetPath()) - cmd, err := git.SafeCmd(ctx, in.Repository, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, in.Repository, nil, git.SubCmd{ Name: "blame", Flags: []git.Option{git.Flag{Name: "-p"}}, Args: []string{revision}, diff --git a/internal/gitaly/service/commit/stats.go b/internal/gitaly/service/commit/stats.go index 2102b757d..169ed0842 100644 --- a/internal/gitaly/service/commit/stats.go +++ b/internal/gitaly/service/commit/stats.go @@ -43,7 +43,7 @@ func (s *server) commitStats(ctx context.Context, in *gitalypb.CommitStatsReques args = append(args, commit.Id+"^", commit.Id) } - cmd, err := git.SafeCmd(ctx, in.Repository, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, in.Repository, nil, git.SubCmd{ Name: "diff", Flags: []git.Option{git.Flag{Name: "--numstat"}}, Args: args, diff --git a/internal/gitaly/service/conflicts/resolve_conflicts.go b/internal/gitaly/service/conflicts/resolve_conflicts.go index 4560e39e3..52ae859bb 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts.go @@ -284,7 +284,7 @@ func (s *server) repoWithBranchCommit(ctx context.Context, srcRepo, targetRepo * return err } - cmd, err := git.SafeCmd(ctx, srcRepo, nil, + cmd, err := git.NewCommand(ctx, srcRepo, nil, git.SubCmd{ Name: "fetch", Flags: []git.Option{git.Flag{Name: "--no-tags"}}, diff --git a/internal/gitaly/service/diff/commit.go b/internal/gitaly/service/diff/commit.go index d1180b5be..1476ac3f9 100644 --- a/internal/gitaly/service/diff/commit.go +++ b/internal/gitaly/service/diff/commit.go @@ -210,7 +210,7 @@ func eachDiff(ctx context.Context, rpc string, repo *gitalypb.Repository, subCmd git.ConfigPair{Key: "diff.noprefix", Value: "false"}, } - cmd, err := git.SafeCmd(ctx, repo, diffArgs, subCmd) + cmd, err := git.NewCommand(ctx, repo, diffArgs, subCmd) if err != nil { if _, ok := status.FromError(err); ok { return err diff --git a/internal/gitaly/service/diff/find_changed_paths.go b/internal/gitaly/service/diff/find_changed_paths.go index 8140bcf95..cc836f4c2 100644 --- a/internal/gitaly/service/diff/find_changed_paths.go +++ b/internal/gitaly/service/diff/find_changed_paths.go @@ -26,7 +26,7 @@ func (s *server) FindChangedPaths(in *gitalypb.FindChangedPathsRequest, stream g diffChunker := chunk.New(&findChangedPathsSender{stream: stream}) - cmd, err := git.SafeCmd(stream.Context(), in.Repository, nil, git.SubCmd{ + cmd, err := git.NewCommand(stream.Context(), in.Repository, nil, git.SubCmd{ Name: "diff-tree", Flags: []git.Option{ git.Flag{Name: "-z"}, diff --git a/internal/gitaly/service/diff/numstat.go b/internal/gitaly/service/diff/numstat.go index ec892a681..c0d7adbe4 100644 --- a/internal/gitaly/service/diff/numstat.go +++ b/internal/gitaly/service/diff/numstat.go @@ -20,7 +20,7 @@ func (s *server) DiffStats(in *gitalypb.DiffStatsRequest, stream gitalypb.DiffSe } var batch []*gitalypb.DiffStats - cmd, err := git.SafeCmd(stream.Context(), in.Repository, nil, git.SubCmd{ + cmd, err := git.NewCommand(stream.Context(), in.Repository, nil, git.SubCmd{ Name: "diff", Flags: []git.Option{git.Flag{Name: "--numstat"}, git.Flag{Name: "-z"}}, Args: []string{in.LeftCommitId, in.RightCommitId}, diff --git a/internal/gitaly/service/diff/raw.go b/internal/gitaly/service/diff/raw.go index 5e47936f0..dd8307bfb 100644 --- a/internal/gitaly/service/diff/raw.go +++ b/internal/gitaly/service/diff/raw.go @@ -48,7 +48,7 @@ func (s *server) RawPatch(in *gitalypb.RawPatchRequest, stream gitalypb.DiffServ } func sendRawOutput(ctx context.Context, rpc string, repo *gitalypb.Repository, sender io.Writer, subCmd git.SubCmd) error { - cmd, err := git.SafeCmd(ctx, repo, nil, subCmd) + cmd, err := git.NewCommand(ctx, repo, nil, subCmd) if err != nil { if _, ok := status.FromError(err); ok { return err diff --git a/internal/gitaly/service/objectpool/alternates.go b/internal/gitaly/service/objectpool/alternates.go index 7583f48c0..8057f3c9c 100644 --- a/internal/gitaly/service/objectpool/alternates.go +++ b/internal/gitaly/service/objectpool/alternates.go @@ -200,7 +200,7 @@ func removeAlternatesIfOk(ctx context.Context, repo *gitalypb.Repository, altFil } }() - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "fsck", Flags: []git.Option{git.Flag{Name: "--connectivity-only"}}, }) diff --git a/internal/gitaly/service/objectpool/alternates_test.go b/internal/gitaly/service/objectpool/alternates_test.go index f7003f423..f12091259 100644 --- a/internal/gitaly/service/objectpool/alternates_test.go +++ b/internal/gitaly/service/objectpool/alternates_test.go @@ -43,7 +43,7 @@ func TestDisconnectGitAlternates(t *testing.T) { require.NoError(t, err, "find info/alternates") require.NoError(t, os.RemoveAll(altPath)) - cmd, err := git.SafeCmd(ctx, testRepo, nil, + cmd, err := git.NewCommand(ctx, testRepo, nil, git.SubCmd{Name: "cat-file", Flags: []git.Option{git.Flag{Name: "-e"}}, Args: []string{existingObjectID}}) require.NoError(t, err) require.Error(t, cmd.Wait(), "expect cat-file to fail because object cannot be found") diff --git a/internal/gitaly/service/objectpool/reduplicate.go b/internal/gitaly/service/objectpool/reduplicate.go index 9778535cd..94d796c31 100644 --- a/internal/gitaly/service/objectpool/reduplicate.go +++ b/internal/gitaly/service/objectpool/reduplicate.go @@ -14,7 +14,7 @@ func (s *server) ReduplicateRepository(ctx context.Context, req *gitalypb.Redupl return nil, status.Errorf(codes.InvalidArgument, "ReduplicateRepository: no repository") } - cmd, err := git.SafeCmd(ctx, req.GetRepository(), nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, req.GetRepository(), nil, git.SubCmd{ Name: "repack", Flags: []git.Option{git.Flag{Name: "--quiet"}, git.Flag{Name: "-a"}}, }) diff --git a/internal/gitaly/service/objectpool/reduplicate_test.go b/internal/gitaly/service/objectpool/reduplicate_test.go index e7c2b5621..b235cbc1c 100644 --- a/internal/gitaly/service/objectpool/reduplicate_test.go +++ b/internal/gitaly/service/objectpool/reduplicate_test.go @@ -40,7 +40,7 @@ func TestReduplicate(t *testing.T) { require.NoError(t, err, "find info/alternates") require.NoError(t, os.RemoveAll(altPath)) - cmd, err := git.SafeCmd(ctx, testRepo, nil, + cmd, err := git.NewCommand(ctx, testRepo, nil, git.SubCmd{Name: "cat-file", Flags: []git.Option{git.Flag{Name: "-e"}}, Args: []string{existingObjectID}}) require.NoError(t, err) require.Error(t, cmd.Wait()) diff --git a/internal/gitaly/service/operations/commit_files.go b/internal/gitaly/service/operations/commit_files.go index 27784374a..4ef4d2509 100644 --- a/internal/gitaly/service/operations/commit_files.go +++ b/internal/gitaly/service/operations/commit_files.go @@ -438,7 +438,7 @@ func (s *Server) fetchRemoteObject(ctx context.Context, local, remote *gitalypb. } stderr := &bytes.Buffer{} - cmd, err := git.SafeCmd(ctx, local, nil, + cmd, err := git.NewCommand(ctx, local, nil, git.SubCmd{ Name: "fetch", Flags: []git.Option{git.Flag{Name: "--no-tags"}}, diff --git a/internal/gitaly/service/operations/merge.go b/internal/gitaly/service/operations/merge.go index 09ab7d1d6..c52ea814a 100644 --- a/internal/gitaly/service/operations/merge.go +++ b/internal/gitaly/service/operations/merge.go @@ -363,7 +363,7 @@ func (s *Server) UserMergeToRef(ctx context.Context, in *gitalypb.UserMergeToRef } func isAncestor(ctx context.Context, repo repository.GitRepo, ancestor, descendant string) (bool, error) { - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "merge-base", Flags: []git.Option{git.Flag{Name: "--is-ancestor"}}, Args: []string{ancestor, descendant}, diff --git a/internal/gitaly/service/operations/squash.go b/internal/gitaly/service/operations/squash.go index 77105d99e..f90c32796 100644 --- a/internal/gitaly/service/operations/squash.go +++ b/internal/gitaly/service/operations/squash.go @@ -330,7 +330,7 @@ func (s *Server) addWorktree(ctx context.Context, repo *gitalypb.Repository, wor } var stderr bytes.Buffer - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubSubCmd{ Name: "worktree", Action: "add", @@ -352,7 +352,7 @@ func (s *Server) addWorktree(ctx context.Context, repo *gitalypb.Repository, wor } func (s *Server) removeWorktree(ctx context.Context, repo *gitalypb.Repository, worktreeName string) error { - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubSubCmd{ Name: "worktree", Action: "remove", @@ -376,7 +376,7 @@ func (s *Server) applyDiff(ctx context.Context, repo *gitalypb.Repository, req * diffRange := diffRange(req) var diffStderr bytes.Buffer - cmdDiff, err := git.SafeCmd(ctx, req.GetRepository(), nil, + cmdDiff, err := git.NewCommand(ctx, req.GetRepository(), nil, git.SubCmd{ Name: "diff", Flags: []git.Option{ @@ -490,7 +490,7 @@ func newSquashWorktreePath(repoPath, squashID string) string { func runCmd(ctx context.Context, repo *gitalypb.Repository, cmd string, opts []git.Option, args []string) error { var stderr bytes.Buffer - safeCmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{Name: cmd, Flags: opts, Args: args}, git.WithStderr(&stderr)) + safeCmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{Name: cmd, Flags: opts, Args: args}, git.WithStderr(&stderr)) if err != nil { return fmt.Errorf("create safe cmd %q: %w", cmd, gitError{ErrMsg: stderr.String(), Err: err}) } diff --git a/internal/gitaly/service/ref/list_new_blobs.go b/internal/gitaly/service/ref/list_new_blobs.go index d23019c84..0792e36fd 100644 --- a/internal/gitaly/service/ref/list_new_blobs.go +++ b/internal/gitaly/service/ref/list_new_blobs.go @@ -33,7 +33,7 @@ func (s *server) listNewBlobs(in *gitalypb.ListNewBlobsRequest, stream gitalypb. } // the added ^ is to negate the oid since there is a --not option that comes earlier in the arg list - revList, err := git.SafeCmd(ctx, in.GetRepository(), nil, git.SubCmd{Name: "rev-list", Flags: cmdFlags, Args: []string{"^" + oid}}) + revList, err := git.NewCommand(ctx, in.GetRepository(), nil, git.SubCmd{Name: "rev-list", Flags: cmdFlags, Args: []string{"^" + oid}}) if err != nil { return err } diff --git a/internal/gitaly/service/ref/list_new_commits.go b/internal/gitaly/service/ref/list_new_commits.go index 1f12f07e6..73fe6b072 100644 --- a/internal/gitaly/service/ref/list_new_commits.go +++ b/internal/gitaly/service/ref/list_new_commits.go @@ -26,7 +26,7 @@ func (s *server) ListNewCommits(in *gitalypb.ListNewCommitsRequest, stream gital func (s *server) listNewCommits(in *gitalypb.ListNewCommitsRequest, stream gitalypb.RefService_ListNewCommitsServer, oid string) error { ctx := stream.Context() - revList, err := git.SafeCmd(ctx, in.GetRepository(), nil, git.SubCmd{ + revList, err := git.NewCommand(ctx, in.GetRepository(), nil, git.SubCmd{ Name: "rev-list", Flags: []git.Option{git.Flag{Name: "--not"}, git.Flag{Name: "--all"}}, Args: []string{"^" + oid}, // the added ^ is to negate the oid since there is a --not option that comes earlier in the arg list diff --git a/internal/gitaly/service/ref/pack_refs.go b/internal/gitaly/service/ref/pack_refs.go index 51e457750..9e8cbe9e6 100644 --- a/internal/gitaly/service/ref/pack_refs.go +++ b/internal/gitaly/service/ref/pack_refs.go @@ -31,7 +31,7 @@ func validatePackRefsRequest(in *gitalypb.PackRefsRequest) error { } func packRefs(ctx context.Context, repository repository.GitRepo, all bool) error { - cmd, err := git.SafeCmd(ctx, repository, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repository, nil, git.SubCmd{ Name: "pack-refs", Flags: []git.Option{git.Flag{Name: "--all"}}, }) diff --git a/internal/gitaly/service/ref/refexists.go b/internal/gitaly/service/ref/refexists.go index b463d1b2c..437f1177d 100644 --- a/internal/gitaly/service/ref/refexists.go +++ b/internal/gitaly/service/ref/refexists.go @@ -28,7 +28,7 @@ func (server) RefExists(ctx context.Context, in *gitalypb.RefExistsRequest) (*gi } func refExists(ctx context.Context, repo *gitalypb.Repository, ref string) (bool, error) { - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "show-ref", Flags: []git.Option{git.Flag{Name: "--verify"}, git.Flag{Name: "--quiet"}}, Args: []string{ref}, diff --git a/internal/gitaly/service/ref/refname.go b/internal/gitaly/service/ref/refname.go index 0e8928bc2..199a07f23 100644 --- a/internal/gitaly/service/ref/refname.go +++ b/internal/gitaly/service/ref/refname.go @@ -43,7 +43,7 @@ func findRefName(ctx context.Context, repo *gitalypb.Repository, commitID, prefi subCmd.Flags = flags subCmd.Args = []string{prefix} - cmd, err := git.SafeCmd(ctx, repo, nil, subCmd) + cmd, err := git.NewCommand(ctx, repo, nil, subCmd) if err != nil { return "", err } diff --git a/internal/gitaly/service/ref/refnames.go b/internal/gitaly/service/ref/refnames.go index e4f12fb5d..6e9f2f0a4 100644 --- a/internal/gitaly/service/ref/refnames.go +++ b/internal/gitaly/service/ref/refnames.go @@ -62,7 +62,7 @@ func listRefNames(ctx context.Context, chunker *chunk.Chunker, prefix string, re flags = append(flags, git.Flag{arg}) } - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: flags, Args: []string{prefix}, diff --git a/internal/gitaly/service/ref/refs.go b/internal/gitaly/service/ref/refs.go index f122bc8d7..c52b23c22 100644 --- a/internal/gitaly/service/ref/refs.go +++ b/internal/gitaly/service/ref/refs.go @@ -48,7 +48,7 @@ func findRefs(ctx context.Context, writer lines.Sender, repo *gitalypb.Repositor options = append(options, opts.cmdArgs...) } - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: options, Args: patterns, @@ -88,7 +88,7 @@ func (t *tagSender) Send() error { } func (s *server) parseAndReturnTags(ctx context.Context, repo *gitalypb.Repository, stream gitalypb.RefService_FindAllTagsServer) error { - tagsCmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + tagsCmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: []git.Option{ git.ValueFlag{"--format", tagFormat}, @@ -157,7 +157,7 @@ func (s *server) validateFindAllTagsRequest(request *gitalypb.FindAllTagsRequest func _findBranchNames(ctx context.Context, repo *gitalypb.Repository) ([][]byte, error) { var names [][]byte - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: []git.Option{git.Flag{Name: "--format=%(refname)"}}, Args: []string{"refs/heads"}}, @@ -184,7 +184,7 @@ func _findBranchNames(ctx context.Context, repo *gitalypb.Repository) ([][]byte, func _headReference(ctx context.Context, repo *gitalypb.Repository) ([]byte, error) { var headRef []byte - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "rev-parse", Flags: []git.Option{git.Flag{Name: "--symbolic-full-name"}}, Args: []string{"HEAD"}, @@ -215,7 +215,7 @@ func _headReference(ctx context.Context, repo *gitalypb.Repository) ([]byte, err // SetDefaultBranchRef overwrites the default branch ref for the repository func SetDefaultBranchRef(ctx context.Context, repo *gitalypb.Repository, ref string, cfg config.Cfg) error { - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "symbolic-ref", Args: []string{"HEAD", ref}, }, git.WithRefTxHook(ctx, repo, cfg)) @@ -413,7 +413,7 @@ func parseTagLine(ctx context.Context, c catfile.Batch, tagLine string) (*gitaly } func (s *server) findTag(ctx context.Context, repository *gitalypb.Repository, tagName []byte) (*gitalypb.Tag, error) { - tagCmd, err := git.SafeCmd(ctx, repository, nil, + tagCmd, err := git.NewCommand(ctx, repository, nil, git.SubCmd{ Name: "tag", Flags: []git.Option{ diff --git a/internal/gitaly/service/remote/fetch_internal_remote.go b/internal/gitaly/service/remote/fetch_internal_remote.go index 838fcb5ff..72fe4765a 100644 --- a/internal/gitaly/service/remote/fetch_internal_remote.go +++ b/internal/gitaly/service/remote/fetch_internal_remote.go @@ -33,7 +33,7 @@ func (s *server) FetchInternalRemote(ctx context.Context, req *gitalypb.FetchInt } stderr := &bytes.Buffer{} - cmd, err := git.SafeCmd(ctx, req.Repository, nil, + cmd, err := git.NewCommand(ctx, req.Repository, nil, git.SubCmd{ Name: "fetch", Flags: []git.Option{git.Flag{Name: "--prune"}}, diff --git a/internal/gitaly/service/remote/find_remote_root_ref.go b/internal/gitaly/service/remote/find_remote_root_ref.go index 0eaea33e3..c87c8f7a1 100644 --- a/internal/gitaly/service/remote/find_remote_root_ref.go +++ b/internal/gitaly/service/remote/find_remote_root_ref.go @@ -15,7 +15,7 @@ import ( const headPrefix = "HEAD branch: " func findRemoteRootRef(ctx context.Context, repo *gitalypb.Repository, remote string) (string, error) { - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubSubCmd{ Name: "remote", Action: "show", diff --git a/internal/gitaly/service/remote/remotes.go b/internal/gitaly/service/remote/remotes.go index 31489dad0..7cb229c55 100644 --- a/internal/gitaly/service/remote/remotes.go +++ b/internal/gitaly/service/remote/remotes.go @@ -118,7 +118,7 @@ func (s *server) ListRemotes(req *gitalypb.ListRemotesRequest, stream gitalypb.R repo := req.GetRepository() ctx := stream.Context() - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{Name: "remote", Flags: []git.Option{git.Flag{Name: "-v"}}}, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{Name: "remote", Flags: []git.Option{git.Flag{Name: "-v"}}}, git.WithRefTxHook(ctx, repo, config.Config), ) if err != nil { diff --git a/internal/gitaly/service/repository/archive.go b/internal/gitaly/service/repository/archive.go index 50dfb1269..c06c01588 100644 --- a/internal/gitaly/service/repository/archive.go +++ b/internal/gitaly/service/repository/archive.go @@ -207,7 +207,7 @@ func handleArchive(p archiveParams) error { globals = append(globals, git.ConfigPair{Key: "filter.lfs.smudge", Value: binary}) } - archiveCommand, err := git.SafeCmd(p.ctx, p.in.GetRepository(), globals, git.SubCmd{ + archiveCommand, err := git.NewCommand(p.ctx, p.in.GetRepository(), globals, git.SubCmd{ Name: "archive", Flags: []git.Option{git.ValueFlag{"--format", p.format}, git.ValueFlag{"--prefix", p.in.GetPrefix() + "/"}}, Args: args, diff --git a/internal/gitaly/service/repository/calculate_checksum.go b/internal/gitaly/service/repository/calculate_checksum.go index 82ad978e2..54dae6153 100644 --- a/internal/gitaly/service/repository/calculate_checksum.go +++ b/internal/gitaly/service/repository/calculate_checksum.go @@ -28,7 +28,7 @@ func (s *server) CalculateChecksum(ctx context.Context, in *gitalypb.CalculateCh return nil, err } - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{Name: "show-ref", Flags: []git.Option{git.Flag{Name: "--head"}}}) + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{Name: "show-ref", Flags: []git.Option{git.Flag{Name: "--head"}}}) if err != nil { if _, ok := status.FromError(err); ok { return nil, err @@ -77,7 +77,7 @@ func (s *server) CalculateChecksum(ctx context.Context, in *gitalypb.CalculateCh func (s *server) isValidRepo(ctx context.Context, repo *gitalypb.Repository) bool { stdout := &bytes.Buffer{} - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "rev-parse", Flags: []git.Option{ diff --git a/internal/gitaly/service/repository/cleanup.go b/internal/gitaly/service/repository/cleanup.go index 48c774563..a0bd3da21 100644 --- a/internal/gitaly/service/repository/cleanup.go +++ b/internal/gitaly/service/repository/cleanup.go @@ -126,7 +126,7 @@ func (s *server) cleanStaleWorktrees(ctx context.Context, repo *gitalypb.Reposit } if info.ModTime().Before(threshold) { - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubSubCmd{ Name: "worktree", Action: "remove", @@ -149,7 +149,7 @@ func (s *server) cleanStaleWorktrees(ctx context.Context, repo *gitalypb.Reposit } func (s *server) cleanDisconnectedWorktrees(ctx context.Context, repo *gitalypb.Repository) error { - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubSubCmd{ Name: "worktree", Action: "prune", diff --git a/internal/gitaly/service/repository/commit_graph.go b/internal/gitaly/service/repository/commit_graph.go index 21d6e326e..23ce2fe4f 100644 --- a/internal/gitaly/service/repository/commit_graph.go +++ b/internal/gitaly/service/repository/commit_graph.go @@ -23,7 +23,7 @@ func (s *server) WriteCommitGraph(ctx context.Context, in *gitalypb.WriteCommitG } func (s *server) writeCommitGraph(ctx context.Context, in *gitalypb.WriteCommitGraphRequest) error { - cmd, err := git.SafeCmd(ctx, in.GetRepository(), nil, + cmd, err := git.NewCommand(ctx, in.GetRepository(), nil, git.SubSubCmd{ Name: "commit-graph", Action: "write", diff --git a/internal/gitaly/service/repository/config.go b/internal/gitaly/service/repository/config.go index 13f890787..d5fc70808 100644 --- a/internal/gitaly/service/repository/config.go +++ b/internal/gitaly/service/repository/config.go @@ -14,7 +14,7 @@ import ( func (*server) DeleteConfig(ctx context.Context, req *gitalypb.DeleteConfigRequest) (*gitalypb.DeleteConfigResponse, error) { for _, k := range req.Keys { // We assume k does not contain any secrets; it is leaked via 'ps'. - cmd, err := git.SafeCmd(ctx, req.Repository, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, req.Repository, nil, git.SubCmd{ Name: "config", Flags: []git.Option{git.ValueFlag{"--unset-all", k}}, }) diff --git a/internal/gitaly/service/repository/create_bundle.go b/internal/gitaly/service/repository/create_bundle.go index b2e1962fc..277f95c30 100644 --- a/internal/gitaly/service/repository/create_bundle.go +++ b/internal/gitaly/service/repository/create_bundle.go @@ -23,7 +23,7 @@ func (s *server) CreateBundle(req *gitalypb.CreateBundleRequest, stream gitalypb return helper.ErrInternalf("running Cleanup on repository: %w", err) } - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubSubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubSubCmd{ Name: "bundle", Action: "create", Flags: []git.Option{git.OutputToStdout, git.Flag{Name: "--all"}}, diff --git a/internal/gitaly/service/repository/fetch.go b/internal/gitaly/service/repository/fetch.go index 8506a4268..92fa293d8 100644 --- a/internal/gitaly/service/repository/fetch.go +++ b/internal/gitaly/service/repository/fetch.go @@ -81,7 +81,7 @@ func (s *server) FetchSourceBranch(ctx context.Context, req *gitalypb.FetchSourc return nil, err } - cmd, err := git.SafeCmd(ctx, req.Repository, nil, + cmd, err := git.NewCommand(ctx, req.Repository, nil, git.SubCmd{ Name: "fetch", Args: []string{gitalyssh.GitalyInternalURL, sourceOid}, diff --git a/internal/gitaly/service/repository/fsck.go b/internal/gitaly/service/repository/fsck.go index a85ddd1b6..f53ff2812 100644 --- a/internal/gitaly/service/repository/fsck.go +++ b/internal/gitaly/service/repository/fsck.go @@ -13,7 +13,7 @@ func (s *server) Fsck(ctx context.Context, req *gitalypb.FsckRequest) (*gitalypb repo := req.GetRepository() - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{Name: "fsck"}, git.WithStdout(&stdout), git.WithStderr(&stderr), diff --git a/internal/gitaly/service/repository/gc.go b/internal/gitaly/service/repository/gc.go index e7e6f7a3b..2890381c3 100644 --- a/internal/gitaly/service/repository/gc.go +++ b/internal/gitaly/service/repository/gc.go @@ -70,7 +70,7 @@ func (s *server) gc(ctx context.Context, in *gitalypb.GarbageCollectRequest) err flags = append(flags, git.Flag{Name: "--prune=30.minutes.ago"}) } - cmd, err := git.SafeCmd(ctx, in.GetRepository(), args, + cmd, err := git.NewCommand(ctx, in.GetRepository(), args, git.SubCmd{Name: "gc", Flags: flags}, ) @@ -93,7 +93,7 @@ func (s *server) gc(ctx context.Context, in *gitalypb.GarbageCollectRequest) err } func configureCommitGraph(ctx context.Context, in *gitalypb.GarbageCollectRequest) error { - cmd, err := git.SafeCmd(ctx, in.GetRepository(), nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, in.GetRepository(), nil, git.SubCmd{ Name: "config", Flags: []git.Option{ git.ConfigPair{Key: "core.commitGraph", Value: "true"}, @@ -177,7 +177,7 @@ func (s *server) fixRef(ctx context.Context, repo *gitalypb.Repository, batch ca } // The name is a valid sha, recreate the ref - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "update-ref", Args: []string{name, sha}, diff --git a/internal/gitaly/service/repository/merge_base.go b/internal/gitaly/service/repository/merge_base.go index f2019deed..0ae6f4198 100644 --- a/internal/gitaly/service/repository/merge_base.go +++ b/internal/gitaly/service/repository/merge_base.go @@ -21,7 +21,7 @@ func (s *server) FindMergeBase(ctx context.Context, req *gitalypb.FindMergeBaseR return nil, status.Errorf(codes.InvalidArgument, "FindMergeBase: at least 2 revisions are required") } - cmd, err := git.SafeCmd(ctx, req.GetRepository(), nil, + cmd, err := git.NewCommand(ctx, req.GetRepository(), nil, git.SubCmd{ Name: "merge-base", Args: revisions, diff --git a/internal/gitaly/service/repository/midx.go b/internal/gitaly/service/repository/midx.go index c1e0e1d03..f9d5494ce 100644 --- a/internal/gitaly/service/repository/midx.go +++ b/internal/gitaly/service/repository/midx.go @@ -54,7 +54,7 @@ func (s *server) safeMidxCommand(ctx context.Context, repo repository.GitRepo, c } func midxSetConfig(ctx context.Context, repo repository.GitRepo) error { - cmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "config", Flags: []git.Option{ git.ConfigPair{ @@ -75,7 +75,7 @@ func midxSetConfig(ctx context.Context, repo repository.GitRepo) error { } func midxWrite(ctx context.Context, repo repository.GitRepo) error { - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubSubCmd{ Name: "multi-pack-index", Action: "write", @@ -111,7 +111,7 @@ func (s *server) midxEnsureExists(ctx context.Context, repo repository.GitRepo) func midxVerify(ctx context.Context, repo repository.GitRepo) error { ctxlogger := ctxlogrus.Extract(ctx) - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubSubCmd{ Name: "multi-pack-index", Action: "verify", @@ -147,7 +147,7 @@ func (s *server) midxRewrite(ctx context.Context, repo repository.GitRepo) error } func midxExpire(ctx context.Context, repo repository.GitRepo) error { - cmd, err := git.SafeCmd(ctx, repo, nil, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubSubCmd{ Name: "multi-pack-index", Action: "expire", @@ -188,7 +188,7 @@ func (s *server) midxRepack(ctx context.Context, repo repository.GitRepo) error // - repack.useDeltaIslands // will only be respected if git version is >=2.28.0. // Bitmap index 'repack.writeBitmaps' is not yet supported. - cmd, err := git.SafeCmd(ctx, repo, + cmd, err := git.NewCommand(ctx, repo, repackConfig(ctx, false), git.SubSubCmd{ Name: "multi-pack-index", diff --git a/internal/gitaly/service/repository/optimize.go b/internal/gitaly/service/repository/optimize.go index 017fb39a7..6e323099f 100644 --- a/internal/gitaly/service/repository/optimize.go +++ b/internal/gitaly/service/repository/optimize.go @@ -187,7 +187,7 @@ func (s *server) unsetAllConfigsByRegexp(ctx context.Context, repository *gitaly } func getConfigKeys(ctx context.Context, repository *gitalypb.Repository, regexp string) ([]string, error) { - cmd, err := git.SafeCmd(ctx, repository, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repository, nil, git.SubCmd{ Name: "config", Flags: []git.Option{ git.Flag{Name: "--name-only"}, @@ -247,7 +247,7 @@ func unsetAll(ctx context.Context, repository *gitalypb.Repository, name string) return nil } - cmd, err := git.SafeCmd(ctx, repository, nil, git.SubCmd{ + cmd, err := git.NewCommand(ctx, repository, nil, git.SubCmd{ Name: "config", Flags: []git.Option{git.ValueFlag{Name: "--unset-all", Value: name}}, }) diff --git a/internal/gitaly/service/repository/raw_changes.go b/internal/gitaly/service/repository/raw_changes.go index 967ede2a4..df80e5323 100644 --- a/internal/gitaly/service/repository/raw_changes.go +++ b/internal/gitaly/service/repository/raw_changes.go @@ -64,7 +64,7 @@ func getRawChanges(stream gitalypb.RepositoryService_GetRawChangesServer, repo * ctx := stream.Context() - diffCmd, err := git.SafeCmd(ctx, repo, nil, git.SubCmd{ + diffCmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ Name: "diff", Flags: []git.Option{git.Flag{Name: "--raw"}, git.Flag{Name: "-z"}}, Args: []string{from, to}, diff --git a/internal/gitaly/service/repository/repack.go b/internal/gitaly/service/repository/repack.go index a3abd040a..939d0b8c7 100644 --- a/internal/gitaly/service/repository/repack.go +++ b/internal/gitaly/service/repository/repack.go @@ -47,7 +47,7 @@ func (*server) RepackIncremental(ctx context.Context, in *gitalypb.RepackIncreme } func repackCommand(ctx context.Context, repo repository.GitRepo, bitmap bool, args ...git.Option) error { - cmd, err := git.SafeCmd(ctx, repo, + cmd, err := git.NewCommand(ctx, repo, repackConfig(ctx, bitmap), // global configs git.SubCmd{ Name: "repack", diff --git a/internal/gitaly/service/repository/search_files.go b/internal/gitaly/service/repository/search_files.go index 958880097..350394cd6 100644 --- a/internal/gitaly/service/repository/search_files.go +++ b/internal/gitaly/service/repository/search_files.go @@ -39,7 +39,7 @@ func (s *server) SearchFilesByContent(req *gitalypb.SearchFilesByContentRequest, } ctx := stream.Context() - cmd, err := git.SafeCmd(ctx, repo, + cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{Name: "grep", Flags: []git.Option{ git.Flag{Name: "--ignore-case"}, @@ -127,7 +127,7 @@ func (s *server) SearchFilesByName(req *gitalypb.SearchFilesByNameRequest, strea } ctx := stream.Context() - cmd, err := git.SafeCmd( + cmd, err := git.NewCommand( ctx, repo, nil, diff --git a/internal/gitaly/service/repository/util.go b/internal/gitaly/service/repository/util.go index c0662ac56..7514beecf 100644 --- a/internal/gitaly/service/repository/util.go +++ b/internal/gitaly/service/repository/util.go @@ -9,7 +9,7 @@ import ( ) func (s *server) removeOriginInRepo(ctx context.Context, repository *gitalypb.Repository) error { - cmd, err := git.SafeCmd(ctx, repository, nil, git.SubCmd{Name: "remote", Args: []string{"remove", "origin"}}, git.WithRefTxHook(ctx, repository, s.cfg)) + cmd, err := git.NewCommand(ctx, repository, nil, git.SubCmd{Name: "remote", Args: []string{"remove", "origin"}}, git.WithRefTxHook(ctx, repository, s.cfg)) if err != nil { return fmt.Errorf("remote cmd start: %v", err) diff --git a/internal/gitaly/service/repository/write_ref.go b/internal/gitaly/service/repository/write_ref.go index 51a38962a..edf7a724b 100644 --- a/internal/gitaly/service/repository/write_ref.go +++ b/internal/gitaly/service/repository/write_ref.go @@ -30,7 +30,7 @@ func (s *server) writeRef(ctx context.Context, req *gitalypb.WriteRefRequest) er } func (s *server) updateSymbolicRef(ctx context.Context, req *gitalypb.WriteRefRequest) error { - cmd, err := git.SafeCmd(ctx, req.GetRepository(), nil, + cmd, err := git.NewCommand(ctx, req.GetRepository(), nil, git.SubCmd{ Name: "symbolic-ref", Args: []string{string(req.GetRef()), string(req.GetRevision())}, |