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 mix_messy_graph/.gitmastery-exercise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"exercise_name": "mix-messy-graph",
"tags": [
"git-branch",
"git-merge"
],
"requires_git": true,
"requires_github": true,
"base_files": {},
"exercise_repo": {
"repo_type": "remote",
"repo_name": "user-docs",
"repo_title": "gm-user-docs",
"create_fork": false,
"init": null
}
}
20 changes: 20 additions & 0 deletions mix_messy_graph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# mix-messy-graph

You are writing user documentation for a product. You have already written documentation for a few new features, each in a separate branch. After merging the `feature-search` branch, you realise this way of merging can result in a complicated revision graph. Instead, you wish to merge these changes in a way that results in a simple linear revision graph.

## Task

1. Undo the merging of `feature-search`.
2. Squash-merge the `feature-search` branch onto the `main` branch. Delete the `feature-search` branch.
3. Similarly, squash-merge and delete the `feature-delete` branch, while resolving any merge conflicts -- in the `features.md`, the delete feature should appear after the search feature.
4. The `list` branch is not needed, as you have decided not to have that feature. Delete that branch.

The resulting revision graph should be as follows:

```mermaid
gitGraph BT:
commit id: "Add features.md"
commit id: "Mention feature for creating books" tag: "v10"
commit id: "Add the delete feature"
commit id: "Add the search feature"
```
Empty file added mix_messy_graph/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions mix_messy_graph/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from exercise_utils.git import merge, merge_with_message, track_remote_branch


def setup(verbose: bool = False):
remote_name = "origin"
remote_branches = ["feature-search", "feature-delete", "list"]
for remote_branch_name in remote_branches:
track_remote_branch(remote_name, remote_branch_name, verbose)

merge_with_message("feature-search", False, "Merge search feature", verbose)
Empty file.
40 changes: 40 additions & 0 deletions mix_messy_graph/tests/specs/base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
initialization:
steps:
- type: commit
empty: true
message: Add features.md
id: start
- type: commit
empty: true
message: Mention feature for creating books
- type: tag
tag-name: v1.0
- type: commit
empty: true
message: Fix phrasing of heading

- type: commit
empty: true
message: Add the search feature

- type: commit
empty: true
message: Add the delete feature

- type: new-file
filename: features.md
contents: |
# Features

## Create Book

Allows creating one book at a time.

## Searching for Books

Allows searching for books by keywords.
Works only for book titles.

## Deleting Books

Allows deleting books.
51 changes: 51 additions & 0 deletions mix_messy_graph/tests/specs/branches_not_deleted.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
initialization:
steps:
- type: commit
empty: true
message: Add features.md
id: start
- type: commit
empty: true
message: Mention feature for creating books
- type: tag
tag-name: v1.0
- type: commit
empty: true
message: Fix phrasing of heading

- type: commit
empty: true
message: Add the search feature

- type: commit
empty: true
message: Add the delete feature

- type: branch
branch-name: feature-search
- type: checkout
branch-name: main
- type: branch
branch-name: feature-delete
- type: checkout
branch-name: main
- type: branch
branch-name: list

- type: new-file
filename: features.md
contents: |
# Features

## Create Book

Allows creating one book at a time.

## Searching for Books

Allows searching for books by keywords.
Works only for book titles.

## Deleting Books

Allows deleting books.
40 changes: 40 additions & 0 deletions mix_messy_graph/tests/specs/features_content_invalid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
initialization:
steps:
- type: commit
empty: true
message: Add features.md
id: start
- type: commit
empty: true
message: Mention feature for creating books
- type: tag
tag-name: v1.0
- type: commit
empty: true
message: Fix phrasing of heading

- type: commit
empty: true
message: Add the search feature

- type: commit
empty: true
message: Add the delete feature

- type: new-file
filename: features.md
contents: |
# Features

## Searching for Books

Allows searching for books by keywords.
Works only for book titles.

## Create Book

Allows creating one book at a time.

## Deleting Books

Allows deleting books.
36 changes: 36 additions & 0 deletions mix_messy_graph/tests/specs/missing_commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
initialization:
steps:
- type: commit
empty: true
message: Add features.md
id: start
- type: commit
empty: true
message: Mention feature for creating books
- type: tag
tag-name: v1.0
- type: commit
empty: true
message: Fix phrasing of heading

- type: commit
empty: true
message: Add the search feature

- type: new-file
filename: features.md
contents: |
# Features

## Create Book

Allows creating one book at a time.

## Searching for Books

Allows searching for books by keywords.
Works only for book titles.

## Deleting Books

Allows deleting books.
46 changes: 46 additions & 0 deletions mix_messy_graph/tests/specs/non_squash_merge_used.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
initialization:
steps:
- type: commit
empty: true
message: Add features.md
id: start
- type: commit
empty: true
message: Mention feature for creating books
- type: tag
tag-name: v1.0
- type: commit
empty: true
message: Fix phrasing of heading

- type: branch
branch-name: feature-search
- type: commit
empty: true
message: Feature search
- type: checkout
branch-name: main
- type: merge
branch-name: feature-search

- type: commit
empty: true
message: Add the delete feature

- type: new-file
filename: features.md
contents: |
# Features

## Create Book

Allows creating one book at a time.

## Searching for Books

Allows searching for books by keywords.
Works only for book titles.

## Deleting Books

Allows deleting books.
40 changes: 40 additions & 0 deletions mix_messy_graph/tests/specs/wrong_commit_message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
initialization:
steps:
- type: commit
empty: true
message: Add features.md
id: start
- type: commit
empty: true
message: Mention feature for creating books
- type: tag
tag-name: v1.0
- type: commit
empty: true
message: Fix phrasing of heading

- type: commit
empty: true
message: Add the search feature!

- type: commit
empty: true
message: Add the delete feature

- type: new-file
filename: features.md
contents: |
# Features

## Create Book

Allows creating one book at a time.

## Searching for Books

Allows searching for books by keywords.
Works only for book titles.

## Deleting Books

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

from ..verify import (
FEATURE_SEARCH_BRANCH_STILL_EXISTS,
FEATURE_DELETE_BRANCH_STILL_EXISTS,
FEATURES_FILE_CONTENT_INVALID,
LIST_BRANCH_STILL_EXISTS,
MISMATCH_COMMIT_MESSAGE,
SQUASH_NOT_USED,
verify,
)

REPOSITORY_NAME = "mix-messy-graph"

loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify)


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


def test_non_squash_merge_used():
with loader.load("specs/non_squash_merge_used.yml") as output:
assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [SQUASH_NOT_USED])


def test_wrong_commit_message():
with loader.load("specs/wrong_commit_message.yml") as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[
MISMATCH_COMMIT_MESSAGE.format(
expected="Add the search feature", given="Add the search feature!"
)
],
)


def test_missing_commit():
with loader.load("specs/missing_commit.yml") as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[
MISMATCH_COMMIT_MESSAGE.format(
expected="Add the delete feature", given="<Missing commit>"
)
],
)


def test_branches_not_deleted():
with loader.load("specs/branches_not_deleted.yml") as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[
FEATURE_SEARCH_BRANCH_STILL_EXISTS,
FEATURE_DELETE_BRANCH_STILL_EXISTS,
LIST_BRANCH_STILL_EXISTS,
],
)


def test_features_content_invalid():
with loader.load("specs/features_content_invalid.yml") as output:
assert_output(
output,
GitAutograderStatus.UNSUCCESSFUL,
[FEATURES_FILE_CONTENT_INVALID],
)
Loading