Skip to content
Merged
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
17 changes: 17 additions & 0 deletions branch_forward/.gitmastery-exercise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"exercise_name": "branch-forward",
"tags": [
"git-branch",
"git-merge"
],
"requires_git": true,
"requires_github": false,
"base_files": {},
"exercise_repo": {
"repo_type": "local",
"repo_name": "love-story",
"repo_title": null,
"create_fork": null,
"init": true
}
}
19 changes: 19 additions & 0 deletions branch_forward/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# branch-forward

You are writing the outline for a story. You now have two parallel storylines in two branches.

## Task

1. Review the `with-sally` and `with-ginny` branches.
2. Merge only the branch(es) that can be fast-forwarded into `main`.
3. Leave other branches (if any) unmerged.

## Hints

<details>

<summary>Hint 1</summary>

Ensure you have switched to the destination branch before initiating the merge.

</details>
Empty file added branch_forward/__init__.py
Empty file.
63 changes: 63 additions & 0 deletions branch_forward/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from exercise_utils.file import append_to_file, create_or_update_file
from exercise_utils.git import add, checkout, commit


def setup(verbose: bool = False):
create_or_update_file(
"story.txt",
"""
Harry was single.
""",
)
add(["story.txt"], verbose)
commit("Introduce Harry", verbose)

append_to_file(
"story.txt",
"""
Harry did not have a family.
""",
)
add(["story.txt"], verbose)
commit("Add about family", verbose)

checkout("with-ginny", True, verbose)
append_to_file(
"story.txt",
"""
Then he met Ginny.
""",
)
add(["story.txt"], verbose)
commit("Add about Ginny", verbose)

checkout("main", False, verbose)
create_or_update_file(
"cast.txt",
"""
Harry
""",
)
add(["cast.txt"], verbose)
commit("Add cast.txt", verbose)

checkout("with-sally", True, verbose)
append_to_file(
"story.txt",
"""
Then he met Sally
""",
)
add(["story.txt"], verbose)
commit("Mention Sally", verbose)

checkout("with-ginny", False, verbose)
append_to_file(
"story.txt",
"""
Ginny was single too
""",
)
add(["story.txt"], verbose)
commit("Mention Ginny is single", verbose)

Empty file.
43 changes: 43 additions & 0 deletions branch_forward/tests/specs/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
initialization:
steps:
- type: commit
empty: true
message: Introduce Harry
id: start
- type: commit
empty: true
message: Add about family

- type: branch
branch-name: with-ginny
- type: checkout
branch-name: with-ginny
- type: commit
empty: true
message: Add about Ginny

- type: checkout
branch-name: main
- type: commit
empty: true
message: Add cast.txt

- type: branch
branch-name: with-sally
- type: checkout
branch-name: with-sally
- type: commit
empty: true
message: Mention Sally

- type: checkout
branch-name: with-ginny
- type: commit
empty: true
message: Mention Ginny is single

- type: checkout
branch-name: main
- type: merge
branch-name: with-sally

44 changes: 44 additions & 0 deletions branch_forward/tests/specs/merge_with_sally_no_ff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
initialization:
steps:
- type: commit
empty: true
message: Introduce Harry
id: start
- type: commit
empty: true
message: Add about family

- type: branch
branch-name: with-ginny
- type: checkout
branch-name: with-ginny
- type: commit
empty: true
message: Add about Ginny

- type: checkout
branch-name: main
- type: commit
empty: true
message: Add cast.txt

- type: branch
branch-name: with-sally
- type: checkout
branch-name: with-sally
- type: commit
empty: true
message: Mention Sally

- type: checkout
branch-name: with-ginny
- type: commit
empty: true
message: Mention Ginny is single

- type: checkout
branch-name: main
- type: merge
branch-name: with-sally
no-ff: true

41 changes: 41 additions & 0 deletions branch_forward/tests/specs/no_merges.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
initialization:
steps:
- type: commit
empty: true
message: Introduce Harry
id: start
- type: commit
empty: true
message: Add about family

- type: branch
branch-name: with-ginny
- type: checkout
branch-name: with-ginny
- type: commit
empty: true
message: Add about Ginny

- type: checkout
branch-name: main
- type: commit
empty: true
message: Add cast.txt

- type: branch
branch-name: with-sally
- type: checkout
branch-name: with-sally
- type: commit
empty: true
message: Mention Sally

- type: checkout
branch-name: with-ginny
- type: commit
empty: true
message: Mention Ginny is single

- type: checkout
branch-name: main

53 changes: 53 additions & 0 deletions branch_forward/tests/specs/other_branch_ff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
initialization:
steps:
- type: commit
empty: true
message: Introduce Harry
id: start
- type: commit
empty: true
message: Add about family

- type: branch
branch-name: with-ginny
- type: checkout
branch-name: with-ginny
- type: commit
empty: true
message: Add about Ginny

- type: checkout
branch-name: main
- type: commit
empty: true
message: Add cast.txt

- type: branch
branch-name: with-sally
- type: checkout
branch-name: with-sally
- type: commit
empty: true
message: Mention Sally

- type: checkout
branch-name: with-ginny
- type: commit
empty: true
message: Mention Ginny is single

- type: checkout
branch-name: main
- type: branch
branch-name: with-ron
- type: checkout
branch-name: with-ron
- type: commit
empty: true
message: Mention Ron

- type: checkout
branch-name: main
- type: merge
branch-name: with-ron

43 changes: 43 additions & 0 deletions branch_forward/tests/specs/other_branch_non_ff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
initialization:
steps:
- type: commit
empty: true
message: Introduce Harry
id: start
- type: commit
empty: true
message: Add about family

- type: branch
branch-name: with-ginny
- type: checkout
branch-name: with-ginny
- type: commit
empty: true
message: Add about Ginny

- type: checkout
branch-name: main
- type: commit
empty: true
message: Add cast.txt

- type: branch
branch-name: with-sally
- type: checkout
branch-name: with-sally
- type: commit
empty: true
message: Mention Sally

- type: checkout
branch-name: with-ginny
- type: commit
empty: true
message: Mention Ginny is single

- type: checkout
branch-name: main
- type: merge
branch-name: with-ginny

52 changes: 52 additions & 0 deletions branch_forward/tests/test_verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from git_autograder import GitAutograderStatus, GitAutograderTestLoader, assert_output

from ..verify import (
FAST_FORWARD_REQUIRED,
ONLY_WITH_SALLY_MERGED,
verify,
)

REPOSITORY_NAME = "branch-forward"

loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)


def test_success():
with loader.load("specs/base.yml", "start") as output:
assert_output(output, GitAutograderStatus.SUCCESSFUL)


def test_no_merges():
with loader.load("specs/no_merges.yml", "start") as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[ONLY_WITH_SALLY_MERGED],
)


def test_other_branch_non_ff():
with loader.load("specs/other_branch_non_ff.yml", "start") as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[ONLY_WITH_SALLY_MERGED],
)


def test_other_branch_ff():
with loader.load("specs/other_branch_ff.yml", "start") as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[ONLY_WITH_SALLY_MERGED],
)


def test_merge_with_sally_no_ff():
with loader.load("specs/merge_with_sally_no_ff.yml", "start") as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[FAST_FORWARD_REQUIRED],
)
Loading