Created
November 13, 2024 19:41
-
-
Save neilmayhew/f01dd8f807ebc0bdd37c4db154eabf64 to your computer and use it in GitHub Desktop.
A script to reproduce `git fsck` failures on `.gitmodules` history
This file contains 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
#!/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