Some new puzzle levels

This commit is contained in:
Sebastian Morr 2020-09-16 14:16:38 +02:00
parent 35b4dc098a
commit 6292d849b9
10 changed files with 65 additions and 0 deletions

View file

@ -0,0 +1,9 @@
Delete all objects in this repository using git commands only!
Useful commands:
git prune
git fsck
git reflog expire
Note: I'm not sure how to beat this level. :D

View file

@ -0,0 +1,4 @@
TREE=$(git mktree)
git read-tree $TREE
rm -rf .git/refs/*
rm -rf .git/objects/*

View file

@ -0,0 +1,9 @@
echo foo > foo
BLOB=$(git hash-object -w foo)
echo bar > bar
git add .
git commit -m "Initial commit"
echo blabber >> bar
git commit -a -m "Second commit"
git update-ref refs/important HEAD
git update-ref refs/interesting "$BLOB"

View file

@ -0,0 +1 @@
test "$(git cat-file --batch-check --batch-all-objects | wc -l)" -eq 0

View file

@ -0,0 +1 @@
Create two trees pointing to the same blob!

View file

@ -0,0 +1,7 @@
BLOB=$(echo "I am precious" | git hash-object -w --stdin)
git update-index --add --cacheinfo 100644,$BLOB,a
git write-tree
git update-index --force-remove a
git update-index --add --cacheinfo 100644,$BLOB,b
git write-tree
git update-index --force-remove b

View file

@ -0,0 +1,10 @@
TREES=$(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep tree | cut -f1 -d" ")
ALL_TREE_CHILDREN=$(for TREE in $TREES; do
git cat-file -p $TREE | cut -f1 | cut -f3 -d" "
done)
NUMBER_OF_CHILDREN=$(echo "$ALL_TREE_CHILDREN" | wc -l)
UNIQUE_CHILDREN=$(echo "$ALL_TREE_CHILDREN" | sort -u | wc -l)
test "$NUMBER_OF_CHILDREN" -gt "$UNIQUE_CHILDREN"

View file

@ -0,0 +1,3 @@
Construct a chain of three trees.
This is hard! The `git mktree` command might be useful.

View file

@ -0,0 +1,3 @@
git mktree
TREE=$(echo -e "040000 tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\tdir" | git mktree)
echo -e "040000 tree $TREE\tdir" | git mktree

View file

@ -0,0 +1,18 @@
TREES=$(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep tree | cut -f1 -d" ")
for TREE in $TREES; do
if [ "$(git cat-file -p $TREE | wc -l)" -eq 1 ]; then
if [ "$(git cat-file -p $TREE | cut -f1 | grep tree | wc -l)" -eq 1 ]; then
# So the tree has exactly one child, and it is a tree!
TREE2=$(git cat-file -p $TREE | cut -f1 | grep tree | cut -f3 -d" ")
if [ "$(git cat-file -p $TREE2 | wc -l)" -eq 1 ]; then
if [ "$(git cat-file -p $TREE2 | cut -f1 | grep tree | wc -l)" -eq 1 ]; then
# Same for its child! \o/
exit 0
fi
fi
fi
fi
done
exit 1