forked from toolshed/abra
feat: diff on release flow
Also, don't commit unstaged files.
This commit is contained in:
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// Commit runs a git commit
|
||||
func Commit(repoPath, glob, commitMessage string, dryRun bool) error {
|
||||
func Commit(repoPath, commitMessage string, dryRun bool) error {
|
||||
if commitMessage == "" {
|
||||
return fmt.Errorf("no commit message specified?")
|
||||
}
|
||||
@ -33,17 +33,8 @@ func Commit(repoPath, glob, commitMessage string, dryRun bool) error {
|
||||
}
|
||||
|
||||
if !dryRun {
|
||||
err = commitWorktree.AddGlob(glob)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("staged %s for commit", glob)
|
||||
} else {
|
||||
logrus.Debugf("dry run: did not stage %s for commit", glob)
|
||||
}
|
||||
|
||||
if !dryRun {
|
||||
_, err = commitWorktree.Commit(commitMessage, &git.CommitOptions{})
|
||||
// NOTE(d1): `All: true` does not include untracked files
|
||||
_, err = commitWorktree.Commit(commitMessage, &git.CommitOptions{All: true})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
42
pkg/git/diff.go
Normal file
42
pkg/git/diff.go
Normal file
@ -0,0 +1,42 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// getGitDiffArgs builds the `git diff` invocation args. It removes the usage
|
||||
// of a pager and ensures that colours are specified even when Git might detect
|
||||
// otherwise.
|
||||
func getGitDiffArgs(repoPath string) []string {
|
||||
return []string{
|
||||
"-C",
|
||||
repoPath,
|
||||
"--no-pager",
|
||||
"-c",
|
||||
"color.diff=always",
|
||||
"diff",
|
||||
}
|
||||
}
|
||||
|
||||
// DiffUnstaged shows a `git diff`. Due to limitations in the underlying go-git
|
||||
// library, this implementation requires the /usr/bin/git binary. It gracefully
|
||||
// skips if it cannot find the command on the system.
|
||||
func DiffUnstaged(path string) error {
|
||||
if _, err := exec.LookPath("git"); err != nil {
|
||||
logrus.Warnf("unable to locate git command, cannot output diff")
|
||||
return nil
|
||||
}
|
||||
|
||||
gitDiffArgs := getGitDiffArgs(path)
|
||||
diff, err := exec.Command("git", gitDiffArgs...).Output()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Print(string(diff))
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user