From 09bbf7a0add1c2dc3df61c3488e6c8bf7f9d36f6 Mon Sep 17 00:00:00 2001 From: blinry Date: Tue, 2 Feb 2021 16:42:55 +0100 Subject: [PATCH] First storification of the index chapter --- levels/index/auto | 29 ----------------------- levels/index/change | 25 ++++++++++++++++++++ levels/index/compare | 45 ++++++++++++++++++++++++++++++++++++ levels/index/new | 22 +++++++----------- levels/index/sequence | 8 +++---- levels/index/steps | 53 +++++++++++++++++++++++++++++++++++++++++++ levels/intro/sequence | 1 + levels/sequence | 3 --- scenes/chapter.gd | 2 +- 9 files changed, 136 insertions(+), 52 deletions(-) delete mode 100644 levels/index/auto create mode 100644 levels/index/change create mode 100644 levels/index/compare create mode 100644 levels/index/steps diff --git a/levels/index/auto b/levels/index/auto deleted file mode 100644 index 0340a54..0000000 --- a/levels/index/auto +++ /dev/null @@ -1,29 +0,0 @@ -title = Capturing the status quo -cards = file-new file-delete commit-auto - -[description] - -So far, you have made commits using a pretty convenient command, which captures the complete working directory as it is in a commit. See how the card says something about "add"? - -Let's try using that one again! (Only pay attention to the white, actual files for now!) - -[setup] - -echo a > a -echo b > b -echo c > c -git add . -git commit -m "Initial commit" - -git commit -m "Nothing changed" --allow-empty - -[win] - -# Make a single commit where you modify a file ... -git show --name-status --oneline | grep '^M ' - -# ... add a new file ... -git show --name-status --oneline | grep '^A ' - -# ... and delete a file. -git show --name-status --oneline | grep '^D ' diff --git a/levels/index/change b/levels/index/change new file mode 100644 index 0000000..e292624 --- /dev/null +++ b/levels/index/change @@ -0,0 +1,25 @@ +title = Update files in the index +cards = add commit + +[description] + +When we change files, the index won't change on its own. We have to use `git add` to update the index to the changed version of the file. + +Let's try that! + +[setup] + +echo "The candle is burning with a blue flame." > candle +git add . +git commit -m "The beginning" + +[win] + +# Make a change to the candle. +test "$(git diff --name-only)" = "candle" || file -f .git/candle-changed && touch .git/candle-changed + +# Add the candle. +test "$(git diff --cached --name-only)" = "candle" || file -f .git/candle-added && touch .git/candle-added + +# Make a commit. +test "$(git diff --name-only HEAD HEAD^)" = "candle" diff --git a/levels/index/compare b/levels/index/compare new file mode 100644 index 0000000..85930aa --- /dev/null +++ b/levels/index/compare @@ -0,0 +1,45 @@ +title = Step by step +cards = checkout + +[description] + +Welcome to today's lesson! Today, we're going to learn how to make commits with precision! + +Have a look at these two timelines. They have exactly the same outcome. But one of them makes it much easier to figure out what happened. + +[setup] + +echo "A small, but heavy glass ball." > ball +echo "A thin book, that's standing upright." > book +echo "A candle, burning with a blue flame." > candle + +git add . +git commit -m "The beginning" + +git branch -M all-at-once + +echo "The ball is now touching the book." > ball +echo "The book has fallen over." > book +echo "The candle has been blown out." > candle + +git commit -am "The end" + +git checkout HEAD^ + +git checkout -b step-by-step + +echo "The ball is now touching the book." > ball +git commit -am "The ball rolls towards the book" + +echo "The book has fallen over." > book +git commit -am "The book falls over" + +echo "The candle has been blown out." > candle +git commit -am "The book blows out the candle" + +git checkout HEAD~3 + +[win] + +# This level doesn't have a goal yet. +false diff --git a/levels/index/new b/levels/index/new index f68434b..434be11 100644 --- a/levels/index/new +++ b/levels/index/new @@ -3,26 +3,20 @@ cards = add commit [description] -But Git allows to you capture changes with more precision! +So far, when we made a commit, we've always recorded the current status all objects, right? -To understand how to do that, you need to learn about [your teacher raises her voice dramatically] *the index*! +But Git allows you to pick which changes you want to put in a commit! -In the index, we can prepare what will be in the next commit. In this game, the index is represented by a blue aura! - -Initially, all files are untracked. If you have a file, and you want to have it in the next commit, use `git add`! - -Here, we don't use the fancy commit card, but a plain `git commit`! +To learn how that works, we need to learn about the "index"! In the index, we can prepare what will be in the next commit. In this game, the index is represented by a blue aura! [setup] -echo a > a -echo b > b -echo c > c +echo "The candle is burning with a blue flame." > candle [win] -# Add all three files to the index. -test "$(git ls-files | wc -l)" -eq 3 +# Add the candle. +test "$(git diff --cached --name-only)" = "candle" || file -f .git/candle-added && touch .git/candle-added -# And make a commit. -test "$(git ls-tree main | wc -l)" -eq 3 +# Make a commit. +test "$(git ls-tree --name-only HEAD)" = "candle" diff --git a/levels/index/sequence b/levels/index/sequence index b6011ad..cf794ab 100644 --- a/levels/index/sequence +++ b/levels/index/sequence @@ -1,6 +1,4 @@ -auto +compare new -add -reset -checkout -rm +change +steps diff --git a/levels/index/steps b/levels/index/steps new file mode 100644 index 0000000..39abf7e --- /dev/null +++ b/levels/index/steps @@ -0,0 +1,53 @@ +title = Adding changes step by step +cards = add commit + +[description] + +The index is really useful, because it allows us to be precise about which changes we want to include in each commit! + +[setup] + +echo "A small, but heavy glass ball. It is not touching the book." > ball +echo "A thin book, that's standing upright." > book +echo "A candle, burning with a blue flame." > candle + +git add . +git commit -m "The beginning" + +[win] + +# Make changes to all three objects! +test "$(git diff --name-only | wc -l)" -eq 3 || file -f .git/candle-changed && touch .git/candle-changed + +# Only add one of these changes! +test "$(git diff --cached --name-only | wc -l)" -eq 1 || file -f .git/candle-added && touch .git/candle-added + +# And make a commit. +COUNT=0 +for commit in $(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep 'commit$' | cut -f1 -d' '); do + if test "$(git diff --name-only $commit $commit^ | wc -l)" -eq 1; then + COUNT=$((COUNT+1)) + fi +done + +test "$COUNT" -ge 1 + +# Make a second commit that only records a single change. +COUNT=0 +for commit in $(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep 'commit$' | cut -f1 -d' '); do + if test "$(git diff --name-only $commit $commit^ | wc -l)" -eq 1; then + COUNT=$((COUNT+1)) + fi +done + +test "$COUNT" -ge 2 + +# And a third one. +COUNT=0 +for commit in $(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep 'commit$' | cut -f1 -d' '); do + if test "$(git diff --name-only $commit $commit^ | wc -l)" -eq 1; then + COUNT=$((COUNT+1)) + fi +done + +test "$COUNT" -ge 3 diff --git a/levels/intro/sequence b/levels/intro/sequence index a815954..b533017 100644 --- a/levels/intro/sequence +++ b/levels/intro/sequence @@ -2,3 +2,4 @@ risky copies git remote +who-are-you diff --git a/levels/sequence b/levels/sequence index fd32b24..1d334c1 100644 --- a/levels/sequence +++ b/levels/sequence @@ -3,6 +3,3 @@ files branches merge index -remotes -changing-the-past -bisect diff --git a/scenes/chapter.gd b/scenes/chapter.gd index f9ab853..9f2abc2 100644 --- a/scenes/chapter.gd +++ b/scenes/chapter.gd @@ -38,7 +38,7 @@ func load(path): level_names.erase(level) final_level_sequence.push_back(level) - final_level_sequence += level_names + #final_level_sequence += level_names for l in final_level_sequence: var level = Level.new()