Skip to content

Commit 4cccc3a

Browse files
arschlesAaron Schlesinger
authored andcommitted
fix(git.go): use cmd.Run() instead of start + waitgroup
1 parent 85781bf commit 4cccc3a

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

pkg/git/git.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,13 @@ func Receive(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)
121121
}
122122
cmd.Env = append(cmd.Env, os.Environ()...)
123123

124-
done := plumbCommand(cmd, channel, &errbuff)
124+
plumbCommand(cmd, channel, &errbuff)
125125

126-
pkglog.Debug("Running %s", strings.Join(cmd.Args, " "))
127-
pkglog.Debug("Working Dir: %s", cmd.Dir)
128-
pkglog.Debug("Environment: %s", strings.Join(cmd.Env, ","))
129-
130-
if err := cmd.Start(); err != nil {
131-
log.Warnf(c, "Failed git receive immediately: %s %s", err, errbuff.Bytes())
132-
return nil, err
126+
if err := cmd.Run(); err != nil {
127+
log.Warnf(c, "Failed git receive: %s %s", err, errbuff.Bytes())
128+
return nil, fmt.Errorf("Failed git receive immediately: %s (%s)", errbuff.Bytes(), err)
133129
}
134130
fmt.Printf("Waiting for git-receive to run.\n")
135-
done.Wait()
136131
fmt.Printf("Waiting for deploy.\n")
137132
if err := cmd.Wait(); err != nil {
138133
log.Errf(c, "Error on command: %s %s", err, errbuff.Bytes())
@@ -166,8 +161,7 @@ func cleanRepoName(name string) (string, error) {
166161
// plumbCommand connects the exec in/output and the channel in/output.
167162
//
168163
// The sidechannel is for sending errors to logs.
169-
func plumbCommand(cmd *exec.Cmd, channel ssh.Channel, sidechannel io.Writer) *sync.WaitGroup {
170-
var wg sync.WaitGroup
164+
func plumbCommand(cmd *exec.Cmd, channel ssh.Channel, sidechannel io.Writer) {
171165
inpipe, _ := cmd.StdinPipe()
172166
go func() {
173167
io.Copy(inpipe, channel)
@@ -176,8 +170,6 @@ func plumbCommand(cmd *exec.Cmd, channel ssh.Channel, sidechannel io.Writer) *sy
176170

177171
cmd.Stdout = channel
178172
cmd.Stderr = io.MultiWriter(channel.Stderr(), sidechannel)
179-
180-
return &wg
181173
}
182174

183175
var createLock sync.Mutex

0 commit comments

Comments
 (0)