Skip to content

fix(git-backup): a slug that cannot match its own history is not an empty store (#263) - #267

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/263-windows-drive-letter
Jul 31, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/263-windows-drive-letter

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #263.

What was verified, and what was not

The regex at resolve-paths.sh:145 is POSIX-only — confirmed. Everything downstream of it in the report is confirmed too, with one correction and one addition.

The alternation is explained. @jqit-ricky flagged both spellings in one day as the observation they could not account for. It falls out of the code, and it needs a third fact neither of us had: session_dir_slug folds the drive letter only when cygpath is on PATH. Run the matrix:

CLAUDE_PROJECT_DIR cygpath slug
/c/Users/… present c--Users-…
c:/Users/… present c--Users-…
/c/Users/… absent C--Users-…
c:/Users/… absent c--Users-…

With cygpath present both shapes converge and there is no bug at all. The reported failure requires a hook PATH without it — and then the shape resolve-paths could match comes out uppercase while the shape it could not stayed lowercase. One directory, two slugs, alternating with the shape of the handover.

A correction. The report reads the uppercase directory as Claude Code's own. It is not evidence of that: C--Users-ricky-… in the backup store was written by this plugin, on a POSIX-shaped invocation without cygpath. What Claude Code writes under ~/.claude/projects/ is not visible in the report, and on NTFS it cannot be — case-insensitivity makes either spelling resolve. So the two normalisations that look contradictory (resolve-paths.sh uppercases, lib-slug.sh lowercases) are not: the first converts a POSIX path to the native Win32 form, the second applies Claude Code's own fold when slugging it. The defect was never the conflict; it was that the first handled one input shape and the second was conditional on a binary being present.

The fix

scripts/resolve-paths.sh — all four shapes now normalise to one canonical C:\…: /c/…, /cygdrive/c/…, c:/…, c:\…. A path with no drive letter still falls through untouched, which is what /tmp and /usr under MSYS need.

scripts/lib-slug.sh — the drive-letter fold is unconditional; it no longer needs cygpath to happen. It is also fork-free (two parameter expansions, not a tr subshell — this runs on every tool call) and no longer uses ${x,,}, which is bash 4 syntax and a runtime bad substitution on macOS's bash 3.2. That last one is why the branch had zero local coverage: it could not execute on the platform the repo is developed on.

The direction was the one real decision, and it was made by counting who already works. Git for Windows ships cygpath, so the working majority already has the lowercase spelling on disk. Uppercasing would have fixed one reporter and renamed every other store — the loud bug traded for a quiet one.

The second half, which is the more important half

Even with the slug fixed, git add staging nothing is indistinguishable from a store with nothing to save, and diff --cached --quiet answered the question it was asked correctly while answering the one that mattered wrongly. Same defect class as #252 and #253, same answer: three states, not two.

50-git-backup.sh now asks, before staging, whether this slug has any tracked path at all — and if not, whether a sibling differing by case alone does:

ERROR: this project's memory is tracked as 'C--Users-…/' but this session
computed 'c--Users-…/' — git pathspecs are case-sensitive, so nothing under
'c--Users-…/' can ever be staged and the backup has STOPPED for this project.

plus a systemMessage on the next prompt, because the condition never clears itself and a log line alone is exactly what let the original run for twelve days.

Four deliberate choices in that guard:

  • Asked of git, not of the filesystem. A case-insensitive filesystem is precisely what hides this; stat would report everything fine.
  • Asked before staging and regardless of whether anything changed. The condition is structural. A store that is clean right now will still lose the next thing it writes.
  • A report requires positive evidence. A brand-new slug has no tracked path either, and that is the normal first backup — it must commit, not accuse. Only a tracked sibling differing by case alone triggers it. :(icase) on an older git errors and prints nothing, which lands on the previous behaviour rather than on a false accusation.
  • Nothing is renamed for you. Same reason a diverged remote is not merged for you: recent.md and archive.md are rewritten wholesale by consolidation, so a wrong automatic repair corrupts memory silently. The report names both spellings and the two-step rename (two steps, because a case-only rename is a no-op on a case-insensitive filesystem).

On memory already committed under the wrong spelling: correctness going forward, plus a loud report — not migration. An existing store keeps its history under whichever spelling it has; if that is not the one this machine now computes, the guard says so on the next backup instead of losing another twelve days. Automating the rename would be the third bullet's mistake made once more.

Tests

tests/test_windows_drive_slug_263.py, written before the fix. Red first: 13 failed, 5 passed. Green after: 18 passed. Full suite 1200 passed, 42 skipped, twice — once before the locale hardening below and once after.

This bug is invisible on macOS and Linux by construction — $OSTYPE is never msys and there is no drive letter to get wrong — so the platform is simulated rather than required: OSTYPE is forced, cygpath is a stub, both presence and absence are parametrised, and the git half needs no Windows at all because pathspec casing is the same everywhere. The 12 shape × cygpath combinations assert one slug; separate tests pin the direction (c--, not C--) so a later change cannot stabilise it at the wrong case, and pin that a POSIX path is untouched.

Five tests passed in the red run, which is the point of listing the number: the lowercase-Windows-shape cases already agreed by accident, and the clean-store and first-backup cases must keep behaving exactly as before.

One thing found on the way

case patterns follow the locale's collation, and under en_US.UTF-8 [A-Z] matches lower-case letters — the trap this repo already hand-works-around in the slug sed. Written naively, a locale-widened match would have indexed past the end of the lower-case alphabet and silently deleted the drive letter. The membership test is now a literal substring and therefore collation-free; verified under LC_ALL=en_US.UTF-8.

…mpty store (#263)

CLAUDE_PROJECT_DIR does not always arrive in the same shape on the same
machine. resolve-paths.sh normalised the drive letter only for the POSIX
form, and session_dir_slug's fold ran only when cygpath was on PATH — so one
Windows directory produced two slugs, `C--Users-…` and `c--Users-…`, in the
same day. NTFS is case-insensitive so memory saved normally; git's pathspecs
are not, so `git add -- "$SLUG/"` matched nothing for twelve days and the
backup logged success every few minutes.

All four shapes are normalised now (POSIX, /cygdrive, and both drive forms),
and the fold no longer depends on cygpath. It stays lower-case deliberately:
Git for Windows ships cygpath, so the working majority already has that
spelling on disk, and uppercasing would rename every other store.

The larger half is that nothing could tell a dead pathspec from a clean
store. Three states now, not two — committed, clean, and "this slug cannot
address its own history", asked of git rather than of the filesystem and
before staging rather than after. Nothing is renamed for you, for the same
reason a diverged remote is not merged for you.

Co-Authored-By: Max <noreply>
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.

A lowercase drive letter in CLAUDE_PROJECT_DIR makes git add match nothing, and the backup reports success

1 participant