-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (39 loc) · 994 Bytes
/
main.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
40
41
42
43
44
45
46
/*
Copyright © 2023 Anindya Chowdhury <[email protected]>
*/
package main
import (
"oni-commit/cmd"
"oni-commit/utils/console"
"os/exec"
"strings"
)
func main() {
err := exec.Command("git", "rev-parse", "--git-dir").Run()
if err != nil { // if error is not nil, then it is not a git repository
console.BoldBgRed("Not a Git repository")
return
}
out, err := exec.Command("git", "status", "--porcelain").Output()
if err != nil {
console.BoldBgRed("Error running git status:")
return
}
lines := strings.Split(string(out), "\n")
allModifiedFilesStaged := true
for _, line := range lines {
if strings.HasPrefix(line, " M") { // if file is modified but not staged
allModifiedFilesStaged = false
break
}
if strings.HasPrefix(line, "MM") { // if file is staged and then modified
allModifiedFilesStaged = false
break
}
}
if !allModifiedFilesStaged {
console.BoldBgRed("Not all modified files are staged.")
return
}
cmd.Execute()
}