diff --git a/levels/puzzle-apocalypse/description b/levels/puzzle-apocalypse/description new file mode 100644 index 0000000..917154d --- /dev/null +++ b/levels/puzzle-apocalypse/description @@ -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 diff --git a/levels/puzzle-apocalypse/goal b/levels/puzzle-apocalypse/goal new file mode 100644 index 0000000..b24313d --- /dev/null +++ b/levels/puzzle-apocalypse/goal @@ -0,0 +1,4 @@ +TREE=$(git mktree) +git read-tree $TREE +rm -rf .git/refs/* +rm -rf .git/objects/* diff --git a/levels/puzzle-apocalypse/start b/levels/puzzle-apocalypse/start new file mode 100644 index 0000000..62fdc47 --- /dev/null +++ b/levels/puzzle-apocalypse/start @@ -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" diff --git a/levels/puzzle-apocalypse/win b/levels/puzzle-apocalypse/win new file mode 100644 index 0000000..3409172 --- /dev/null +++ b/levels/puzzle-apocalypse/win @@ -0,0 +1 @@ +test "$(git cat-file --batch-check --batch-all-objects | wc -l)" -eq 0 diff --git a/levels/puzzle-precious-blob/description b/levels/puzzle-precious-blob/description new file mode 100644 index 0000000..151d979 --- /dev/null +++ b/levels/puzzle-precious-blob/description @@ -0,0 +1 @@ +Create two trees pointing to the same blob! diff --git a/levels/puzzle-precious-blob/goal b/levels/puzzle-precious-blob/goal new file mode 100644 index 0000000..6f7a3b3 --- /dev/null +++ b/levels/puzzle-precious-blob/goal @@ -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 diff --git a/levels/puzzle-precious-blob/win b/levels/puzzle-precious-blob/win new file mode 100644 index 0000000..b7f955f --- /dev/null +++ b/levels/puzzle-precious-blob/win @@ -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" diff --git a/levels/puzzle-trees-all-the-way-down/description b/levels/puzzle-trees-all-the-way-down/description new file mode 100644 index 0000000..f38ca57 --- /dev/null +++ b/levels/puzzle-trees-all-the-way-down/description @@ -0,0 +1,3 @@ +Construct a chain of three trees. + +This is hard! The `git mktree` command might be useful. diff --git a/levels/puzzle-trees-all-the-way-down/goal b/levels/puzzle-trees-all-the-way-down/goal new file mode 100644 index 0000000..5e62d7d --- /dev/null +++ b/levels/puzzle-trees-all-the-way-down/goal @@ -0,0 +1,3 @@ +git mktree +TREE=$(echo -e "040000 tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\tdir" | git mktree) +echo -e "040000 tree $TREE\tdir" | git mktree diff --git a/levels/puzzle-trees-all-the-way-down/win b/levels/puzzle-trees-all-the-way-down/win new file mode 100644 index 0000000..4a8a6d2 --- /dev/null +++ b/levels/puzzle-trees-all-the-way-down/win @@ -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