mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-19 00:28:03 +02:00
second commit
This commit is contained in:
BIN
hello-world
Executable file
BIN
hello-world
Executable file
Binary file not shown.
@ -9,23 +9,74 @@ import (
|
|||||||
// "log"
|
// "log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func plus(a int, b int) int {
|
||||||
|
return a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
// from https://gobyexample.com/collection-functions
|
||||||
|
func Map(vs []string, f func(string) string) []string {
|
||||||
|
vsm := make([]string, len(vs))
|
||||||
|
for i, v := range vs {
|
||||||
|
vsm[i] = f(v)
|
||||||
|
}
|
||||||
|
return vsm
|
||||||
|
}
|
||||||
|
|
||||||
|
func sanitisedFileString(fileString string) string {
|
||||||
|
r := regexp.MustCompile("\\s| \\(new commits\\)|.* ")
|
||||||
|
fileString = r.ReplaceAllString(fileString, "")
|
||||||
|
return fileString
|
||||||
|
}
|
||||||
|
|
||||||
|
func filesByMatches(statusString string, targets []string) []string {
|
||||||
|
files := make([]string, 0)
|
||||||
|
for _, target := range targets {
|
||||||
|
if strings.Index(statusString, target) == -1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
r := regexp.MustCompile("(?s)" + target + ".*?\n\n(.*?)\n\n")
|
||||||
|
fmt.Println(r)
|
||||||
|
|
||||||
|
matchedFileStrings := strings.Split(r.FindStringSubmatch(statusString)[1], "\n")
|
||||||
|
// fmt.Println(matchedFileStrings)
|
||||||
|
|
||||||
|
matchedFiles := Map(matchedFileStrings, sanitisedFileString)
|
||||||
|
// fmt.Println(matchedFiles)
|
||||||
|
files = append(files, matchedFiles...)
|
||||||
|
|
||||||
|
}
|
||||||
|
fmt.Println(files)
|
||||||
|
return files
|
||||||
|
}
|
||||||
|
|
||||||
|
func filesToStage(statusString string) []string {
|
||||||
|
targets := []string{"Changes not staged for commit:", "Untracked files:"}
|
||||||
|
return filesByMatches(statusString, targets)
|
||||||
|
}
|
||||||
|
|
||||||
|
func runCommand(cmd string) (string, error) {
|
||||||
|
splitCmd := strings.Split(cmd, " ")
|
||||||
|
fmt.Println(splitCmd)
|
||||||
|
|
||||||
|
cmdOut, err := exec.Command(splitCmd[0], splitCmd[1:]...).Output()
|
||||||
|
|
||||||
|
// if err != nil {
|
||||||
|
// os.Exit(1)
|
||||||
|
// }
|
||||||
|
|
||||||
|
return string(cmdOut), err
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
var (
|
statusString, _ := runCommand("git status")
|
||||||
cmdOut []byte
|
fmt.Println(filesToStage(statusString))
|
||||||
err error
|
|
||||||
)
|
|
||||||
cmdName := "git"
|
|
||||||
cmdArgs := []string{"rev-parse", "--verify", "HEAD"}
|
|
||||||
if cmdOut, err = exec.Command(cmdName, cmdArgs...).Output(); err != nil {
|
|
||||||
fmt.Fprintln(os.Stderr, "There was an error running git rev-parse command: ", err)
|
|
||||||
fmt.Println(string(cmdOut))
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
sha := string(cmdOut)
|
|
||||||
firstSix := sha[:6]
|
|
||||||
fmt.Println("The first six chars of the SHA at HEAD in this repo are", firstSix)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user