diff --git a/levels/commit-rhombus/description b/levels/commit-rhombus/description new file mode 100644 index 0000000..acf8162 --- /dev/null +++ b/levels/commit-rhombus/description @@ -0,0 +1,5 @@ +A commit can have multiple parents! You can specify the -p option multiple times, like this: + + git commit-tree -m "Description" -p -p + +Build a rhombus shape from commits, where two commits point to the same parent, and then a fourth commit points to both of them. diff --git a/levels/commit-rhombus/start b/levels/commit-rhombus/start new file mode 100644 index 0000000..f74e07d --- /dev/null +++ b/levels/commit-rhombus/start @@ -0,0 +1,5 @@ +TREE=$(git write-tree) +SOUTH=$(git commit-tree $TREE -m "South") +EAST=$(git commit-tree $TREE -m "East" -p $SOUTH) +WEST=$(git commit-tree $TREE -m "West" -p $SOUTH) +NORTH=$(git commit-tree $TREE -m "Nort" -p $EAST -p $WEST) diff --git a/levels/commit-rhombus/win b/levels/commit-rhombus/win new file mode 100644 index 0000000..2364153 --- /dev/null +++ b/levels/commit-rhombus/win @@ -0,0 +1,10 @@ +COMMITS=$(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep commit | cut -f1 -d" ") + +for COMMIT in $COMMITS; do + # My first parent's parents has to be the same as my second parent's parent. + if [ "$(git rev-parse --verify -q $COMMIT^1^)" = "$(git rev-parse --verify -q $COMMIT^2^)" ]; then + exit 0 + fi +done + +exit 1 diff --git a/levels/tree-nested/description b/levels/tree-nested/description new file mode 100644 index 0000000..8a30ffc --- /dev/null +++ b/levels/tree-nested/description @@ -0,0 +1,5 @@ +Trees can also point to other trees! This way, they can basically describe nested directory structures. + +When you add a file inside of a directory to the index, and then call `git write-tree`, it will automatically do the correct thing. + +To solve this level, build a little stick figure, as shown on the left - a tree that points to two blobs, and to a tree that points to two blobs. diff --git a/levels/tree-nested/goal b/levels/tree-nested/goal new file mode 100644 index 0000000..dfb9bef --- /dev/null +++ b/levels/tree-nested/goal @@ -0,0 +1,7 @@ +echo "I'm the left arm" > arm1 +echo "I'm the right arm" > arm2 +mkdir hip +echo "I'm the left leg" > hip/leg1 +echo "I'm the right leg" > hip/leg2 +git add . +git write-tree diff --git a/levels/tree-nested/start b/levels/tree-nested/start new file mode 100644 index 0000000..e69de29 diff --git a/levels/tree-nested/win b/levels/tree-nested/win new file mode 100644 index 0000000..e0cc491 --- /dev/null +++ b/levels/tree-nested/win @@ -0,0 +1,16 @@ +TREES=$(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep tree | cut -f1 -d" ") + +for OUTER_TREE in $TREES; do + NUMBER_OF_BLOB_CHILDREN=$(git cat-file -p $OUTER_TREE | cut -f2 -d" " | grep blob | wc -l) + NUMBER_OF_TREE_CHILDREN=$(git cat-file -p $OUTER_TREE | cut -f2 -d" " | grep tree | wc -l) + + if [ $NUMBER_OF_BLOB_CHILDREN -eq 2 -a $NUMBER_OF_TREE_CHILDREN -eq 1 ]; then + TREE_CHILD=$(git cat-file -p $OUTER_TREE | cut -f1 | grep tree | cut -d" " -f3) + NUMBER_OF_BLOB_CHILDREN_OF_TREE_CHILD=$(git cat-file -p $TREE_CHILD | cut -f2 -d" " | grep blob | wc -l) + if [ $NUMBER_OF_BLOB_CHILDREN_OF_TREE_CHILD -eq 2 ]; then + exit 0 + fi + fi +done + +exit 1