fix pre delete dirmd set dir bug and implement last git sha and commit#
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CommitInfo struct {
|
||||
ShortSHA string
|
||||
Message string
|
||||
}
|
||||
|
||||
func GetCommitInfo(rootDir string) *CommitInfo {
|
||||
cmd := exec.Command("git", "-C", rootDir, "log", "-1", "--format=%h %s")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
parts := strings.SplitN(strings.TrimSpace(string(output)), " ", 2)
|
||||
if len(parts) < 2 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &CommitInfo{
|
||||
ShortSHA: parts[0],
|
||||
Message: parts[1],
|
||||
}
|
||||
}
|
||||
|
||||
func FormatCommitLine(info *CommitInfo) string {
|
||||
if info == nil {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("> Commit: %s (%s)\n", info.ShortSHA, info.Message)
|
||||
}
|
||||
Reference in New Issue
Block a user