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:
authorNick Thomas <nick@gitlab.com>2018-12-03 19:50:11 +0300
committerNick Thomas <nick@gitlab.com>2018-12-06 15:55:37 +0300
commit4e84d21587efd68aa07fdac568f2c5710d717395 (patch)
treea1e2cba416ceed58e1f31aed2cb2bb4d8b9562fc /internal/git/command.go
parentd09529276173e55eec782033fb7441d46d050d4c (diff)
Allow commands to be written to via their stdin
Diffstat (limited to 'internal/git/command.go')
-rw-r--r--internal/git/command.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/internal/git/command.go b/internal/git/command.go
index 012a3f895..fc10324f2 100644
--- a/internal/git/command.go
+++ b/internal/git/command.go
@@ -12,14 +12,34 @@ import (
// Command creates a git.Command with the given args and Repository
func Command(ctx context.Context, repo repository.GitRepo, args ...string) (*command.Command, error) {
- repoPath, env, err := alternates.PathAndEnv(repo)
+ args, env, err := argsAndEnv(repo, args...)
+ if err != nil {
+ return nil, err
+ }
+
+ return BareCommand(ctx, nil, nil, nil, env, args...)
+}
+
+// StdinCommand creates a git.Command with the given args and Repository that is
+// suitable for Write()ing to
+func StdinCommand(ctx context.Context, repo repository.GitRepo, args ...string) (*command.Command, error) {
+ args, env, err := argsAndEnv(repo, args...)
if err != nil {
return nil, err
}
+ return BareCommand(ctx, command.SetupStdin, nil, nil, env, args...)
+}
+
+func argsAndEnv(repo repository.GitRepo, args ...string) ([]string, []string, error) {
+ repoPath, env, err := alternates.PathAndEnv(repo)
+ if err != nil {
+ return nil, nil, err
+ }
+
args = append([]string{"--git-dir", repoPath}, args...)
- return BareCommand(ctx, nil, nil, nil, env, args...)
+ return args, env, nil
}
// BareCommand creates a git.Command with the given args, stdin/stdout/stderr, and env