Repository navigation
fix(git-backup): a slug that cannot match its own history is not an empty store (#263) - #267
Merged
Merged
Conversation
…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>
fdaviddpt
force-pushed
the
fix/263-windows-drive-letter
branch
from
July 31, 2026 13:53
2c894cf to
2007c91
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #263.
What was verified, and what was not
The regex at
resolve-paths.sh:145is 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_slugfolds the drive letter only whencygpathis on PATH. Run the matrix:CLAUDE_PROJECT_DIR/c/Users/…c--Users-…c:/Users/…c--Users-…/c/Users/…C--Users-…c:/Users/…c--Users-…With
cygpathpresent 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 withoutcygpath. 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.shuppercases,lib-slug.shlowercases) 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 canonicalC:\…:/c/…,/cygdrive/c/…,c:/…,c:\…. A path with no drive letter still falls through untouched, which is what/tmpand/usrunder MSYS need.scripts/lib-slug.sh— the drive-letter fold is unconditional; it no longer needscygpathto happen. It is also fork-free (two parameter expansions, not atrsubshell — 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 addstaging nothing is indistinguishable from a store with nothing to save, anddiff --cached --quietanswered 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.shnow asks, before staging, whether this slug has any tracked path at all — and if not, whether a sibling differing by case alone does:plus a
systemMessageon 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:
statwould report everything fine.:(icase)on an older git errors and prints nothing, which lands on the previous behaviour rather than on a false accusation.recent.mdandarchive.mdare 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 —
$OSTYPEis nevermsysand there is no drive letter to get wrong — so the platform is simulated rather than required:OSTYPEis forced,cygpathis 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--, notC--) 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
casepatterns follow the locale's collation, and underen_US.UTF-8[A-Z]matches lower-case letters — the trap this repo already hand-works-around in the slugsed. 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 underLC_ALL=en_US.UTF-8.