Skip to content

fix: handle backslashes in filenames in _forgit_worktree_changes#500

Merged
sandr01d merged 2 commits intowfxr:mainfrom
sandr01d:fix-add-preview-backslash
Mar 17, 2026
Merged

fix: handle backslashes in filenames in _forgit_worktree_changes#500
sandr01d merged 2 commits intowfxr:mainfrom
sandr01d:fix-add-preview-backslash

Conversation

@sandr01d
Copy link
Collaborator

@sandr01d sandr01d commented Mar 15, 2026

Check list

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have added unit tests for my code
  • I have made corresponding changes to the documentation

Description

Fixes #467

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Test
  • Documentation change

Test environment

  • Shell
    • bash
    • zsh
    • fish
  • OS
    • Linux
    • Mac OS X
    • Windows
    • Others:

Summary by CodeRabbit

  • Bug Fixes

    • Untracked files now properly respect git configuration for visibility and are handled consistently during file selection.
  • Improvements

    • File selection for adding now correctly includes modified and untracked files while excluding already staged or fully tracked files.
  • Tests

    • Added end-to-end tests covering working-tree change detection, including edge cases with special characters in filenames.

@coderabbitai
Copy link

coderabbitai bot commented Mar 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5480951f-4a95-4678-a409-f4858b240de7

📥 Commits

Reviewing files that changed from the base of the PR and between 7a8e066 and 91c4645.

📒 Files selected for processing (2)
  • bin/git-forgit
  • tests/working-tree-changes.test.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • bin/git-forgit

📝 Walkthrough

Walkthrough

Added a new internal helper _forgit_worktree_changes to compute worktree changed, unmerged, and untracked files via git status --porcelain, and refactored _forgit_add to delegate file selection to that helper. Added tests validating behavior with tracked, staged, modified, and untracked files (including backslashes).

Changes

Cohort / File(s) Summary
Worktree Status Helper & Add Command
bin/git-forgit
Added _forgit_worktree_changes to emit changed/unmerged/untracked files (honoring status.showUntrackedFiles); refactored _forgit_add to consume that pipeline and removed inline status color/token handling.
Test Suite
tests/working-tree-changes.test.sh
New Bash test validating _forgit_worktree_changes output includes modified and untracked files (including names with backslashes) and excludes staged/committed files.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • cjappl
  • carlfriedrich

Poem

🐇 I sniffed the status, hopped through the trees,
I gathered changes on the gentlest breeze,
Backslashes tamed, no preview fright,
Tests hop along in the moonlight bright,
A tiny patch, a rabbit's delight. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the specific bug fix addressing backslash handling in the _forgit_worktree_changes function, directly matching the main change.
Description check ✅ Passed The PR description follows the template with all required sections completed: checklist items marked, issue reference provided, type of change selected, and test environment specified.
Linked Issues check ✅ Passed The changes successfully address issue #467 by introducing _forgit_worktree_changes to properly handle backslashes in filenames, with comprehensive tests covering the scenario.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #467: the new helper function, refactored _forgit_add logic, and comprehensive tests for backslash handling in filenames.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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 and usage tips.

Git escapes backslashes with `git status` even when
`core.quotepath=false` is set. Use `--porcelain -z` with `git status` as
a more robust approach to fix this.

Fixes wfxr#467
@sandr01d sandr01d force-pushed the fix-add-preview-backslash branch from 7a8e066 to 91c4645 Compare March 15, 2026 16:34
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/working-tree-changes.test.sh (1)

29-68: Add a config-mode test for status.showUntrackedFiles=no.

The helper explicitly depends on this config, but current tests only validate default behavior.

Suggested test case
+function test_forgit_worktree_changes_respects_show_untracked_no() {
+    local output
+
+    git config status.showUntrackedFiles no
+    output=$(_forgit_worktree_changes)
+
+    assert_not_contains "untracked_file.txt" "$output"
+    assert_not_contains 'untracked_with_\backslash' "$output"
+}
As per coding guidelines "Add or update tests for behavior changes, especially parsing, selection, and cross-shell integration".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/working-tree-changes.test.sh` around lines 29 - 68, Add a new test to
verify _forgit_worktree_changes respects git config
status.showUntrackedFiles=no: create a test function (e.g.,
test_forgit_worktree_changes_respects_showUntrackedFiles_no) that sets the
repo-local config (git config --local status.showUntrackedFiles no), calls
_forgit_worktree_changes to capture output, asserts that untracked entries like
"untracked_file.txt" and 'untracked_with_\backslash' are NOT present while
keeping other behavior (modified files still present), and then restore or unset
the config to avoid affecting other tests; reference _forgit_worktree_changes
and use assert_not_contains/assert_contains as in the existing tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bin/git-forgit`:
- Around line 221-230: The current pipeline in bin/git-forgit uses color tokens
($changed, $unmerged, $untracked) to filter git status output, which breaks when
multiple color keys map to the same ANSI code; replace the grep-based color
filtering with a porcelain-status parsing step that examines the XY status codes
instead. Specifically, after the git -c ... status --porcelain -zs output (the
pipeline that currently goes into tr '\0' '\n'), drop the grep -F -e "$changed"
-e "$unmerged" -e "$untracked" and instead pipe into an awk filter that parses
the leading two-character status (substr($0,1,2)) and only prints lines where
the worktree status (second char, Y) is non-space (Y != " ") or where the entry
is untracked (first char == "?"), ensuring staged-only entries (X != " " and Y
== " ") are excluded; leave the final sed -E
's/^(..[^[:space:]]*)[[:space:]]+(.*)$/[\1]  \2/' intact to format the output.

---

Nitpick comments:
In `@tests/working-tree-changes.test.sh`:
- Around line 29-68: Add a new test to verify _forgit_worktree_changes respects
git config status.showUntrackedFiles=no: create a test function (e.g.,
test_forgit_worktree_changes_respects_showUntrackedFiles_no) that sets the
repo-local config (git config --local status.showUntrackedFiles no), calls
_forgit_worktree_changes to capture output, asserts that untracked entries like
"untracked_file.txt" and 'untracked_with_\backslash' are NOT present while
keeping other behavior (modified files still present), and then restore or unset
the config to avoid affecting other tests; reference _forgit_worktree_changes
and use assert_not_contains/assert_contains as in the existing tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c9e6d183-b12f-417a-927d-6a6a7cc6b7e7

📥 Commits

Reviewing files that changed from the base of the PR and between f7e2d43 and 7a8e066.

📒 Files selected for processing (2)
  • bin/git-forgit
  • tests/working-tree-changes.test.sh

Copy link
Owner

@wfxr wfxr left a comment

Choose a reason for hiding this comment

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

LGTM

@sandr01d sandr01d merged commit 2c17635 into wfxr:main Mar 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preview for git add is broken for files that contain backslashes in their name

2 participants