mirror of
https://github.com/thegeeklab/wp-git-action.git
synced 2024-11-10 03:20:40 +00:00
45 lines
596 B
Go
45 lines
596 B
Go
package git
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
"golang.org/x/sys/execabs"
|
|
)
|
|
|
|
func Status(repo Repository) *execabs.Cmd {
|
|
cmd := execabs.Command(
|
|
gitBin,
|
|
"status",
|
|
"--porcelain",
|
|
)
|
|
cmd.Dir = repo.WorkDir
|
|
cmd.Stderr = os.Stderr
|
|
|
|
return cmd
|
|
}
|
|
|
|
func IsDirty(repo Repository) bool {
|
|
res := bytes.NewBufferString("")
|
|
|
|
cmd := Status(repo)
|
|
cmd.Dir = repo.WorkDir
|
|
cmd.Stderr = os.Stderr
|
|
cmd.Stdout = res
|
|
cmd.Stderr = res
|
|
|
|
err := runCommand(cmd)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
if res.Len() > 0 {
|
|
logrus.Debug(res.String())
|
|
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|