From 3500ec941636dad3e405117f8454b88d9e542ee9 Mon Sep 17 00:00:00 2001 From: system Date: Wed, 1 Oct 2025 21:59:45 +0200 Subject: [PATCH] Use porcelain commands --- main.go | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 1cb4ddb..a9cb4df 100644 --- a/main.go +++ b/main.go @@ -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)