summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hunter <m@lfurio.us>2026-04-30 01:32:54 -0400
committerMatt Hunter <m@lfurio.us>2026-05-07 19:56:04 -0400
commitedf22dc5e40b3cdfe9beaf3365002ccb3cd527c2 (patch)
tree17a86a35d18fcd506374ff21ee880c77f97c8bb3
parentcee3f0443ff992a8f64f13d66da4867d1db836de (diff)
downloadgit-sonar-edf22dc5e40b3cdfe9beaf3365002ccb3cd527c2.tar.gz
git-sonar-edf22dc5e40b3cdfe9beaf3365002ccb3cd527c2.zip
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 <m@lfurio.us>
Diffstat (limited to '')
-rwxr-xr-xgit-sonar5
1 files 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