Skip to content

[ai] Fix word-splitting in git status parsing#14

Closed
pablopunk wants to merge 1 commit into
masterfrom
ai/pablopunk__bashy-word-splitting
Closed

[ai] Fix word-splitting in git status parsing#14
pablopunk wants to merge 1 commit into
masterfrom
ai/pablopunk__bashy-word-splitting

Conversation

@pablopunk

@pablopunk pablopunk commented Jul 6, 2026

Copy link
Copy Markdown
Owner

What: Fixed word-splitting bug in git status output parsing. Replaced for loop with while IFS= read -r to iterate lines instead of whitespace-split words.

Found by: Static analysis — unquoted variable in for-loop iterates over IFS-split words, not lines, causing incorrect porcelain status parsing.

Fix: Changed loop from for line in gitstatus to while IFS= read -r line with proper heredoc. Updated regex patterns to check both index (position 1) and working tree (position 2) columns in porcelain v1 format using substring checks.

Tested:

  • Clean repo shows clean checkmark
  • Untracked file shows + symbol
  • Modified file shows bullet symbol
  • Staged delete shows delete symbol
  • Smoke test passes (bash syntax check OK)

Summary by CodeRabbit

  • Bug Fixes
    • Improved status detection to handle file and branch changes more reliably.
    • Fixed an issue where status output could be misread due to whitespace or token splitting.

@pablopunk pablopunk added the ai label Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The change modifies the bashy script's git status parsing to iterate over git status --porcelain --branch output using a while IFS= read -r line loop fed via a here-string, replacing the previous for line in $gitstatus word-splitting approach. Flag detection for delete, modify, new/untracked files now uses fixed-position character checks, while ahead/behind detection continues using regex matching. The resulting delete, change, new, ahead, and behind flags still drive the final status symbol output.

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: replacing word-splitting in git status parsing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
bashy (1)

34-35: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Ahead/behind regex matches any line, not just the ## branch header.

[[ $line =~ behind ]] / [[ $line =~ ahead ]] run against every line in the loop, including file status lines. A tracked file whose name contains "ahead" or "behind" (e.g. ahead_calc.py) would falsely set the ahead/behind flag. Since this loop was just reworked to fix line-splitting issues, it's a good time to anchor the check to the branch header line.

🔧 Proposed fix to scope the match to the `##` header line
-  [[ $line =~ behind ]] && behind=1
-  [[ $line =~ ahead ]] && ahead=1
+  if [[ ${line:0:2} == '##' ]]; then
+    [[ $line =~ behind ]] && behind=1
+    [[ $line =~ ahead ]] && ahead=1
+  fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bashy` around lines 34 - 35, The ahead/behind detection in the loop is too
broad because `[[ $line =~ behind ]]` and `[[ $line =~ ahead ]]` match any line,
including file names and status lines. Update the matching logic in the `bashy`
loop so the `behind` and `ahead` flags are only set when processing the `##`
branch header line, using the existing line variable and the reworked
line-splitting flow to keep the check scoped to the header.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@bashy`:
- Around line 34-35: The ahead/behind detection in the loop is too broad because
`[[ $line =~ behind ]]` and `[[ $line =~ ahead ]]` match any line, including
file names and status lines. Update the matching logic in the `bashy` loop so
the `behind` and `ahead` flags are only set when processing the `##` branch
header line, using the existing line variable and the reworked line-splitting
flow to keep the check scoped to the header.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ce76726e-c6ac-4e5e-a741-d2fdca9bde36

📥 Commits

Reviewing files that changed from the base of the PR and between 9af56ab and 864c8c0.

📒 Files selected for processing (1)
  • bashy

@pablopunk

Copy link
Copy Markdown
Owner Author

Repo not maintained — closing per Pablo

@pablopunk pablopunk closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant