Skip to content

Commit

Permalink
Fix empty output from git-plan command (#50)
Browse files Browse the repository at this point in the history
Currently the git-plan command returns an empty output. This is due to a race
condition in the command runner where the output is not captured correctly
before the command stops.

The Go tool chain is also updated to support dependencies using new package
errors functions, e.g. errors.As.

Co-authored-by: Bjørn Sørensen <bso@lunar.app>
  • Loading branch information
jweibel22 and Crevil authored Sep 28, 2020
1 parent 4bd7c78 commit dd2f8b3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- "1.11.x"
- "1.15.x"

script: |
echo "Build shuttle" &&
Expand All @@ -17,4 +17,4 @@ deploy:
script: curl -sL https://git.io/goreleaser | bash
on:
tags: true
condition: $TRAVIS_OS_NAME = linux
condition: $TRAVIS_OS_NAME = linux
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/Masterminds/sprig v2.16.0+incompatible
github.com/aokoli/goutils v1.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-cmd/cmd v1.0.3
github.com/go-cmd/cmd v1.2.0
github.com/go-test/deep v1.0.1 // indirect
github.com/google/uuid v1.0.0 // indirect
github.com/huandu/xstrings v1.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-cmd/cmd v1.0.3 h1:N4lOnQy9gKNXLDnjoyRLLXG5sRqEzvFtdHjQysBez/g=
github.com/go-cmd/cmd v1.0.3/go.mod h1:y8q8qlK5wQibcw63djSl/ntiHUHXHGdCkPk0j4QeW4s=
github.com/go-cmd/cmd v1.2.0 h1:Aohz0ZG0nQbvT4z55Mh+fdegX48GSAXL3cSsbYxRfvI=
github.com/go-cmd/cmd v1.2.0/go.mod h1:XgKkd0L6sv9WcYV0FS8RfG1RJCSTVHTsLeAD2pTgHt0=
github.com/go-test/deep v1.0.1 h1:UQhStjbkDClarlmv0am7OXXO4/GaPdCGiUiMTvi28sg=
github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA=
Expand Down
23 changes: 20 additions & 3 deletions pkg/git/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,39 @@ func GetGitPlan(plan string, localShuttleDirectoryPath string, uii ui.UI, skipGi
}

func RunGitPlanCommand(command string, plan string, uii ui.UI) {

cmdOptions := go_cmd.Options{
Buffered: false,
Streaming: true,
}
execCmd := go_cmd.NewCmdOptions(cmdOptions, "sh", "-c", "cd '"+plan+"'; git "+command)
execCmd.Env = os.Environ()

doneChan := make(chan struct{})
go func() {
for {
defer close(doneChan)

for execCmd.Stdout != nil || execCmd.Stderr != nil {
select {
case line := <-execCmd.Stdout:
case line, open := <-execCmd.Stdout:
if !open {
execCmd.Stdout = nil
continue
}
uii.Infoln("%s", line)
case line := <-execCmd.Stderr:
case line, open := <-execCmd.Stderr:
if !open {
execCmd.Stderr = nil
continue
}
uii.Infoln("%s", line)
}
}
}()

status := <-execCmd.Start()
<-doneChan

if status.Exit > 0 {
os.Exit(status.Exit)
}
Expand Down

0 comments on commit dd2f8b3

Please sign in to comment.