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
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
}
}
26 changes: 26 additions & 0 deletions branch_forward/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# branch-forward

You are outlining a story and experimenting with different plotlines. Each version lives on its own branch, and you now need to fold the right storyline back into `main` without cluttering the history.

## Learning objectives

- Identify when a branch can be fast-forward merged
- Use fast-forward merges to keep the commit graph linear
- [Fast-forward merges](https://nus-cs2103-ay2526s1.github.io/website/book/gitAndGithub/merge/index.html)

## 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

46 changes: 46 additions & 0 deletions branch_forward/tests/specs/with_sally_non_ff_then_ff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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: bash
runs: |
git merge with-sally --no-ff -m "Non fast-forward merge"
git reset --hard 'HEAD^'
git merge with-sally

Loading