Use porcelain commands

This commit is contained in:
system
2025-10-01 21:59:45 +02:00
parent 128db358fc
commit 3500ec9416

33
main.go
View File

@@ -118,19 +118,32 @@ func doRun() {
return
}
// Count changes by type
// Count changes by type using porcelain status
lines := strings.Split(statusOutput, "\n")
var added, modified, deleted int
for _, line := range lines {
if len(line) >= 2 {
status := line[:2]
if strings.Contains(status, "A") {
// Parse porcelain status format
// First character: index status (staged)
// Second character: working tree status (unstaged)
indexStatus := status[0]
worktreeStatus := status[1]
// Count staged changes
switch indexStatus {
case 'A':
added++
}
if strings.Contains(status, "M") {
case 'M':
modified++
case 'D':
deleted++
}
if strings.Contains(status, "D") {
// Count unstaged changes (only if not already counted as staged)
if worktreeStatus == 'M' && indexStatus != 'M' {
modified++
} else if worktreeStatus == 'D' && indexStatus != 'D' {
deleted++
}
}
@@ -166,11 +179,11 @@ func doRun() {
return
}
// Get commit details
authorName, _ := executeGitCommand("log", "-1", "--format=%an", commitHash)
authorEmail, _ := executeGitCommand("log", "-1", "--format=%ae", commitHash)
commitDate, _ := executeGitCommand("log", "-1", "--format=%ai", commitHash)
commitMessage, _ := executeGitCommand("log", "-1", "--format=%s", commitHash)
// Get commit details using porcelain format
authorName, _ := executeGitCommand("log", "-1", "--pretty=format:%an")
authorEmail, _ := executeGitCommand("log", "-1", "--pretty=format:%ae")
commitDate, _ := executeGitCommand("log", "-1", "--pretty=format:%ai")
commitMessage, _ := executeGitCommand("log", "-1", "--pretty=format:%s")
logger.Info("Changes committed successfully:")
logger.Info(" Branch: %s", branch)