From edf22dc5e40b3cdfe9beaf3365002ccb3cd527c2 Mon Sep 17 00:00:00 2001 From: Matt Hunter Date: Thu, 30 Apr 2026 01:32:54 -0400 Subject: Fix unmerged paths being double counted in status There are a couple edge-cases that these basic regexes over the status indicators might double count as different change stages. These involve the status symbols used for unmerged paths. For instance, "DD $path" is printed for a conflicted file which has been deleted by both sides of a merge. However, "D" is a valid character for both regular staged and unstaged file deletions. Catch and filter out these problematic "unmerged path" cases by replacing one of the duplicate characters in them with a "U". Paths will only ever contain a "U" on either side of their status if they are in an unmerged state, and will thus prevent the staged/unstaged regexes from matching them. This solution works for git-sonar, since we don't care to distinguish between AA/AU/UA or DD/DU/UD. We simply report whether any unmerged path involved an "addded" or "deleted" status on either side, as opposed to more common "both modified (UU)" cases. Signed-off-by: Matt Hunter --- git-sonar | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/git-sonar b/git-sonar index 4978818..47f3a7f 100755 --- a/git-sonar +++ b/git-sonar @@ -124,7 +124,8 @@ line_count() { } status_count() { - echo "$git_status" | grep -E "$1" | line_count + # Use a sed transform to prevent unmerged paths from being miscounted + echo "$git_status" | sed -nE "s/^AA /AU /;s/^DD /DU /;/${1}/p" | line_count } print_commit_range() { @@ -201,7 +202,7 @@ element_unstaged() { element_unmerged() { if [ -n "$opt_status" ]; then for x in A D U; do - if cnt="$(status_count "^(${x}${x}|U${x}|${x}U) ")"; then + if cnt="$(status_count "^(U${x}|${x}U) ")"; then printf '%s%b%s%b' "$cnt" "$STATUS_COLOR_UNMERGED" "$x" "$COLOR_DEFAULT" fi done -- cgit v1.2.3