noodcon's picture mondk's picture
Duplicate from mondk/TerminalBench-DockerLess
b199558
Raw History Blame Contribute Delete
1.04 kB
#!/usr/bin/env bash
# Oracle solution: find the lost commit through fsck, recover the file from the
# right historical revision, tag, ignore and commit.
set -euo pipefail
cd "$TB_WORK"
git config user.name "Release Bot"
git config user.email "release@example.invalid"
# 1. restore src/app.py from "Add config loader"
loader_commit="$(git log --format='%H %s' main | awk '$0 ~ / Add config loader$/ {print $1}' | head -1)"
test -n "$loader_commit"
mkdir -p src
git show "$loader_commit:src/app.py" > src/app.py
# 4. ignore the junk
cat > .gitignore <<'EOF'
*.log
build/
EOF
git add -A
git commit -qm "restore app.py"
# 2. rescue the unreachable commit
wip_commit="$(git fsck --unreachable --no-reflogs 2>/dev/null | awk '$2 == "commit" {print $3}' | while read -r sha; do
if [ "$(git log -1 --format=%s "$sha" 2>/dev/null)" = "wip: plan" ]; then
echo "$sha"
break
fi
done)"
test -n "$wip_commit"
git branch recovered "$wip_commit"
# 3. tag the release commit
git tag v1.0 "$loader_commit"
git status --porcelain