shad-go/tools/testtool/commands/git.go

23 lines
422 B
Go
Raw Normal View History

2020-02-12 22:54:25 +00:00
package commands
import (
"bytes"
"os"
"os/exec"
"strings"
)
func listChangedFiles(gitPath string) ([]string, error) {
var gitOutput bytes.Buffer
cmd := exec.Command("git", "diff-tree", "--no-commit-id", "--name-only", "-r", "HEAD")
cmd.Dir = gitPath
cmd.Stdout = &gitOutput
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
return nil, err
}
return strings.Split(gitOutput.String(), "\n"), nil
}