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 return
} }
// Count changes by type // Count changes by type using porcelain status
lines := strings.Split(statusOutput, "\n") lines := strings.Split(statusOutput, "\n")
var added, modified, deleted int var added, modified, deleted int
for _, line := range lines { for _, line := range lines {
if len(line) >= 2 { if len(line) >= 2 {
status := 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++ added++
} case 'M':
if strings.Contains(status, "M") {
modified++ 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++ deleted++
} }
} }
@@ -166,11 +179,11 @@ func doRun() {
return return
} }
// Get commit details // Get commit details using porcelain format
authorName, _ := executeGitCommand("log", "-1", "--format=%an", commitHash) authorName, _ := executeGitCommand("log", "-1", "--pretty=format:%an")
authorEmail, _ := executeGitCommand("log", "-1", "--format=%ae", commitHash) authorEmail, _ := executeGitCommand("log", "-1", "--pretty=format:%ae")
commitDate, _ := executeGitCommand("log", "-1", "--format=%ai", commitHash) commitDate, _ := executeGitCommand("log", "-1", "--pretty=format:%ai")
commitMessage, _ := executeGitCommand("log", "-1", "--format=%s", commitHash) commitMessage, _ := executeGitCommand("log", "-1", "--pretty=format:%s")
logger.Info("Changes committed successfully:") logger.Info("Changes committed successfully:")
logger.Info(" Branch: %s", branch) logger.Info(" Branch: %s", branch)