mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-03 19:04:40 +01:00
Some new puzzle levels
This commit is contained in:
parent
35b4dc098a
commit
6292d849b9
10 changed files with 65 additions and 0 deletions
9
levels/puzzle-apocalypse/description
Normal file
9
levels/puzzle-apocalypse/description
Normal 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
|
4
levels/puzzle-apocalypse/goal
Normal file
4
levels/puzzle-apocalypse/goal
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
TREE=$(git mktree)
|
||||||
|
git read-tree $TREE
|
||||||
|
rm -rf .git/refs/*
|
||||||
|
rm -rf .git/objects/*
|
9
levels/puzzle-apocalypse/start
Normal file
9
levels/puzzle-apocalypse/start
Normal 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"
|
1
levels/puzzle-apocalypse/win
Normal file
1
levels/puzzle-apocalypse/win
Normal file
|
@ -0,0 +1 @@
|
||||||
|
test "$(git cat-file --batch-check --batch-all-objects | wc -l)" -eq 0
|
1
levels/puzzle-precious-blob/description
Normal file
1
levels/puzzle-precious-blob/description
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Create two trees pointing to the same blob!
|
7
levels/puzzle-precious-blob/goal
Normal file
7
levels/puzzle-precious-blob/goal
Normal 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
|
10
levels/puzzle-precious-blob/win
Normal file
10
levels/puzzle-precious-blob/win
Normal 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"
|
3
levels/puzzle-trees-all-the-way-down/description
Normal file
3
levels/puzzle-trees-all-the-way-down/description
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Construct a chain of three trees.
|
||||||
|
|
||||||
|
This is hard! The `git mktree` command might be useful.
|
3
levels/puzzle-trees-all-the-way-down/goal
Normal file
3
levels/puzzle-trees-all-the-way-down/goal
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
git mktree
|
||||||
|
TREE=$(echo -e "040000 tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\tdir" | git mktree)
|
||||||
|
echo -e "040000 tree $TREE\tdir" | git mktree
|
18
levels/puzzle-trees-all-the-way-down/win
Normal file
18
levels/puzzle-trees-all-the-way-down/win
Normal 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
|
Loading…
Reference in a new issue