Skip to content

Conversation

@vsumner
Copy link
Contributor

@vsumner vsumner commented Jan 19, 2026

Summary

  • improve git porcelain parsing for untracked/edge cases
  • ensure untracked file stats remain available when git diff fails
  • add targeted tests for git stats handling

Summary by cubic

Hardened git stats parsing to include untracked files and avoid failures when git diff or HEAD is unavailable. Added a formatting helper and tests to keep file change summaries reliable.

  • Bug Fixes

    • Parse git status --porcelain (tracked and ??) and handle quoted/escaped paths.
    • Count lines for untracked files by reading files directly.
    • Return empty stats for non-git dirs; tolerate git diff/HEAD absence.
  • New Features

    • formatFileChanges outputs a concise summary, with optional notepadPath highlight.
    • Export git-stats utilities via shared index.

Written for commit 0845588. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-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.

3 issues found across 3 files

Confidence score: 3/5

  • Some risk due to concrete parsing issues in src/shared/git-stats.ts that can misclassify tracked/untracked files and report incorrect stats when paths contain spaces or special characters.
  • Test flakiness risk: src/shared/git-stats.test.ts uses a shared mutable repo path, so concurrent runs or leftovers can cause intermittent failures.
  • Pay close attention to src/shared/git-stats.ts, src/shared/git-stats.test.ts - path parsing correctness and test isolation.
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/shared/git-stats.test.ts">

<violation number="1" location="src/shared/git-stats.test.ts:8">
P2: Tests share a mutable git repo at a fixed path, so failures or concurrent runs can leave/modify state and cause flakiness</violation>
</file>

<file name="src/shared/git-stats.ts">

<violation number="1" location="src/shared/git-stats.ts:78">
P2: Untracked file paths from `git status --porcelain` are used without unquoting, so quoted/escaped paths (spaces/special chars) fail to read and report wrong stats/path.</violation>

<violation number="2" location="src/shared/git-stats.ts:112">
P2: Tracked file paths are parsed with a leading space, so staged adds/deletes are misclassified when matching against git diff output.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link

@cubic-dev-ai cubic-dev-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.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/shared/git-stats.ts">

<violation number="1" location="src/shared/git-stats.ts:122">
P2: Status map keys are unquoted but numstat paths stay quoted, so files with tabs/newlines/backslashes are misclassified as modified instead of added/deleted.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

// For untracked files: path at index 3
const pathStart = trimmed.startsWith("??") ? 3 : 2
const rawPath = trimmed.substring(pathStart)
const path = parsePorcelainPath(rawPath)
Copy link

@cubic-dev-ai cubic-dev-ai bot Jan 19, 2026

Choose a reason for hiding this comment

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

P2: Status map keys are unquoted but numstat paths stay quoted, so files with tabs/newlines/backslashes are misclassified as modified instead of added/deleted.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/shared/git-stats.ts, line 122:

<comment>Status map keys are unquoted but numstat paths stay quoted, so files with tabs/newlines/backslashes are misclassified as modified instead of added/deleted.</comment>

<file context>
@@ -110,7 +118,8 @@ export function getGitDiffStats(directory: string): GitFileStat[] {
       const pathStart = trimmed.startsWith("??") ? 3 : 2
-      const path = trimmed.substring(pathStart)
+      const rawPath = trimmed.substring(pathStart)
+      const path = parsePorcelainPath(rawPath)
       const status = parseFileStatus(line)
       statusMap.set(path, status)
</file context>
Fix with Cubic

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.

1 participant