diff options
author | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-05-09 05:44:03 +0300 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-05-10 18:27:52 +0300 |
commit | 2ce9392ae0b73cc7a68b307c96b82fa95ba9f5dc (patch) | |
tree | 6abe7ed2e28acdd3f1931df998004330ca96d77d | |
parent | 5e48b957746438b48436a9cc7849d238ad8761be (diff) |
helper.NewCommand takes optional 'stderr'
-rw-r--r-- | internal/helper/command.go | 12 | ||||
-rw-r--r-- | internal/service/commit/isancestor.go | 2 | ||||
-rw-r--r-- | internal/service/smarthttp/receive_pack.go | 2 | ||||
-rw-r--r-- | internal/service/smarthttp/upload_pack.go | 2 | ||||
-rw-r--r-- | internal/service/ssh/receive_pack.go | 6 | ||||
-rw-r--r-- | internal/service/ssh/uploadpack.go | 4 |
6 files changed, 14 insertions, 14 deletions
diff --git a/internal/helper/command.go b/internal/helper/command.go index 46cf1543e..61d672a91 100644 --- a/internal/helper/command.go +++ b/internal/helper/command.go @@ -22,11 +22,11 @@ func (c *Command) Kill() { // GitCommandReader creates a git Command with the given args func GitCommandReader(args ...string) (*Command, error) { - return NewCommand(exec.Command("git", args...), nil, nil) + return NewCommand(exec.Command("git", args...), nil, nil, nil) } // NewCommand creates a Command from an exec.Cmd -func NewCommand(cmd *exec.Cmd, stdin io.Reader, stdout io.Writer, env ...string) (*Command, error) { +func NewCommand(cmd *exec.Cmd, stdin io.Reader, stdout, stderr io.Writer, env ...string) (*Command, error) { command := &Command{Cmd: cmd} // Explicitly set the environment for the command @@ -56,8 +56,12 @@ func NewCommand(cmd *exec.Cmd, stdin io.Reader, stdout io.Writer, env ...string) command.Reader = pipe } - // If we don't do something with cmd.Stderr, Git errors will be lost - cmd.Stderr = os.Stderr + if stderr != nil { + cmd.Stderr = stderr + } else { + // If we don't do something with cmd.Stderr, Git errors will be lost + cmd.Stderr = os.Stderr + } if err := cmd.Start(); err != nil { return nil, fmt.Errorf("GitCommand: start %v: %v", cmd.Args, err) diff --git a/internal/service/commit/isancestor.go b/internal/service/commit/isancestor.go index 59b64774e..ebac68d91 100644 --- a/internal/service/commit/isancestor.go +++ b/internal/service/commit/isancestor.go @@ -32,7 +32,7 @@ func (s *server) CommitIsAncestor(ctx context.Context, in *pb.CommitIsAncestorRe // Assumes that `path`, `ancestorID` and `childID` are populated :trollface: func commitIsAncestorName(path, ancestorID, childID string) (bool, error) { osCommand := exec.Command("git", "--git-dir", path, "merge-base", "--is-ancestor", ancestorID, childID) - cmd, err := helper.NewCommand(osCommand, nil, ioutil.Discard) + cmd, err := helper.NewCommand(osCommand, nil, ioutil.Discard, nil) if err != nil { return false, grpc.Errorf(codes.Internal, err.Error()) } diff --git a/internal/service/smarthttp/receive_pack.go b/internal/service/smarthttp/receive_pack.go index 91aa97af1..7d482d10a 100644 --- a/internal/service/smarthttp/receive_pack.go +++ b/internal/service/smarthttp/receive_pack.go @@ -40,7 +40,7 @@ func (s *server) PostReceivePack(stream pb.SmartHTTP_PostReceivePackServer) erro helper.Debugf("PostReceivePack: RepoPath=%q GlID=%q GlRepository=%q", repoPath, req.GlId, req.GlRepository) osCommand := exec.Command("git", "receive-pack", "--stateless-rpc", repoPath) - cmd, err := helper.NewCommand(osCommand, stdin, stdout, env...) + cmd, err := helper.NewCommand(osCommand, stdin, stdout, nil, env...) if err != nil { return grpc.Errorf(codes.Unavailable, "PostReceivePack: cmd: %v", err) diff --git a/internal/service/smarthttp/upload_pack.go b/internal/service/smarthttp/upload_pack.go index deab1da28..a5ee5b15f 100644 --- a/internal/service/smarthttp/upload_pack.go +++ b/internal/service/smarthttp/upload_pack.go @@ -35,7 +35,7 @@ func (s *server) PostUploadPack(stream pb.SmartHTTP_PostUploadPackServer) error helper.Debugf("PostUploadPack: RepoPath=%q", repoPath) osCommand := exec.Command("git", "upload-pack", "--stateless-rpc", repoPath) - cmd, err := helper.NewCommand(osCommand, stdin, stdout) + cmd, err := helper.NewCommand(osCommand, stdin, stdout, nil) if err != nil { return grpc.Errorf(codes.Unavailable, "PostUploadPack: cmd: %v", err) diff --git a/internal/service/ssh/receive_pack.go b/internal/service/ssh/receive_pack.go index 243ea2aa4..e6c199052 100644 --- a/internal/service/ssh/receive_pack.go +++ b/internal/service/ssh/receive_pack.go @@ -50,16 +50,14 @@ func (s *server) SSHReceivePack(stream pb.SSH_SSHReceivePackServer) error { log.Printf("PostReceivePack: RepoPath=%q GlID=%q", repoPath, req.GlId) - osCommand := exec.Command("git", "receive-pack", repoPath) - cmd, err := helper.NewCommand(osCommand, stdin, stdout, env...) + osCommand := exec.Command("git-receive-pack", repoPath) + cmd, err := helper.NewCommand(osCommand, stdin, stdout, stderr, env...) if err != nil { return grpc.Errorf(codes.Unavailable, "PostReceivePack: cmd: %v", err) } defer cmd.Kill() - cmd.Stderr = stderr - if err := cmd.Wait(); err != nil { if status, ok := helper.ExitStatus(err); ok { log.Printf("Exit Status: %d", status) diff --git a/internal/service/ssh/uploadpack.go b/internal/service/ssh/uploadpack.go index dc816ecff..1ff0d988f 100644 --- a/internal/service/ssh/uploadpack.go +++ b/internal/service/ssh/uploadpack.go @@ -44,15 +44,13 @@ func (s *server) SSHUploadPack(stream pb.SSH_SSHUploadPackServer) error { log.Printf("PostUploadPack: RepoPath=%q", repoPath) osCommand := exec.Command("git", "upload-pack", repoPath) - cmd, err := helper.NewCommand(osCommand, stdin, stdout) + cmd, err := helper.NewCommand(osCommand, stdin, stdout, stderr) if err != nil { return grpc.Errorf(codes.Unavailable, "PostUploadPack: cmd: %v", err) } defer cmd.Kill() - cmd.Stderr = stderr - if err := cmd.Wait(); err != nil { if status, ok := helper.ExitStatus(err); ok { log.Printf("Exit Status: %d", status) |