Skip to content

Commit ccca7a1

Browse files
authored
Implement mix-messy-docs L2 exercise (#72)
# Exercise Review ## Exercise Discussion #70 ## Checklist - [ ] If you require a new remote repository on the `Git-Mastery` organization, have you [created a request](https://github.com/git-mastery/exercises/issues/new?template=request_exercise_repository.md) for it? - [ ] Have you written unit tests using [`repo-smith`](https://github.com/git-mastery/repo-smith) to validate the exercise grading scheme? - [ ] Have you tested the download script using `test-download.sh`? - [ ] Have you verified that this exercise does not already exist or is not currently in review? - [ ] Did you introduce a new grading mechanism that should belong to [`git-autograder`](https://github.com/git-mastery/git-autograder)? - [ ] Did you introduce a new dependency that should belong to [`app`](https://github.com/git-mastery/app)?
2 parents a1d9aee + 2fa4917 commit ccca7a1

16 files changed

+771
-0
lines changed

exercise_utils/git.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ def init(verbose: bool) -> None:
6868
def push(remote: str, branch: str, verbose: bool) -> None:
6969
"""Push the given branch on the remote."""
7070
run_command(["git", "push", remote, branch], verbose)
71+
72+
73+
def track_remote_branch(remote: str, branch: str, verbose: bool) -> None:
74+
"""Tracks a remote branch locally using the same name."""
75+
run_command(["git", "branch", branch, f"{remote}/{branch}"], verbose)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"exercise_name": "mix-messy-docs",
3+
"tags": [
4+
"git-branch"
5+
],
6+
"requires_git": true,
7+
"requires_github": true,
8+
"base_files": {},
9+
"exercise_repo": {
10+
"repo_type": "remote",
11+
"repo_name": "user-docs",
12+
"repo_title": "gm-user-docs",
13+
"create_fork": false,
14+
"init": null
15+
}
16+
}

mix_messy_docs/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# mix-messy-docs
2+
3+
You are writing user documentation for a product. You have already written documentation for a few new features, each in a separate branch. You wish to accumulate this work in a separate branch called `development` until the next product release.
4+
5+
## Task
6+
7+
1. Create a new branch `development`, starting from the commit tagged `v1.0`
8+
2. Merge the `feature-search` branch onto the `development` branch, without using fast-forwarding (i.e., create a merge commit). Delete the `feature-search` branch.
9+
3. Similarly, merge the `feature-delete` branch onto the `development` branch. Resolve any merge conflicts -- in the `features.md`, the delete feature should appear after the search feature (see below). Delete the `feature-delete` branch.
10+
```
11+
# Features
12+
13+
## Create Book
14+
15+
Allows creating one book at a time.
16+
17+
## Searching for Books
18+
19+
Allows searching for books by keywords.
20+
Works only for book titles.
21+
22+
## Deleting Books
23+
24+
Allows deleting books.
25+
```
26+
5. The `list` branch is not yet ready to be merged but rename it as `feature-list`, to be consistent with the naming convention you have been following in this repo.
27+

mix_messy_docs/__init__.py

Whitespace-only changes.

mix_messy_docs/download.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from exercise_utils.git import track_remote_branch
2+
3+
4+
def setup(verbose: bool = False):
5+
remote_name = "origin"
6+
remote_branches = ["feature-search", "feature-delete", "list"]
7+
for remote_branch_name in remote_branches:
8+
track_remote_branch(remote_name, remote_branch_name, verbose)

mix_messy_docs/tests/__init__.py

