Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions branch_previous/.gitmastery-exercise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"exercise_name": "branch-previous",
"tags": [
"git-branch"
],
"requires_git": true,
"requires_github": false,
"base_files": {},
"exercise_repo": {
"repo_type": "local",
"repo_name": "horror-story",
"repo_title": null,
"create_fork": null,
"init": true
}
}
33 changes: 33 additions & 0 deletions branch_previous/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# branch-previous

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.

## Task

1. Start a new branch named `visitor-line`, starting from the second commit (i.e., commit `Add second line`).
2. Add the line `I heard someone knocking at the door`. to the `story.txt`.
3. Commit the change. You may use any suitable commit message.
4. Start a new branch named `sleep-line`, starting from the same starting point as before.
5. Add the line `I fell asleep on the couch`. to the `story.txt`.
6. Commit the change. You may use any suitable commit message.

## Expected Revision Graph

```mermaid
gitGraph BT:
commit id: "Describe night"
commit id: "Describe location"
branch visitor-line
checkout main
branch sleep-line
checkout main
commit id: "Mention noise"
checkout visitor-line
commit id: "Mention knocking"
checkout sleep-line
commit id: "Mention sleeping"
```
Empty file added branch_previous/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions branch_previous/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from exercise_utils.file import create_or_update_file, append_to_file
from exercise_utils.git import add, commit

def setup(verbose: bool = False):
create_or_update_file(
"story.txt",
"""
It was a dark and stormy night.
"""
)
add(["story.txt"], verbose)
commit("Describe night", verbose)

append_to_file(
"story.txt",
"""
I was alone in my room.
"""
)
add(["story.txt"], verbose)
commit("Describe location", verbose)

append_to_file(
"story.txt",
"""
I heard a strange noise.
"""
)
add(["story.txt"], verbose)
commit("Mention noise", verbose)
Empty file.
52 changes: 52 additions & 0 deletions branch_previous/tests/specs/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
initialization:
steps:
- type: new-file
filename: story.txt
contents: "It was a dark and stormy night.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe night
id: start
- type: append-file
filename: story.txt
contents: "I was alone in my room.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe location
empty: false
id: describe_location_commit
- type: append-file
filename: story.txt
contents: "I heard a strange noise.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention noise
empty: false
- type: bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also implemented the support for start-point in repo-smith, so we can wait for it to get merged.

git-mastery/repo-smith#4

runs: git checkout -b visitor-line HEAD~1
- type: append-file
filename: story.txt
contents: "I heard someone knocking at the door.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention knocking
empty: false
- type: bash
runs: git checkout -b sleep-line HEAD~1
- type: append-file
filename: story.txt
contents: "I fell asleep on the couch.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention sleeping
empty: false
43 changes: 43 additions & 0 deletions branch_previous/tests/specs/sleep_missing_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
initialization:
steps:
- type: new-file
filename: story.txt
contents: "It was a dark and stormy night.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe night
empty: false
id: start
- type: append-file
filename: story.txt
contents: "I was alone in my room.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe location
empty: false
id: describe_location_commit
- type: append-file
filename: story.txt
contents: "I heard a strange noise.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention noise
empty: false
# Only create visitor-line branch, not sleep-line
- type: bash
runs: git checkout -b visitor-line HEAD~1
- type: append-file
filename: story.txt
contents: "I heard someone knocking at the door.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention knocking
empty: false
53 changes: 53 additions & 0 deletions branch_previous/tests/specs/sleep_wrong_content.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
initialization:
steps:
- type: new-file
filename: story.txt
contents: "It was a dark and stormy night.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe night
empty: false
id: start
- type: append-file
filename: story.txt
contents: "I was alone in my room.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe location
empty: false
id: describe_location_commit
- type: append-file
filename: story.txt
contents: "I heard a strange noise.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention noise
empty: false
- type: bash
runs: git checkout -b visitor-line HEAD~1
- type: append-file
filename: story.txt
contents: "I heard someone knocking at the door.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention knocking
empty: false
- type: bash
runs: git checkout -b sleep-line HEAD~1
- type: append-file
filename: story.txt
contents: "Wrong content here.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention sleeping
empty: false
42 changes: 42 additions & 0 deletions branch_previous/tests/specs/visitor_missing_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
initialization:
steps:
- type: new-file
filename: story.txt
contents: "It was a dark and stormy night.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe night
id: start
- type: append-file
filename: story.txt
contents: "I was alone in my room.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe location
empty: false
id: second_commit
- type: append-file
filename: story.txt
contents: "I heard a strange noise.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention noise
empty: false
# Only create sleep-line branch, not visitor-line
- type: bash
runs: git checkout -b sleep-line HEAD~1
- type: append-file
filename: story.txt
contents: "I fell asleep on the couch.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention sleeping
empty: false
46 changes: 46 additions & 0 deletions branch_previous/tests/specs/visitor_missing_commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
initialization:
steps:
- type: new-file
filename: story.txt
contents: "It was a dark and stormy night.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe night
empty: false
id: start
- type: append-file
filename: story.txt
contents: "I was alone in my room.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe location
empty: false
id: describe_location_commit
- type: append-file
filename: story.txt
contents: "I heard a strange noise.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention noise
empty: false
# visitor-line branch created but no commit made
- type: bash
runs: git checkout -b visitor-line HEAD~1
# sleep-line branch created with commit
- type: bash
runs: git checkout -b sleep-line
- type: append-file
filename: story.txt
contents: "I fell asleep on the couch.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention sleeping
empty: false
53 changes: 53 additions & 0 deletions branch_previous/tests/specs/visitor_wrong_content.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
initialization:
steps:
- type: new-file
filename: story.txt
contents: "It was a dark and stormy night.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe night
empty: false
id: start
- type: append-file
filename: story.txt
contents: "I was alone in my room.\n"
- type: add
files:
- story.txt
- type: commit
message: Describe location
empty: false
id: describe_location_commit
- type: append-file
filename: story.txt
contents: "I heard a strange noise.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention noise
empty: false
- type: bash
runs: git checkout -b visitor-line HEAD~1
- type: append-file
filename: story.txt
contents: "Wrong content here.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention knocking
empty: false
- type: bash
runs: git checkout -b sleep-line HEAD~1
- type: append-file
filename: story.txt
contents: "I fell asleep on my couch.\n"
- type: add
files:
- story.txt
- type: commit
message: Mention sleeping
empty: false
Loading