From be45b82e41d8452f0a3391b86d13ac59815a714d Mon Sep 17 00:00:00 2001 From: blinry Date: Wed, 13 Jan 2021 16:26:48 +0100 Subject: [PATCH] Polish branches chapter --- levels/branches/branch-create | 33 +++++---- levels/branches/branch-remove | 12 ++-- levels/branches/branches | 103 ---------------------------- levels/branches/checkout-commit | 39 +++++++++++ levels/branches/{branching => fork} | 6 +- levels/branches/grow | 45 ++++++++++++ levels/branches/reorder | 81 ++++++++++++++++++++++ levels/branches/sequence | 6 ++ levels/merge/conflict | 4 +- levels/merge/merge | 7 +- levels/merge/merge-abort | 9 +-- levels/merge/sequence | 3 + levels/sequence | 4 +- levels/unused/checkout-commit | 44 ------------ resources/cards.json | 9 ++- scenes/main.gd | 2 +- scenes/main.tscn | 5 +- scenes/repository.gd | 10 ++- 18 files changed, 231 insertions(+), 191 deletions(-) delete mode 100644 levels/branches/branches create mode 100644 levels/branches/checkout-commit rename levels/branches/{branching => fork} (89%) create mode 100644 levels/branches/grow create mode 100644 levels/branches/reorder create mode 100644 levels/branches/sequence create mode 100644 levels/merge/sequence delete mode 100644 levels/unused/checkout-commit diff --git a/levels/branches/branch-create b/levels/branches/branch-create index 22c2ae6..5c84791 100644 --- a/levels/branches/branch-create +++ b/levels/branches/branch-create @@ -1,35 +1,40 @@ -title = Party Time -cards = checkout commit-auto reset-hard branch +title = Creating branches +cards = checkout commit-auto branch branch-delete reset-hard [description] -You were invited to two parties but they will happen at the same time! At party 1 your favorite band is playing and the other one is your best friend's birthday party. +You were invited to two parties! At one of them, your favorite band is playing - and the other one is your best friend's birthday party. Where should you go? No worries - as a time travel agent in training, you can go to both parties! -Where should you go? No worries - you are a time travel agent in training. You can go to both parties! To quickly switch between both events, check out the last commits and -create branches with the `git branch [string]` command. Now you can easily switch between both branches by calling `git checkout [branch]`. +To make it easier to tell which timeline is which, you can create time portals! (We call these "branches".) [setup] -echo "-Birthday present. --Concert ticket." > backpack +echo "You wrap the birthday present, and grab your concert ticket." > you git add . -git commit -m "evening preparations" -echo "-Birthday present." > backpack +git commit -m "Evening preparations" +echo "You go to the birthday party!" >> you git add . -git commit -m "go to the birthday" +git commit -m "Go to the birthday" git checkout HEAD~1 -echo "-Concert ticket." > backpack +echo "You go to the concert!" > you git add . -git commit -m "go to the concert" +git commit -m "Go to the concert" git checkout HEAD~1 +git branch -D main + [win] -NUM_BRANCHES="$(git show-ref --heads | wc -l)" -test "$NUM_BRANCHES" -ge 3 +# Create a branch called 'birthday' that points to the birthday timeline. +git show birthday | grep 'to the birthday' + +# Create a branch called 'concert' that points to the concert timeline. +git show concert | grep 'to the concert' [congrats] +Now you can travel between those branches easily (using `git checkout`) - try it! + Your friend is happy that you made it to the birthday party and you also got your concert ticket signed. Yay! diff --git a/levels/branches/branch-remove b/levels/branches/branch-remove index 9d91108..2a9f806 100644 --- a/levels/branches/branch-remove +++ b/levels/branches/branch-remove @@ -1,4 +1,4 @@ -title = Choose your own adventure +title = Deleting branches cards = checkout commit-auto reset-hard branch-delete [description] @@ -7,8 +7,6 @@ Life is full of dangers, right? Even when walking to school, it seems like there This Monday is especially bad. You made it to school, but there's some timelines you definitely don't want to keep around. -Find the bad branches and delete them. Keep the one that seems okay. - [setup] echo You leave your house and start walking to school. > you @@ -33,14 +31,16 @@ echo Because you\'re kind of late, you start running. Someone throws a piano out git commit -am "Sounds nice" git checkout HEAD^ -b ice-cream -echo You\'re not in a hurry, and walk slowly. You even get some ice cream on your way. You arrive at school too late, and your teacher is angry. >> you +echo You\'re not in a hurry, and walk slowly. You even get some ice cream on your way. You arrive at school too late, your teacher is angry, and you are expelled. >> you git commit -am "Yum" -git checkout main +git branch -M main leap +git checkout leap^^ [win] -test "$(git branch | cut -c 3-)" = "$(echo -e ice-cream\\nmain)" +# Find the bad branches and delete them. Keep the best one. +test "$(git show-ref --heads | cut -f2 -d' ')" = "$(echo refs/heads/leap)" [congrats] diff --git a/levels/branches/branches b/levels/branches/branches deleted file mode 100644 index 82bdcaa..0000000 --- a/levels/branches/branches +++ /dev/null @@ -1,103 +0,0 @@ -title = Branching out -cards = checkout commit-auto merge reset-hard - -[description] - -You can use these little blue labels to give names to different timelines! This makes it easier to remember what happened where. - -One of your colleagues messed up here - can you help reordering the branches correctly using the "reset" card? - -When you do commits or merges while you're on a branch, the branch will grow with you. Try that while you eat that donut. - -Finally, merge all timelines together, in a way so that the "main" branch points to the result. That's base reality! - ---- -tipp1 ---- -tipp2 ---- -tipp3 - -[setup] - -echo "A friendly old lady. -Sells delicious baguettes." > mary - -echo "A rebellious teenager. -Sells good coffee." > larry - -echo "A snail. Literally a snail. -Sells donuts with an unspecified, slimy filling." > gary - -echo "You do not have a baguette. - -You do not have coffee. - -You do not have a donut." > you - -git add . -git commit -m "The Beginning" - -git checkout -b coffee -echo "You have a baguette. - -You do not have coffee. - -You do not have a donut." > you -git add . -git commit -m "You buy a baguette" - -echo "You ate a baguette. - -You do not have coffee. - -You do not have a donut." > you -git add . -git commit -m "You eat the baguette" - -git checkout -b baguette main -echo "You do not have a baguette. - -You have coffee. - -You do not have a donut." > you -git add . -git commit -m "You buy some coffee" - -echo "You do not have a baguette. - -You drank coffee. - -You do not have a donut." > you -git add . -git commit -m "You drink the coffee" - -git checkout -b donut main -echo "You do not have a baguette. - -You do not have coffee. - -You have a donut." > you -git add . -git commit -m "You buy a donut" - -git checkout --detach main - -[win] - -# Did you eat a baguette on the main branch? -git show main:you | grep "You ate.*baguette" - -# Did you drink a coffee on the main branch? -git show main:you | grep "You drank.*coffee" - -# Did you eat a donut on the main branch? -git show main:you | grep "You ate.*donut" - -[actions] - -test "$(git rev-parse HEAD^)" = "$(git rev-parse donut)" && hint "Ooops, your branch ref is still on the old commit." - -[congrats] - -Nice! It's often convenient to stay on branches most of the time! diff --git a/levels/branches/checkout-commit b/levels/branches/checkout-commit new file mode 100644 index 0000000..f878d5d --- /dev/null +++ b/levels/branches/checkout-commit @@ -0,0 +1,39 @@ +title = Moving through time +cards = checkout commit-auto + +[description] + +The yellow boxes are frozen points in time, we call them "commits"! You can travel between them using the "checkout" card! (Try it!) + +The grey panel below shows your current environment - click on an object to inspect or modify it! + +Can you find out what happened here? Then, while on the latest commit, fix the problem, and make a new commit! + +[setup] + +echo "This piggy bank belongs to the big sister. +It contains 10 coins." > piggy_bank +git add . +git commit -m "The beginning" + +echo "A young girl with brown, curly hair." > little_sister +git add . +git commit -m "Little sister comes in" + +echo "Has 10 coins." >> little_sister +echo "This piggy bank belongs to the big sister. +It is empty." > piggy_bank +git add . +git commit -m "Little sister does something" + +git checkout HEAD^^ +git branch -df main + +[win] + +# Restore sisterly peace. +{ git show HEAD:piggy_bank | grep "10 coins"; } && { git show HEAD:little_sister | grep -v "10 coins"; } && { git rev-parse HEAD^^^; } + +[congrats] + +Wonderful! Now that you're getting familiar with the time machine, let's look at some more complicated situations... diff --git a/levels/branches/branching b/levels/branches/fork similarity index 89% rename from levels/branches/branching rename to levels/branches/fork index 114decd..2ca5180 100644 --- a/levels/branches/branching +++ b/levels/branches/fork @@ -1,4 +1,4 @@ -title = Parallelism +title = Make parallel commits cards = checkout commit-auto [description] @@ -38,10 +38,10 @@ git branch -d main [win] -# Is the child still there? +# Make sure that the child is happy. git ls-tree --name-only -r HEAD | grep child -# Is the lion not hungry? +# Make sure that the lion gets something to eat. git show HEAD:cage/lion | grep -v "very hungry" [congrats] diff --git a/levels/branches/grow b/levels/branches/grow new file mode 100644 index 0000000..f4079d7 --- /dev/null +++ b/levels/branches/grow @@ -0,0 +1,45 @@ +title = Branches grow with you! +cards = checkout commit-auto branch branch-delete reset-hard + +[description] + +Note that there are two options to "travel to the end of a timeline": + +First, you can directly travel to the commit, like we've done it before. + +And second, you can travel to the branch label. In this case, when you make a new commit, the branch will grow with you, and still point at the end of the timeline, which is usually what we want! + +Let's try both of these! + +[setup] + +echo "You wrap the birthday present, and grab your concert ticket." > you +git add . +git commit -m "Evening preparations" +echo "You go to the birthday party!" >> you +git add . +git commit -m "Go to the birthday" +git branch birthday + +git checkout HEAD~1 +echo "You go to the concert!" > you +git add . +git commit -m "Go to the concert" +git branch concert + +git checkout HEAD~1 + +git branch -D main + +[win] + +# Travel directly to the last commit of the birthday timeline, make a change to 'you', and make a commit +for commit in $(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep 'commit$' | cut -f1 -d' '); do + if test $(git rev-parse $commit^) = $(git rev-parse birthday); then + return 0 + fi +done +return 1 + +# Travel to the 'concert' branch, make a change to 'you', and a commit. +git show concert^ | grep "Go to the concert" diff --git a/levels/branches/reorder b/levels/branches/reorder new file mode 100644 index 0000000..82e35cd --- /dev/null +++ b/levels/branches/reorder @@ -0,0 +1,81 @@ +title = Moving branches around +cards = checkout commit-auto merge reset-hard + +[description] + +One of your colleagues messed up here, and put the branches in the wrong timelines! + +You could delete and re-create these branches - but you can also directly move them to different commits, using `git reset --hard`. + +The donut branch is in the right place, but the timeline is still incomplete. + +[setup] + +echo "You do not have a baguette. + +You do not have coffee. + +You do not have a donut." > you + +git add . +git commit -m "The Beginning" + +git checkout -b coffee +echo "You have a baguette. + +You do not have coffee. + +You do not have a donut." > you +git add . +git commit -m "You buy a baguette" + +echo "You ate a baguette. + +You do not have coffee. + +You do not have a donut." > you +git add . +git commit -m "You eat the baguette" + +git checkout -b baguette main +echo "You do not have a baguette. + +You have coffee. + +You do not have a donut." > you +git add . +git commit -m "You buy some coffee" + +echo "You do not have a baguette. + +You drank coffee. + +You do not have a donut." > you +git add . +git commit -m "You drink the coffee" + +git checkout -b donut main +echo "You do not have a baguette. + +You do not have coffee. + +You have a donut." > you +git add . +git commit -m "You buy a donut" + +git checkout --detach main + +[win] + +# Did you eat a baguette on the baguette branch? +git show baguette:you | grep "You ate.*baguette" + +# Did you drink a coffee on the coffee branch? +git show coffee:you | grep "You drank.*coffee" + +# Did you eat a donut on the donut branch? +git show donut:you | grep "You ate.*donut" + +[actions] + +test "$(git rev-parse HEAD^)" = "$(git rev-parse donut)" && hint "Remember to checkout the blue branch tag when you want it to grow with the timeline." diff --git a/levels/branches/sequence b/levels/branches/sequence new file mode 100644 index 0000000..2619ea0 --- /dev/null +++ b/levels/branches/sequence @@ -0,0 +1,6 @@ +checkout-commit +fork +branch-create +grow +branch-remove +reorder diff --git a/levels/merge/conflict b/levels/merge/conflict index 1db3fa5..1a8b02b 100644 --- a/levels/merge/conflict +++ b/levels/merge/conflict @@ -9,7 +9,7 @@ For example, in this case, one of our clients wants these timelines merged, but Try to merge them together! You'll notice that there will be a conflict! The time machine will leave it up to you how to proceed: you can edit the problematic item, it will show you the conflicting sections. You can keep either of the two versions - or create a combination of them! Remove the >>>, <<<, and === markers, and make a new commit to finalize the merge! -Again, let your finalized timeline be the "main" one. +Let your finalized timeline be the "main" one. [setup] @@ -39,7 +39,7 @@ git checkout main [win] -# main has a parent, and the grandparent of both its first and child parents are the same commit: +# Make a breakfast compromise in the 'main' branch. git rev-parse main^ && test "$(git rev-parse main^1^^)" = "$(git rev-parse main^2^^)" [congrats] diff --git a/levels/merge/merge b/levels/merge/merge index 5b7b014..c1de34a 100644 --- a/levels/merge/merge +++ b/levels/merge/merge @@ -5,10 +5,6 @@ cards = checkout commit-auto merge Here's a trick so that you can sleep a bit longer: just do all your morning activities in parallel universes, and then at the end, merge them together! -Here, you see three parallel timelines - can you build a situation where you consumed a baguette, a coffee, *and* a donut? - -The "merge" card will help you - try it! - [setup] echo "A friendly old lady. @@ -79,11 +75,12 @@ You ate a donut." > you git add . git commit -m "You eat the donut" -git checkout HEAD~2 +git checkout --detach git branch -D main [win] +# Build a situation where you consumed a baguette, a coffee, *and* a donut. { git show HEAD:you | grep "You ate.*baguette"; } && { git show HEAD:you | grep "You drank.*coffee"; } && { git show HEAD:you | grep "You ate.*donut"; } [congrats] diff --git a/levels/merge/merge-abort b/levels/merge/merge-abort index 0032582..ce7190b 100644 --- a/levels/merge/merge-abort +++ b/levels/merge/merge-abort @@ -1,9 +1,10 @@ -title = Merging timelines -cards = checkout commit-auto merge +title = Abort a merge +cards = checkout commit-auto merge merge-abort [description] -Sometimes you want to merge two commits, nut a merge conflict occurs that you currently don't want to resolve. +Sometimes you want to merge two commits, but a merge conflict occurs that you currently don't want to resolve. + In these situations you can abort the merge to merge later. Use git merge --abort when you are in a merge process. @@ -46,7 +47,7 @@ fi test -f .git/secretfile # You aborted to merge? -test -f .git/secretfile && ! test -f .git/MERGE_HEAD +test -f .git/secretfile && ! test -f .git/MERGE_HEAD && ! git rev-parse HEAD^^ [congrats] diff --git a/levels/merge/sequence b/levels/merge/sequence new file mode 100644 index 0000000..cd94a4d --- /dev/null +++ b/levels/merge/sequence @@ -0,0 +1,3 @@ +merge +conflict +merge-abort diff --git a/levels/sequence b/levels/sequence index c569414..0138870 100644 --- a/levels/sequence +++ b/levels/sequence @@ -1,10 +1,10 @@ intro files -index branches merge -tags remotes +index +tags changing-the-past shit-happens stash diff --git a/levels/unused/checkout-commit b/levels/unused/checkout-commit deleted file mode 100644 index 2adab40..0000000 --- a/levels/unused/checkout-commit +++ /dev/null @@ -1,44 +0,0 @@ -title = Moving through time -cards = checkout commit-auto - -[description] - -The yellow boxes are frozen points in time, we call them "commits"! You can travel between them using the "checkout" card! (Try it!) - -The grey panel below shows your current environment - click on an object to inspect or modify it! - -Can you find out what happened here? Then, come back to the latest commit, and fix the problem, using the "commit" card! - -[setup] - -mkdir room1 room2 -echo "A young girl with brown, curly hair." > room1/little_sister -echo "This piggy bank belongs to the big sister. -It contains 10 coins." > room2/piggy_bank -git add . -git commit -m "The beginning" - -mv room1/little_sister room2 -git add . -git commit -m "Little sister walks over" - -echo "Has 10 coins." >> room2/little_sister -echo "This piggy bank belongs to the big sister. -It is empty." > room2/piggy_bank -git add . -git commit -m "Little sister does something" - -mv room2/little_sister room1 -git add . -git commit -m "Little sister walks back" - -git checkout --detach -git branch -d main - -[win] - -{ git show HEAD:room2/piggy_bank | grep "10 coins"; } && { git show HEAD:room1/little_sister | grep -v "10 coins"; } && { git rev-parse HEAD^; } - -[congrats] - -Wonderful! Now that you're getting familiar with the time machine, let's look at some more complicated situations... diff --git a/resources/cards.json b/resources/cards.json index ff03fa5..54294f6 100644 --- a/resources/cards.json +++ b/resources/cards.json @@ -46,9 +46,14 @@ }, { "id": "merge", - "command": "git merge [commit]", + "command": "git merge [commit, ref]", "description": "Merge the specified timeline into yours. If necessary, will create a merge commit." }, + { + "id": "merge-abort", + "command": "git merge --abort", + "description": "Abort the current merge attempt, and reconstruct the previous state." + }, { "id": "rebase", "command": "git rebase [commit]", @@ -137,7 +142,7 @@ { "id": "branch", "command": "git branch [string]", - "description": "Create a new branch." + "description": "Create a new branch at your current location." }, { "id": "branch-delete", diff --git a/scenes/main.gd b/scenes/main.gd index 98b179a..0bc4c8c 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -102,7 +102,7 @@ func load_level(level_id): terminal.clear() terminal.find_node("TextEditor").close() - #update_repos() + update_repos() # Unmute the audio after a while, so that player can hear pop sounds for # nodes they create. diff --git a/scenes/main.tscn b/scenes/main.tscn index 39bd18b..0203746 100644 --- a/scenes/main.tscn +++ b/scenes/main.tscn @@ -188,7 +188,7 @@ __meta__ = { [node name="Text" type="Control" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel"] margin_top = 65.0 margin_right = 633.0 -margin_bottom = 264.0 +margin_bottom = 464.0 size_flags_vertical = 3 [node name="LevelDescription" type="RichTextLabel" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel/Text"] @@ -215,10 +215,11 @@ __meta__ = { } [node name="Goals" type="VBoxContainer" parent="Rows/Columns/RightSide/LevelInfo/LevelPanel"] -margin_top = 269.0 +margin_top = 469.0 margin_right = 633.0 margin_bottom = 469.0 size_flags_vertical = 3 +size_flags_stretch_ratio = 0.0 [node name="FileBrowser" parent="Rows/Columns/RightSide" instance=ExtResource( 5 )] anchor_right = 0.0 diff --git a/scenes/repository.gd b/scenes/repository.gd index 29a8cd1..28aaaa1 100644 --- a/scenes/repository.gd +++ b/scenes/repository.gd @@ -17,6 +17,7 @@ var node = preload("res://scenes/node.tscn") var shell = Shell.new() var objects = {} var mouse_inside = false +var has_been_layouted = false # Used for caching. var all_objects_cache @@ -33,8 +34,8 @@ func _ready(): set_editable_path(editable_path) set_path(path) - update_everything() - update_node_positions() + #update_everything() + #update_node_positions() func _process(_delta): nodes.rect_pivot_offset = nodes.rect_size / 2 @@ -60,7 +61,10 @@ func update_everything(): else: for o in objects: objects[o].queue_free() - objects = {} + objects = {} + if not has_been_layouted: + update_node_positions() + has_been_layouted = true func set_path(new_path): path = new_path