Work on the intro and the index chapter

This commit is contained in:
blinry 2021-01-11 19:16:35 +01:00
parent 4910e4d566
commit 8d333ce56a
31 changed files with 327 additions and 185 deletions

View file

@ -1,23 +1,24 @@
title = Interior design
cards = checkout commit-auto reset-hard file-new file-delete
cards = file-new file-delete
[description]
Our client want some new furniture! You'll discover that they have a very special taste - please add some more furniture that matches this style and make a commit!
Today has been stressful and exhausting. Let's make sure you know how to interact with your current environment, before doing fancy Git stuff.
You're moving into your student apartment, but soon discover that some furniture is missing!
[setup]
echo A yellow cupboard with lots of drawers. > cupboard
echo A really big yellow shelf. > shelf
git add .
git commit -m "A cupboard and a shelf"
echo A small yellow shelf. > shelf
[win]
NUM_FILES="$(git ls-tree --name-only -r HEAD | wc -l)"
YELLOW_FILES="$(git grep -l yellow HEAD | wc -l)"
test "$NUM_FILES" -ge 5 && test "$YELLOW_FILES" = "$NUM_FILES"
# Add two more pieces of furniture (in matching colors).
NUM_FILES="$(ls | wc -l)"
YELLOW_FILES="$(grep -l yellow * | wc -l)"
test "$NUM_FILES" -ge 4 && test "$YELLOW_FILES" = "$NUM_FILES"
[congrats]
Thanks! Our clients says that they really like what you picked!
Don't you immediately feel more at home?

View file

@ -1,10 +1,11 @@
title = Unexpected Visitors
cards = checkout commit-auto reset-hard file-new file-delete
cards = file-new file-delete
[description]
*ring ring* Oh no! You wanted to meet with your parents in your student apartment and your alarm did not go off in time to clean your room!
"Coming!" you yell while you jump out of bed. Now quick! Remove all litter and trash you can find by using `rm [file]` and commit your changes.
"Coming!" you yell while you jump out of bed. Now quick!
[setup]
@ -12,14 +13,17 @@ echo Very smelly socks. > socks
echo A tiny couch table. > table
echo An empty energy drink can. > can
echo An empty bag of chips. > bag_of_chips
git add .
git commit -m "weekend"
[win]
NUM_FILES="$(git ls-tree --name-only -r HEAD | wc -l)"
test "$NUM_FILES" -eq 1 && test "$(git ls-tree --name-only -r HEAD)" = "table"
# Remove all litter and trash.
! ls | grep bag_of_chips &&
! ls | grep can &&
! ls | grep socks
# But make sure to keep important things!
ls | grep table
[congrats]
Your parents are happy to see you (and of course your neat and tidy apartment)!
Your parents are happy to see you (and, of course, your neat and tidy apartment)!

View file

@ -1,28 +1,27 @@
title = No sleep required
cards = checkout commit-auto reset-hard file-new file-delete file-rename
cards = file-new file-delete file-rename
[description]
Our client just let us know they don't need sleep! Huh.
Actually, you decide that you don't need any sleep.
Because of that, they won't require a bed, and have asked you to build some other piece of furniture from the wood.
Because of that, you won't require a bed, and can build some other piece of furniture from the wood!
Can you rename the object into something else, give it a new description, and make a commit from that?
[setup]
echo A yellow cupboard with lots of drawers. > cupboard
echo A really big yellow shelf. > shelf
echo A comfortable, yellow bed with yellow cushions. > bed
git add .
git commit -m "Initial furniture"
[win]
NUM_FILES="$(git ls-tree --name-only -r HEAD | wc -l)"
NUM_BEDS="$(git ls-tree --name-only -r HEAD | grep '^bed$' | wc -l)"
test "$NUM_BEDS" = 0 && test "$NUM_FILES" -ge 3
# Rename the bed into something else, and give it a new description!
NUM_FILES="$(ls | wc -l)"
! test -f bed && test "$NUM_FILES" -ge 3 && ! grep -r "yellow bed" .
[congrats]
Neat! It even still looks a bit comfortable!
You head out, eager for your first lesson at time travel school!

3
levels/files/sequence Normal file
View file

@ -0,0 +1,3 @@
files-add
files-delete
files-move

View file

@ -1,10 +1,12 @@
title = Updating files in the index
cards = add
cards = add commit checkout
[description]
So you start working, and make changes to your files! Git lets you choose which of these changes you want to put in the next commit. This is like updating the index version of that file to the new version.
This allows you to have smaller commits, that describe better what you changed!
The command for this is the same - `git add`!
[setup]
@ -17,5 +19,20 @@ git commit -m "Initial commit"
[win]
# Make changes to all three files, and add all of them to the index.
test "$(git diff --cached --name-only | wc -l)" -eq 3
# Make changes to all files!
test "$(cat a)" != "a" &&
test "$(cat b)" != "b" &&
test "$(cat c)" != "c"
# Add only the changes of a and c, and make a commit! Finally, make a commit which captures the changes in b!
test "$(git show main:a)" != "a" &&
test "$(git show main:b)" != "b" &&
test "$(git show main:c)" != "c" &&
test "$(git show main^:a)" != "a" &&
test "$(git show main^:b)" == "b" &&
test "$(git show main^:c)" != "c"
[congrats]
Well done! Try tavelling between the commits using `git checkout`, so you can look at their contents again!

29
levels/index/auto Normal file
View file

@ -0,0 +1,29 @@
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 '

View file

@ -1,10 +1,12 @@
title = Checking out files from the index
cards = add reset checkout
cards = add reset checkout-file commit
[description]
So you've made changes to your files, but you decide that you don't want to keep them! You can use `git checkout` for that!
What happens if you have already update the index, like in file c? You have to reset the index first!
[setup]
echo a > a
@ -14,6 +16,8 @@ git add .
git commit -m "Initial commit"
echo x > a
echo x > b
echo x > c
git add c
[win]

View file

@ -1,5 +1,5 @@
title = Rename a file in the next commit
cards = add reset checkout mv commit
cards = add reset checkout-file mv commit
[description]

View file

@ -1,11 +1,17 @@
title = Add new files to the index
cards = add
cards = add commit
[description]
In the index, we can prepare what will be in the next commit.
But Git allows to you capture changes with more precision!
Initially, the index will be empty, and all files are untracked. If you have a file, and you want to have it in the next commit, use `git add`!
To understand how to do that, you need to learn about [your teacher raises her voice dramatically] *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!
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`!
[setup]
@ -16,4 +22,7 @@ echo c > c
[win]
# Add all three files to the index.
test "$(git diff --cached --name-only | wc -l)" -eq 3
test "$(git ls-files | wc -l)" -eq 3
# And make a commit.
test "$(git ls-tree main | wc -l)" -eq 3

View file

@ -1,9 +1,11 @@
title = Resetting files in the index
cards = add reset
cards = add reset commit
[description]
If you already have changes in the index, but want to reset them, you can use `git reset`!
See the dark shadow behind the icons? That's the version of the commit you're at!
If you already have updated the index to a changed file, but want to reset it, you can use `git reset`!
[setup]
@ -14,9 +16,17 @@ git add .
git commit -m "Initial commit"
echo x > a
echo x > b
echo x > c
git add .
[win]
# Reset all changes in files in the index!
test "$(git diff --cached --name-only | wc -l)" -eq 0
# Reset the changes in a and c
test "$(git show :a)" == "a" &&
test "$(git show :b)" != "a" &&
test "$(git show :c)" == "c"
# And make a commit!
test "$(git show main:a)" == "a" &&
test "$(git show main:b)" != "b" &&
test "$(git show main:c)" == "c"

View file

@ -1,5 +1,5 @@
title = Delete a file in the next commit
cards = add reset checkout rm commit
cards = add reset checkout-file rm file-delete commit
[description]

View file

@ -1,8 +1,7 @@
auto
new
add
reset
checkout
commit
commit-a
rm
mv

41
levels/intro/copies Normal file
View file

@ -0,0 +1,41 @@
title = Making copies
cards =
[description]
One month later, you're working on an essay about cats.
You've started making backup copies of your essay regularly - you can look at them by clicking on them!
Your current version, essay4.txt, needs one more line
[congrats]
Okay, this works. But you're a bit worried that two weeks from now, you'll have hundreds of copies of your essay, and it will be hard to keep track of all of them.
And especially when working with other people, sending copies back and forth doesn't seem ideal. Let's look at another way to do this!
[setup]
rm -rf .git
echo "~ Why cats are the best pets ~
(I still need to write this.)" >> essay1.txt
echo "~ Why cats are the best pets ~
- They live longer than goldfish." >> essay2.txt
echo "~ Why cats are the best pets ~
- They live longer than goldfish.
- Their little paws are super cute." >> essay3.txt
cp essay3.txt essay4.txt
[win]
# Add two more lines to essay4.txt!
test "$(cat essay4.txt | wc -l )" -ge 6

39
levels/intro/git Normal file
View file

@ -0,0 +1,39 @@
title = Enter the time machine
cards = init commit-auto checkout
[description]
Another month later, you're woking on an essay about tardigrades!
But this time, a friend has borrowed you a time machine!
It's called "Git", and it's very shiny.
[setup]
rm -rf .git
echo "~ Why tardigrades are cool ~
- They can survive in space.
- They are resistant to extreme heat and cold." > essay.txt
[win]
# Initialize the time machine!
test -d .git
# Make a snapshot of your essay (a "commit")
test -d .git && git rev-parse HEAD
# Add another line to the essay.
test "$(cat essay.txt | wc -l)" -ge 5
# And make a second commit!
git rev-parse HEAD^ && test "$(git show HEAD:essay.txt | wc -l)" -ge 5
[congrats]
Nice! You can now travel between those two snapshots using `git checkout` - try it, and look at the essay in each commit!
You can also make some additional commits. When you feel comfortable, click on "Next Level".

View file

@ -1,24 +0,0 @@
title = Welcome!
cards = init
[description]
Welcome, time agent! Good to see you - we could really use your help with fixing some temporal paradoxes!
Ready to initialize your time machine? Drag the `git init` card into the empty space above it!
[setup]
rm -rf .git
[win]
test -d .git
[congrats]
Oh hey, that's you! :)
The time machine can help you fix problems in the past! It allows you to collaborate with other time agents! It's really powerful, and it's really popular!
Let's get familiar with it! Click on "Next level", as soon as you're ready!

View file

@ -1,53 +0,0 @@
title = Why Git?
cards = file-copy
[description]
So you've been working on an essay about goldfish. You can look at the backup copies you made by clicking on them!
But look - something went wrong in the latest version of the file! Maybe it has been infected with a vowel-eating virus?
[congrats]
Good that you had that backup, huh?
But you're a bit worried that two weeks from now, you'll have hundreds of copies of your essay, and it will be hard to keep track of all of them.
And especially when working with other people, sending backup copies around doesn't seem ideal.
Let's look at another way to do this. :) Click "Next Level" as soon as you're ready!
[setup]
rm -rf .git
echo "~ Why goldfish are the best pets ~
(I still need to write this.)" >> essay1.txt
echo "~ Why goldfish are the best pets ~
- They don't make any noise.
- They are pretty. (I should probably put this higher in the list?)" >> essay2.txt
echo "~ Why goldfish are the best pets ~
- They are pretty.
- They don't pee on the carpet.
- They don't make any noise." >> essay3.txt
echo "~ Why gldfsh r th bst pts ~
- Thy r prtty.
- Thy dn't p n th crpt.
- Thy dn't mk ny ns." >> essay4.txt
[win]
# Make a new version (with the number 5) from the last version that's still okay
cat essay5.txt | grep carpet
# And add at least two more lines to it!
test "$(cat essay5.txt | wc -l )" -ge 7

View file

@ -1,26 +1,26 @@
title = Working together
cards = pull commit-auto push
cards = clone checkout commit-auto pull push
[description]
A friend has asked you to help with an essay about hobbies! She has already started to write a list, started tracking it in a Git repository. You can get a copy by using `git pull`!
A friend has asked you to help with an essay about hobbies! She has already started to write a list, and started tracking it with her own time machine!
[congrats]
"Thanks, these are some really nice hobbies! Hope we can do that together soon!"
You're still pretty confused by everything that's going on. The next day, you decide to enroll in time travel school!
[setup]
rm -rf .git
[setup friend]
echo "~ Best hobbies ~" > hobbies.txt
git add .
git commit -m "Initial version"
git push -u friend main
[setup friend]
git checkout main
echo "
- Collecting stamps
- Looking at clouds" >> hobbies.txt
@ -30,10 +30,16 @@ git commit -m "Added two hobbies"
[win]
# Help her by adding at least two more items to the list!
# Get a copy of her timeline using `git clone`!
test -d .git
# Add at least two more items to the list!
test "$(cat hobbies.txt |wc -l)" -ge 6
# Commit your result.
test "$(git show main:hobbies.txt |wc -l)" -ge 6
[win friend]
# When you're done, commit your result and use `git push` to send it to her copy of the repository!
# And use `git push` to send it to your friend!
test "$(git show main:hobbies.txt |wc -l)" -ge 6

44
levels/intro/risky Normal file
View file

@ -0,0 +1,44 @@
title = A normal day
cards =
[description]
You're working on an essay about goldfish! Your current version is already quite nice, but needs a bit more work.
[congrats]
Suddenly, your cat jumps on your keyboard, deletes what you've written, and runs away! Oh no. :( Just look at it now! All your hard work, destroyed!
You decide to be more careful in the future.
(Click "Next Level" as soon as you're ready!)
[setup]
rm -rf .git
echo "~ Why are the best pets ~
- They are pretty.
- They don't pee on the carpet.
- They don't make any noise." >> essay.txt
echo "Your cat is sitting next to you, watching you intensely.
It's small, black, and very cute!" > cat
[actions]
test "$(cat essay.txt | wc -l )" -ge 7 && echo "~ Why goldfish are the best pets ~
- asdijwrlj
- they
- are
- delicious
- adfkafkasdufyasfiudasd" > essay.txt && rm -f cat
[win]
# Add two more lines to essay.txt!
test "$(cat essay.txt | wc -l )" -ge 7

View file

@ -1,5 +1,4 @@
motivation
setup
checkout
restore
first-remote
risky
copies
git
remote

View file

@ -1,34 +0,0 @@
title = A better way
cards = init commit-auto
[description]
One month later, you're woking on an essay about tardigrades!
This time, a friend has recommended that you use the version control system Git to keep backups of your file.
Currently, your directory only contains your essay. To initialize a Git repository in your directory, use the `init` card!
Then, each time you want to make a backup, use the `commit` card!
That way, you've made a backup of the current version of the file.
[setup]
rm -rf .git
echo "~ Why tardigrades are cool ~
- They can survive in space.
- They are resistant to extreme heat and cold." > essay.txt
[win]
# Initialize a Git repository
test -d .git
# And make another commit
test -d .git && git rev-parse HEAD^
# Add at least two more lines.
test "$(git show HEAD:essay.txt | wc -l)" -ge 6

View file

@ -1,23 +1,35 @@
title = Nice to meet you!
cards = config-name config-email
title = Welcome to time travel school!
cards = config-name commit-auto checkout
[description]
Introduce yourself using
git config --global user.name Firstname
git config --global user.email "your@mail.com"
Your time travel teacher welcomes you: "Hello there! Wanna tell us your name?"
[setup]
git config --global user.name "You"
echo "~ Why do you want to learn how to use time machines? ~
[ ] To make sure that my cat doesn't eat my homework.
[ ] So I don't have to keep copies of all my essays.
[ ] To collaborate with other time travel students.
[ ] Other, please specify:" > form
[actions]
test "$(git config user.name)" != "You" && hint "Hey $(git config user.name), nice to meet you!"
test "$(git config user.name)" != "You" && hint "Hey $(git config user.name), welcome to time travel school!"
[win]
# Have a name configured.
# Introduce yourself.
test "$(git config user.name)" != "You"
# Have an email address configured.
test "$(git config user.email)" != "you@time.agency"
# Fill out the enrollment form, and commit it!
git show main:form | grep '\[x\]'
[congrats]
"We're glad to have you! See how the commit now includes your name?
Git can help you fix problems in the past! It allows you to collaborate with other students of time travel! It's really powerful, and it's really popular! I'll see you for your first lesson tomorrow!"

View file

@ -3,7 +3,7 @@ cards = add reset checkout commit
[description]
With that, we're ready to make our first commit! It will contain the version of the files which are currently in the index.
For practice, make a commit where all files contain an "x"!
[setup]

14
levels/unused/init Normal file
View file

@ -0,0 +1,14 @@
title = Welcome!
cards = init
[description]
[setup]
rm -rf .git
[win]
# Again, initialize your time machine!
test -d .git

23
levels/unused/who-are-you Normal file
View file

@ -0,0 +1,23 @@
title = Nice to meet you!
cards = config-name config-email
[description]
Introduce yourself using
git config --global user.name Firstname
git config --global user.email "your@mail.com"
[setup]
[actions]
test "$(git config user.name)" != "You" && hint "Hey $(git config user.name), nice to meet you!"
[win]
# Have a name configured.
test "$(git config user.name)" != "You"
# Have an email address configured.
test "$(git config user.email)" != "you@time.agency"

View file

@ -2,7 +2,7 @@
{
"id": "init",
"command": "git init",
"description": "Initialize the time machine!"
"description": "Drag this card into the empty space above to initialize the time machine!"
},
{
"id": "clone",
@ -12,7 +12,7 @@
{
"id": "config-name",
"command": "git config --global user.name [string]",
"description": "Set your name."
"description": "Set your name.\n\n(Will not change anything outside of this game.)"
},
{
"id": "config-email",
@ -57,12 +57,12 @@
{
"id": "pull",
"command": "git pull",
"description": "Get timelines from a colleague."
"description": "Get timelines from a friend."
},
{
"id": "push",
"command": "git push",
"description": "Give timelines to a colleague."
"description": "Give timelines to a friend."
},
{
"id": "rebase-interactive",
@ -157,12 +157,12 @@
{
"id": "file-delete",
"command": "rm [file]",
"description": "Delete a new file."
"description": "Delete a file."
},
{
"id": "file-rename",
"command": "mv [file] [string]",
"description": "Rename a new file."
"description": "Rename a file."
},
{
"id": "file-copy",

View file

@ -64,7 +64,7 @@ func load(path):
else:
repo = "yours"
var desc = "Goal"
var desc = "Complete the goal of this level"
for line in Array(config[k].split("\n")):
if line.length() > 0 and line[0] == "#":
desc = line.substr(1).strip_edges(true, true)