Skip to content

[bug/4] Resolved staged filenames droping first character of filename#8

Merged
justinkumpe merged 1 commit intomainfrom
bug/4
Feb 13, 2026
Merged

[bug/4] Resolved staged filenames droping first character of filename#8
justinkumpe merged 1 commit intomainfrom
bug/4

Conversation

@justinkumpe
Copy link
Member

@justinkumpe justinkumpe commented Feb 13, 2026

resolves #4

Summary by Sourcery

Fix parsing of git status output to correctly capture full staged and unstaged file paths and adjust git command output trimming.

Bug Fixes:

  • Correct staged file path parsing so filenames are no longer missing their first character when reading git status output.
  • Fix unstaged file path parsing to be robust against leading whitespace in git status lines.

Enhancements:

  • Adjust git command output handling to preserve leading whitespace while trimming trailing newlines only.

@justinkumpe justinkumpe self-assigned this Feb 13, 2026
@justinkumpe justinkumpe added the bug Something isn't working label Feb 13, 2026
@justinkumpe justinkumpe linked an issue Feb 13, 2026 that may be closed by this pull request
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 13, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes parsing of git status output so staged/unstaged filenames no longer lose their first character, and adjusts git command output trimming to preserve leading whitespace while removing only trailing whitespace.

Sequence diagram for execGit stdout trimming behavior

sequenceDiagram
    actor ExtensionCode
    participant GitUtils as GitUtils_execGit
    participant ChildProcess as child_process_exec

    ExtensionCode->>GitUtils: execGit(cwd, args)
    activate GitUtils
    GitUtils->>ChildProcess: exec(cwd, args, callback)
    activate ChildProcess

    ChildProcess-->>GitUtils: callback(error, stdout, stderr)
    deactivate ChildProcess

    alt error is non null
        GitUtils-->>ExtensionCode: reject(new Error(stderr or error.message))
    else success
        GitUtils->>GitUtils: trimmed = stdout.trimEnd()
        GitUtils-->>ExtensionCode: resolve(trimmed)
    end
    deactivate GitUtils
Loading

File-Level Changes

Change Details Files
Correct parsing of staged and unstaged file paths from git status output to avoid dropping the first character and to tolerate leading whitespace.
  • For staged entries, use trimStart() on each status line, derive the status from the first character of the trimmed string, and compute the file path by slicing from index 2 and trimming surrounding whitespace.
  • For unstaged entries, use trimStart() before inspecting status characters, derive the status using the second character when non-space or the first otherwise, and compute the file path from slice(2).trim().
src/webviewProvider.ts
Preserve leading whitespace in git command output while still stripping trailing newlines and spaces.
  • Replace stdout.trim() with stdout.trimEnd() in the git execution helper so only trailing whitespace is removed, keeping leading spaces that may be meaningful for downstream parsers.
src/gitUtils.ts

Assessment against linked issues

Issue Objective Addressed Explanation
#4 Parse staged file paths from git status output without dropping the first character of the filename.
#4 Avoid stripping leading whitespace from git command output so that status lines are parsed correctly.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • In both staged and unstaged parsing, the comment says we “skip 2 status chars + space” but the code uses trimmed.slice(2).trim(), which actually starts at the second index and then trims the space; consider updating the comment or using slice(3) so the implementation and explanation align.
  • For the unstaged entries, the .filter still uses l.charAt(...) while the .map uses trimmed = l.trimStart(), which could diverge if lines ever contain leading whitespace; consider basing both the filter and map on the same trimmed value for consistency.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In both staged and unstaged parsing, the comment says we “skip 2 status chars + space” but the code uses `trimmed.slice(2).trim()`, which actually starts at the second index and then trims the space; consider updating the comment or using `slice(3)` so the implementation and explanation align.
- For the unstaged entries, the `.filter` still uses `l.charAt(...)` while the `.map` uses `trimmed = l.trimStart()`, which could diverge if lines ever contain leading whitespace; consider basing both the filter and map on the same `trimmed` value for consistency.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@justinkumpe justinkumpe added this pull request to the merge queue Feb 13, 2026
Merged via the queue into main with commit 9423f43 Feb 13, 2026
5 checks passed
@justinkumpe justinkumpe deleted the bug/4 branch February 13, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Staged Changes dropping 1st character from file name

1 participant