Skip to content

Instantly share code, notes, and snippets.

@neilmayhew
Created November 13, 2024 19:41
Show Gist options
  • Save neilmayhew/f01dd8f807ebc0bdd37c4db154eabf64 to your computer and use it in GitHub Desktop.
Save neilmayhew/f01dd8f807ebc0bdd37c4db154eabf64 to your computer and use it in GitHub Desktop.
A script to reproduce `git fsck` failures on `.gitmodules` history
#!/usr/bin/env -S bash -euo pipefail
# Reproduce git fsck problem
DIR=$(mktemp -d)
trap 'cd /; rm -rf "$DIR"' EXIT
cd "$DIR"
git init
git config commit.gpgsign false
git submodule add https://github.com/git/book.git-scm.com.git # Can be any repo
git commit -am "Add submodule"
# fsck will succeed
git fsck
sed -i~ 's#github.com/#github.com:#' .gitmodules
git commit -am "Mess up submodule url"
git revert --no-edit @
# Predict hash of problem blob
echo -n "Problem blob: "
echo @^:.gitmodules | git cat-file --batch-check='%(objectname)'
# fsck will fail on problem blob
git fsck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment