Skip to content

Commit 58ffe26

Browse files
committed
Clean up code
1 parent aa28ab8 commit 58ffe26

14 files changed

+241
-183
lines changed

branch_previous/README.md

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
# branch-previous
22

3-
You are writing the outline for a story, in `story.txt`. You have written the first few steps of the storyline. You are not very happy with the way the story is progressing, and wish to explore a few alternative storylines starting from a previous step.
3+
You are writing the outline for a story, in `story.txt`.
4+
5+
You have written the first few steps of the storyline.
6+
7+
You are not very happy with the way the story is progressing, and wish to explore a few alternative storylines starting from a previous step.
48

59
## Task
610

7-
1. Start a new branch named `visitor-line`, starting from the second commit (i.e., commit with message "Describe location").
8-
2. Add the line `I heard someone knocking at the door.` to the `story.txt`.
11+
1. Start a new branch named `visitor-line`, starting from the second commit (i.e., commit `Add second line`).
12+
2. Add the line `I heard someone knocking at the door`. to the `story.txt`.
913
3. Commit the change. You may use any suitable commit message.
1014
4. Start a new branch named `sleep-line`, starting from the same starting point as before.
11-
5. Add the line `I fell asleep on the couch.` to the `story.txt`.
15+
5. Add the line `I fell asleep on the couch`. to the `story.txt`.
1216
6. Commit the change. You may use any suitable commit message.
1317

14-
## Hints
15-
16-
<details>
17-
<summary>How do I create a branch from a specific commit?</summary>
18-
19-
You can create a branch from a specific commit using:
20-
```bash
21-
git branch <branch-name> <commit-hash>
22-
```
23-
24-
Or you can checkout directly to a new branch from a specific commit:
25-
```bash
26-
git checkout -b <branch-name> <commit-hash>
27-
```
28-
</details>
29-
30-
<details>
31-
<summary>How do I find the commit hash?</summary>
18+
## Expected Revision Graph
3219

33-
Use `git log` to view the commit history and find the hash of the commit with message "Describe location".
34-
</details>
20+
![Expected Revision Graph](horror-story/expected-tree.png)

branch_previous/download.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
from exercise_utils.file import create_or_update_file, append_to_file
22
from exercise_utils.git import add, commit
3-
from exercise_utils.gitmastery import create_start_tag
43

5-
__resources__ = {"README.md": "README.md"}
4+
__resources__ = {"expected-tree.png": "expected-tree.png"}
65

76

87
def setup(verbose: bool = False):
9-
# First commit: Describe night
108
create_or_update_file(
11-
"story.txt",
12-
"It was a dark and stormy night.\n"
9+
"story.txt",
10+
"""
11+
It was a dark and stormy night.
12+
"""
1313
)
1414
add(["story.txt"], verbose)
1515
commit("Describe night", verbose)
1616

17-
# Second commit: Describe location
1817
append_to_file(
1918
"story.txt",
20-
"It was a dark and stormy night.\nI was alone in my room.\n"
19+
"""
20+
I was alone in my room.
21+
"""
2122
)
2223
add(["story.txt"], verbose)
2324
commit("Describe location", verbose)
2425

25-
# Third commit: Mention noise
26-
create_or_update_file(
26+
append_to_file(
2727
"story.txt",
28-
"It was a dark and stormy night.\nI was alone in my room.\nI heard a strange noise.\n",
28+
"""
29+
I heard a strange noise.
30+
"""
2931
)
3032
add(["story.txt"], verbose)
3133
commit("Mention noise", verbose)
32-
56 KB
Loading

branch_previous/tests/specs/base.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ initialization:
1616
- type: commit
1717
message: Describe location
1818
empty: false
19-
id: second_commit
19+
id: describe_location_commit
2020
- type: bash
2121
runs: echo "I heard a strange noise." >> story.txt
2222
- type: add
@@ -27,23 +27,23 @@ initialization:
2727
empty: false
2828
- type: bash
2929
runs: |
30-
SECOND_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
31-
git checkout -b visitor-line $SECOND_COMMIT
30+
DESCRIBE_LOCATION_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
31+
git checkout -b visitor-line $DESCRIBE_LOCATION_COMMIT
3232
echo "I heard someone knocking at the door." >> story.txt
3333
- type: add
3434
files:
3535
- story.txt
3636
- type: commit
37-
message: Add visitor line
37+
message: Mention knocking
3838
empty: false
3939
- type: bash
4040
runs: |
41-
SECOND_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
42-
git checkout -b sleep-line $SECOND_COMMIT
41+
DESCRIBE_LOCATION_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
42+
git checkout -b sleep-line $DESCRIBE_LOCATION_COMMIT
4343
echo "I fell asleep on the couch." >> story.txt
4444
- type: add
4545
files:
4646
- story.txt
4747
- type: commit
48-
message: Add sleep line
48+
message: Mention sleeping
4949
empty: false

branch_previous/tests/specs/sleep_branch_missing.yml renamed to branch_previous/tests/specs/sleep_missing_branch.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ initialization:
1717
- type: commit
1818
message: Describe location
1919
empty: false
20-
id: second_commit
20+
id: describe_location_commit
2121
- type: bash
2222
runs: echo "I heard a strange noise." >> story.txt
2323
- type: add
@@ -29,12 +29,12 @@ initialization:
2929
# Only create visitor-line branch, not sleep-line
3030
- type: bash
3131
runs: |
32-
SECOND_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
33-
git checkout -b visitor-line $SECOND_COMMIT
32+
DESCRIBE_LOCATION_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
33+
git checkout -b visitor-line $DESCRIBE_LOCATION_COMMIT
3434
echo "I heard someone knocking at the door." >> story.txt
3535
- type: add
3636
files:
3737
- story.txt
3838
- type: commit
39-
message: Add visitor line
39+
message: Mention knocking
4040
empty: false
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
initialization:
2+
steps:
3+
- type: bash
4+
runs: echo "It was a dark and stormy night." > story.txt
5+
- type: add
6+
files:
7+
- story.txt
8+
- type: commit
9+
message: Describe night
10+
empty: false
11+
id: start
12+
- type: bash
13+
runs: echo "I was alone in my room." >> story.txt
14+
- type: add
15+
files:
16+
- story.txt
17+
- type: commit
18+
message: Describe location
19+
empty: false
20+
id: describe_location_commit
21+
- type: bash
22+
runs: echo "I heard a strange noise." >> story.txt
23+
- type: add
24+
files:
25+
- story.txt
26+
- type: commit
27+
message: Mention noise
28+
empty: false
29+
- type: bash
30+
runs: |
31+
DESCRIBE_LOCATION_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
32+
git checkout -b visitor-line $DESCRIBE_LOCATION_COMMIT
33+
echo "I heard someone knocking at the door." >> story.txt
34+
- type: add
35+
files:
36+
- story.txt
37+
- type: commit
38+
message: Mention knocking
39+
empty: false
40+
- type: bash
41+
runs: |
42+
DESCRIBE_LOCATION_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
43+
git checkout -b sleep-line $DESCRIBE_LOCATION_COMMIT
44+
echo "Wrong content here." >> story.txt
45+
- type: add
46+
files:
47+
- story.txt
48+
- type: commit
49+
message: Mention sleeping
50+
empty: false

branch_previous/tests/specs/visitor_branch_missing.yml

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
initialization:
2+
steps:
3+
- type: bash
4+
runs: echo "It was a dark and stormy night." > story.txt
5+
- type: add
6+
files:
7+
- story.txt
8+
- type: commit
9+
message: Describe night
10+
id: start
11+
- type: bash
12+
runs: |
13+
echo "I was alone in my room." >> story.txt
14+
- type: commit
15+
message: Describe location
16+
empty: false
17+
id: second_commit
18+
- type: bash
19+
runs: |
20+
echo "I heard a strange noise." >> story.txt
21+
- type: commit
22+
message: Mention noise
23+
empty: false
24+
# Only create sleep-line branch, not visitor-line
25+
- type: bash
26+
runs: |
27+
DESCRIBE_LOCATION_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
28+
git checkout -b sleep-line $DESCRIBE_LOCATION_COMMIT
29+
echo "I fell asleep on the couch." >> story.txt
30+
- type: commit
31+
message: Mention sleeping
32+
empty: false

branch_previous/tests/specs/visitor_commit_missing.yml renamed to branch_previous/tests/specs/visitor_missing_commit.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ initialization:
1717
- type: commit
1818
message: Describe location
1919
empty: false
20-
id: second_commit
20+
id: describe_location_commit
2121
- type: bash
2222
runs: echo "I heard a strange noise." >> story.txt
2323
- type: add
@@ -29,17 +29,17 @@ initialization:
2929
# visitor-line branch created but no commit made
3030
- type: bash
3131
runs: |
32-
SECOND_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
33-
git branch visitor-line $SECOND_COMMIT
32+
DESCRIBE_LOCATION_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
33+
git checkout -b visitor-line $DESCRIBE_LOCATION_COMMIT
3434
# sleep-line branch created with commit
3535
- type: bash
3636
runs: |
37-
SECOND_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
38-
git checkout -b sleep-line $SECOND_COMMIT
37+
DESCRIBE_LOCATION_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
38+
git checkout -b sleep-line $DESCRIBE_LOCATION_COMMIT
3939
echo "I fell asleep on the couch." >> story.txt
4040
- type: add
4141
files:
4242
- story.txt
4343
- type: commit
44-
message: Add sleep line
44+
message: Mention sleeping
4545
empty: false

branch_previous/tests/specs/visitor_wrong_content.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ initialization:
1717
- type: commit
1818
message: Describe location
1919
empty: false
20-
id: second_commit
20+
id: describe_location_commit
2121
- type: bash
2222
runs: echo "I heard a strange noise." >> story.txt
2323
- type: add
@@ -28,23 +28,23 @@ initialization:
2828
empty: false
2929
- type: bash
3030
runs: |
31-
SECOND_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
32-
git checkout -b visitor-line $SECOND_COMMIT
31+
DESCRIBE_LOCATION_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
32+
git checkout -b visitor-line $DESCRIBE_LOCATION_COMMIT
3333
echo "Wrong content here." >> story.txt
3434
- type: add
3535
files:
3636
- story.txt
3737
- type: commit
38-
message: Add visitor line
38+
message: Mention knocking
3939
empty: false
4040
- type: bash
4141
runs: |
42-
SECOND_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
43-
git checkout -b sleep-line $SECOND_COMMIT
42+
DESCRIBE_LOCATION_COMMIT=$(git log --all --grep="Describe location" --format=%H -n 1)
43+
git checkout -b sleep-line $DESCRIBE_LOCATION_COMMIT
4444
echo "I fell asleep on my couch." >> story.txt
4545
- type: add
4646
files:
4747
- story.txt
4848
- type: commit
49-
message: Add sleep line
49+
message: Mention sleeping
5050
empty: false

0 commit comments

Comments
 (0)