Whitespace-only changes.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
7+
- type: new-file
8+
filename: conflict.txt
9+
contents: |
10+
Hello world
11+
- type: add
12+
files:
13+
- conflict.txt
14+
- type: commit
15+
message: Expected branch point
16+
- type: tag
17+
tag-name: v1.0
18+
19+
- type: branch
20+
branch-name: feature-search
21+
- type: edit-file
22+
filename: conflict.txt
23+
contents: |
24+
Hello world!
25+
- type: add
26+
files:
27+
- conflict.txt
28+
- type: commit
29+
message: Feature search changes
30+
- type: checkout
31+
branch-name: main
32+
33+
- type: branch
34+
branch-name: feature-delete
35+
- type: edit-file
36+
filename: conflict.txt
37+
contents: |
38+
Hello world?
39+
- type: add
40+
files:
41+
- conflict.txt
42+
- type: commit
43+
message: Feature delete changes
44+
- type: checkout
45+
branch-name: main
46+
47+
- type: branch
48+
branch-name: feature-list
49+
- type: commit
50+
empty: true
51+
message: Feature list changes
52+
53+
- type: checkout
54+
branch-name: main
55+
- type: branch
56+
branch-name: development
57+
- type: commit
58+
empty: true
59+
message: Commit on development
60+
- type: merge
61+
branch-name: feature-search
62+
no-ff: true
63+
- type: bash
64+
runs: |
65+
# Controlling everything through Bash to simplify workflow
66+
(git merge feature-delete || true) > /dev/null
67+
echo 'New contents' > conflict.txt
68+
git add conflict.txt
69+
(git commit --no-edit) > /dev/null
70+
71+
- type: new-file
72+
filename: features.md
73+
contents: |
74+
# Features
75+
76+
## Searching for Books
77+
78+
Allows searching for books by keywords.
79+
Works only for book titles.
80+
81+
## Create Book
82+
83+
Allows creating one book at a time.
84+
85+
86+
## Deleting Books
87+
88+
Allows deleting books.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
7+
- type: new-file
8+
filename: conflict.txt
9+
contents: |
10+
Hello world
11+
- type: add
12+
files:
13+
- conflict.txt
14+
- type: commit
15+
message: Expected branch point
16+
- type: tag
17+
tag-name: v1.0
18+
19+
- type: branch
20+
branch-name: feature-search
21+
- type: edit-file
22+
filename: conflict.txt
23+
contents: |
24+
Hello world!
25+
- type: add
26+
files:
27+
- conflict.txt
28+
- type: commit
29+
message: Feature search changes
30+
- type: checkout
31+
branch-name: main
32+
33+
- type: branch
34+
branch-name: feature-delete
35+
- type: edit-file
36+
filename: conflict.txt
37+
contents: |
38+
Hello world?
39+
- type: add
40+
files:
41+
- conflict.txt
42+
- type: commit
43+
message: Feature delete changes
44+
- type: checkout
45+
branch-name: main
46+
47+
- type: branch
48+
branch-name: other-list
49+
- type: commit
50+
empty: true
51+
message: Feature list changes
52+
53+
- type: checkout
54+
branch-name: main
55+
- type: branch
56+
branch-name: development
57+
- type: commit
58+
empty: true
59+
message: Commit on development
60+
- type: merge
61+
branch-name: feature-search
62+
no-ff: true
63+
- type: bash
64+
runs: |
65+
# Controlling everything through Bash to simplify workflow
66+
(git merge feature-delete || true) > /dev/null
67+
echo 'New contents' > conflict.txt
68+
git add conflict.txt
69+
(git commit --no-edit) > /dev/null
70+
71+
- type: new-file
72+
filename: features.md
73+
contents: |
74+
# Features
75+
76+
## Create Book
77+
78+
Allows creating one book at a time.
79+
80+
## Searching for Books
81+
82+
Allows searching for books by keywords.
83+
Works only for book titles.
84+
85+
## Deleting Books
86+
87+
Allows deleting books.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start
7+
- type: new-file
8+
filename: conflict.txt
9+
contents: |
10+
Hello world
11+
- type: add
12+
files:
13+
- conflict.txt
14+
- type: commit
15+
message: Expected branch point
16+
- type: tag
17+
tag-name: v1.0
18+
19+
- type: branch
20+
branch-name: feature-search
21+
- type: edit-file
22+
filename: conflict.txt
23+
contents: |
24+
Hello world!
25+
- type: add
26+
files:
27+
- conflict.txt
28+
- type: commit
29+
message: Feature search changes
30+
- type: checkout
31+
branch-name: main
32+
33+
- type: branch
34+
branch-name: feature-delete
35+
- type: edit-file
36+
filename: conflict.txt
37+
contents: |
38+
Hello world?
39+
- type: add
40+
files:
41+
- conflict.txt
42+
- type: commit
43+
message: Feature delete changes
44+
- type: checkout
45+
branch-name: main
46+
47+
- type: branch
48+
branch-name: list
49+
- type: commit
50+
empty: true
51+
message: Feature list changes
52+
53+
- type: checkout
54+
branch-name: main
55+
- type: branch
56+
branch-name: development
57+
- type: commit
58+
empty: true
59+
message: Commit on development
60+
- type: merge
61+
branch-name: feature-search
62+
no-ff: true
63+
- type: bash
64+
runs: |
65+
# Controlling everything through Bash to simplify workflow
66+
(git merge feature-delete || true) > /dev/null
67+
echo 'New contents' > conflict.txt
68+
git add conflict.txt
69+
(git commit --no-edit) > /dev/null
70+
71+
- type: new-file
72+
filename: features.md
73+
contents: |
74+
# Features
75+
76+
## Create Book
77+
78+
Allows creating one book at a time.
79+
80+
## Searching for Books
81+
82+
Allows searching for books by keywords.
83+
Works only for book titles.
84+
85+
## Deleting Books
86+
87+
Allows deleting books.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty commit
6+
id: start

0 commit comments

Comments
 (0)