Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@
.gitignore text eol=lf
.gitattributes text eol=lf
LICENSE text eol=lf

# samebytes' stat-cache hook (.githooks/) MUST be LF: core.autocrlf is true in
# Git for Windows' system config, and a CRLF `#!/bin/sh` fails as "bad
# interpreter", silently, after every checkout.
.githooks/* text eol=lf
60 changes: 60 additions & 0 deletions .githooks/drive-restat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh
#
# Repair git's stat cache after Google Drive lies about file size.
#
# THE BUG
# Diagnosed in economicspace, whose tree has lived in synced folders: first a
# Google Drive File Stream mount (G:), then OneDrive. When git
# writes a file during checkout / merge / pull and immediately stats it, Drive
# returns a placeholder size of 16384 bytes rather than the real size. Git
# caches that bogus number in the index:
#
# $ git ls-files --debug master.py
# size: 16384 <- what Drive told git at write time
# $ ls -l master.py
# 328335 <- the truth, moments later
#
# Every later `git status` compares the two, sees a size mismatch, and reports
# the file as modified. Git never re-reads the content, because differing
# size is normally conclusive proof of a change, a sound inference from a
# false premise. So the tree looks permanently dirty while `git diff` shows
# nothing, and `git update-index --refresh` refuses to help for the same
# reason. The knock-on effect is worse than the cosmetics: `git merge
# --ff-only` and `git checkout` abort with "your local changes would be
# overwritten", so a merged PR silently fails to land locally.
#
# THE REPAIR
# Re-stat the affected entries once Drive has settled. A file is touched only
# when its content hash ALREADY matches what the index records, so this cannot
# stage, hide, or discard a real modification, verified by test. Anything
# genuinely changed is left exactly as it was.
#
# Shipped by samebytes; `python -m samebytes hooks install <repo>` copies it
# and the three post-* hooks into <repo>/.githooks and sets core.hooksPath,
# and `hooks check` says when a copy has drifted. The repo's .gitattributes
# must pin `.githooks/* text eol=lf`. Safe to run by hand at any
# time: sh .githooks/drive-restat.sh

# One path per LINE, never `for f in $(...)`: word splitting cut
# `_START HERE.vbs` into two names that both failed `-f`, so the one tracked
# path with a space in it could never be repaired. The here-document (not a
# pipe) keeps the loop in this shell, so the count survives it; quotePath off
# hands non-ASCII names over as-is rather than octal-escaped.
restated=0
modified=$(git -c core.quotePath=false ls-files -m)
while IFS= read -r f; do
[ -n "$f" ] && [ -f "$f" ] || continue
worktree=$(git hash-object -- "$f" 2>/dev/null) || continue
indexed=$(git rev-parse ":$f" 2>/dev/null) || continue
if [ "$worktree" = "$indexed" ]; then
git update-index -- "$f" 2>/dev/null && restated=$((restated + 1))
fi
done <<EOF
$modified
EOF

if [ "$restated" -gt 0 ]; then
echo "drive-restat: repaired $restated stale index entr$([ "$restated" -eq 1 ] && echo y || echo ies)"
fi

exit 0
3 changes: 3 additions & 0 deletions .githooks/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
# Runs after checkout / switch / clone. See drive-restat.sh for why.
exec "$(dirname "$0")/drive-restat.sh"
3 changes: 3 additions & 0 deletions .githooks/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
# Runs after merge / pull. See drive-restat.sh for why.
exec "$(dirname "$0")/drive-restat.sh"
3 changes: 3 additions & 0 deletions .githooks/post-rewrite
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
# Runs after rebase / commit --amend rewrites history. See drive-restat.sh.
exec "$(dirname "$0")/drive-restat.sh"
16 changes: 16 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,19 @@ jobs:
run: python -m pip install -e ".[test]"
- name: Test
run: python -m pytest -q

# .githooks/ holds samebytes' stat-cache hook (this tree lives in a synced
# folder). Drift, CRLF, a missing eol=lf pin or a missing executable bit
# each make a copy silently useless after a checkout; this fails on any of
# them. The tag is the samebytes release the copies came from.
hooks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.14"
- name: Hooks match samebytes
run: |
python -m pip install "samebytes @ git+https://github.com/loggger101/samebytes@v0.1.0"
python -m samebytes hooks check .
4 changes: 3 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ the way it does" is the list. Rules:
Consumers pin the tag (economicspace: `requirements-ui.txt`, and its
`launch_ui.py` shim compares the tag to the installed version).
- The tree lives in OneDrive. `*-DESKTOP-*` files are sync-conflict copies:
diff, then delete; never commit one. Never `git stash`.
diff, then delete; never commit one. Never `git stash`. `.githooks/` is
samebytes' stat-cache hook (opt in with `git config core.hooksPath
.githooks`); CI's `hooks` job holds the copies to the samebytes tag it names.
Loading