forked from karantin2020/gitcomm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitutils.go
39 lines (34 loc) · 770 Bytes
/
gitutils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package gitcomm
import (
"log"
"os"
"os/exec"
"strings"
)
var (
colorOutputFlag = []string{"-c", "color.ui=always"}
)
// UndoLastCommit leaves your working tree (the state of your
// files on disk) unchanged but undoes the commit
// and leaves the changes you committed unstaged
func UndoLastCommit() {
undoCmd := []string{"reset", "HEAD~"}
args := append(colorOutputFlag, undoCmd...)
git(args...)
}
func git(args ...string) {
cmd := exec.Command("git", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err := cmd.Run()
ExitIfError(err)
}
func gitColorCmd(cmd ...string) {
if cmd == nil || len(cmd) == 0 {
return
}
args := append(colorOutputFlag, cmd...)
log.Printf("git %s\n", strings.Join(cmd, " "))
git(args...)
}