Skip to content

fix(strategy): keep non-ASCII staged paths literal so commit linking matches - #2399

Open
wangzhengzhuo05 wants to merge 1 commit into
entireio:mainfrom
wangzhengzhuo05:fix/nul-delimited-staged-files
Open

fix(strategy): keep non-ASCII staged paths literal so commit linking matches#2399
wangzhengzhuo05 wants to merge 1 commit into
entireio:mainfrom
wangzhengzhuo05:fix/nul-delimited-staged-files

Conversation

@wangzhengzhuo05

Copy link
Copy Markdown

What

getStagedFiles in cmd/entire/cli/strategy/manual_commit_hooks.go now parses git diff --cached --name-only -z and splits the output on NUL, so staged paths are returned literally instead of as git's quoted/C-escaped display form.

Why

With git's default core.quotePath=true, the newline-delimited --name-only output quotes and C-escapes unusual pathnames — café.go comes back as the display string "caf\303\251.go". That string was exact-compared against the literal path stored in SessionState.FilesTouched, so a session that touched only a non-ASCII file was classified as contributing no content to the commit: the commit was still created, but it received no Entire-Checkpoint trailer and its provenance (entire explain attribution) was incomplete. Reported with a focused control/canary reproduction in #2398: an ASCII control file got its trailer, an otherwise equivalent UTF-8 canary did not.

How

  • Pass -z to the git invocation and iterate the NUL-delimited fields, keeping filepath.ToSlash on every entry.
  • Drop the \r\n\n normalization: it only existed to unwrap the newline framing, and -z emits NUL-terminated, unquoted names.
  • The function's contract is unchanged: (non-nil empty slice, nil) when nothing is staged, (nil, err) only when git itself fails, and the same error wrapping.
  • This follows the precedent already in the same package: priorAICommitFiles in cmd/entire/cli/strategy/telemetry_signals.go uses -z for the same reason, so paths match their FilesTouched form.

Tests

New cmd/entire/cli/strategy/staged_files_quoting_test.go, TestGetStagedFiles_PreservesNonASCIIPaths: sets core.quotePath true explicitly, stages a literal café.go plus an ASCII control.go, and asserts both come back literal and that no returned entry is git-quoted or C-escaped.

$ gofmt -l cmd/entire/cli/strategy/manual_commit_hooks.go cmd/entire/cli/strategy/staged_files_quoting_test.go
(no output)
$ go test ./cmd/entire/cli/strategy/ -count=1
ok  	github.com/entireio/cli/cmd/entire/cli/strategy	25.187s
$ go build ./...
(exit 0)

Mutation check

Reverting only the fix (removing -z, i.e. the previous behaviour) makes the new test fail with exactly the string from the report — the assertion output is the single staged entry "\"caf\\303\\251.go\"\ncontrol.go\n", which contains neither literal filename. Restoring -z returns the package suite to green, so the test guards the defect rather than the implementation.

Fixes #2398.

…matches

git quotes and C-escapes unusual paths in `--name-only` output by default
(core.quotePath=true), so getStagedFiles returned `café.go` as the display
string `"caf\303\251.go"`. The exact comparison against the literal entry in
SessionState.FilesTouched then failed, the session was treated as having no
overlap with the commit, and the Entire-Checkpoint trailer was omitted.

Parse the `-z` NUL-delimited output instead, as priorAICommitFiles in this
package already does, and drop the CRLF normalization that only existed to
unwrap the newline framing.

Fixes entireio#2398.
Copilot AI lite review requested due to automatic review settings September 13, 2026 10:18
@wangzhengzhuo05
wangzhengzhuo05 requested a review from a team as a code owner September 13, 2026 10:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved issues remain, and regression coverage validates the fix.

Pull request overview

Fixes commit-to-session linking for non-ASCII staged paths by preserving literal Git filenames.

Changes:

  • Parses staged paths using Git’s NUL-delimited output.
  • Adds regression coverage for non-ASCII filenames.
File summaries
File Description
cmd/entire/cli/strategy/staged_files_quoting_test.go Verifies literal non-ASCII and ASCII paths.
cmd/entire/cli/strategy/manual_commit_hooks.go Uses NUL-delimited staged-path parsing.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Checkpoint linking fails for non-ASCII filenames

2 participants