feat: git commit user appender

This commit is contained in:
Slug-Boi
2025-04-28 15:35:47 +02:00
committed by Theis
parent 6c198447ba
commit 7a0e734ba8
+40
View File
@@ -128,3 +128,43 @@ func group_selection(group []User, excludeMode []string) []string {
return excludeMode
}
func GitCommitAppender(authors string, hash string, flags []string) error {
// Get old commit message
var cmd *exec.Cmd
// git log --format=%B -n1
if hash == "" {
cmd = exec.Command("git", "log", "--format=%B", "-n1")
} else {
cmd = exec.Command("git", "log", "--format=%B", "-n1", hash)
}
out, err := cmd.Output()
if err != nil {
return fmt.Errorf("error: %s", err)
}
// Convert the output to a string
old_commit := string(out)
// commit shell command
// specify git command1
input := []string{"commit"}
input = append(input, flags...)
input = append(input, "--amend", "-m", old_commit+"\n"+authors)
// append the message to the flags
// concat the git command and the flags + message
cmd = exec.Command("git", input...)
// https://stackoverflow.com/questions/18159704/how-to-debug-exit-status-1-error-when-running-exec-command-in-golang
cmd_output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("error: %s : %s", err, string(cmd_output))
} else {
println(string(cmd_output))
}
return nil
}