Skip to content

Commit

Permalink
Merge branch 'master' into handle-empty-pull
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaniwaki committed Jun 14, 2019
2 parents d521f1f + 7548f35 commit cf84534
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
11 changes: 3 additions & 8 deletions pkg/ghost/git/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"os"
"os/exec"
"syscall"

"github.com/pfnet-research/git-ghost/pkg/util"
"github.com/pfnet-research/git-ghost/pkg/util/errors"
Expand Down Expand Up @@ -94,13 +93,9 @@ func AppendNonIndexedDiffFiles(dir, filepath string, nonIndexedFilepaths []strin
cmd.Stdout = f
ggerr := util.JustRunCmd(cmd)
if ggerr != nil {
if exiterr, ok := ggerr.Cause().(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
// exit 1 is valid for git diff
if status.ExitStatus() == 1 {
continue
}
}
if util.GetExitCode(ggerr.Cause()) == 1 {
// exit 1 is valid for git diff
continue
}
errs = multierror.Append(errs, ggerr)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/ghost/git/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ func ValidateGit() errors.GitGhostError {

// ValidateCommittish check committish is valid on dir
func ValidateCommittish(dir, committish string) errors.GitGhostError {
return util.JustRunCmd(
output, err := util.JustOutputCmd(
exec.Command("git", "-C", dir, "cat-file", "-e", committish),
)
if err != nil && util.GetExitCode(err.Cause()) == 1 && len(output) == 0 {
// exit 1 is for unexisting committish.
return errors.Errorf("%s does not exist", committish)
}
return err
}
10 changes: 10 additions & 0 deletions pkg/util/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"
"os/exec"
"strings"
"syscall"

"github.com/pfnet-research/git-ghost/pkg/util/errors"

Expand Down Expand Up @@ -62,3 +63,12 @@ func JustRunCmd(cmd *exec.Cmd) errors.GitGhostError {
}
return nil
}

func GetExitCode(err error) int {
if exiterr, ok := err.(*exec.ExitError); ok {
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
return status.ExitStatus()
}
}
return -1
}

0 comments on commit cf84534

Please sign in to comment.