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
5 changes: 5 additions & 0 deletions exercise_utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,8 @@ def init(verbose: bool) -> None:
def push(remote: str, branch: str, verbose: bool) -> None:
"""Push the given branch on the remote."""
run_command(["git", "push", remote, branch], verbose)


def track_remote_branch(remote: str, branch: str, verbose: bool) -> None:
"""Tracks a remote branch locally using the same name."""
run_command(["git", "branch", branch, f"{remote}/{branch}"], verbose)
16 changes: 16 additions & 0 deletions mix_messy_docs/.gitmastery-exercise.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"exercise_name": "mix-messy-docs",
"tags": [
"git-branch"
],
"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
}
}
27 changes: 27 additions & 0 deletions mix_messy_docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# mix-messy-docs

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.

## Task

1. Create a new branch `development`, starting from the commit tagged `v1.0`
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.
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.
```
# 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.
```
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.

Empty file added mix_messy_docs/__init__.py
Empty file.
8 changes: 8 additions & 0 deletions mix_messy_docs/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from exercise_utils.git import 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)
Empty file.
88 changes: 88 additions & 0 deletions mix_messy_docs/tests/specs/contents_wrong.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
initialization:
steps:
- type: commit
empty: true
message: Empty commit
id: start
- type: new-file
filename: conflict.txt
contents: |
Hello world
- type: add
files:
- conflict.txt
- type: commit
message: Expected branch point
- type: tag
tag-name: v1.0

- type: branch
branch-name: feature-search
- type: edit-file
filename: conflict.txt
contents: |
Hello world!
- type: add
files:
- conflict.txt
- type: commit
message: Feature search changes
- type: checkout
branch-name: main

- type: branch
branch-name: feature-delete
- type: edit-file
filename: conflict.txt
contents: |
Hello world?
- type: add
files:
- conflict.txt
- type: commit
message: Feature delete changes
- type: checkout
branch-name: main

- type: branch
branch-name: feature-list
- type: commit
empty: true
message: Feature list changes

- type: checkout
branch-name: main
- type: branch
branch-name: development
- type: commit
empty: true
message: Commit on development
- type: merge
branch-name: feature-search
no-ff: true
- type: bash
runs: |
# Controlling everything through Bash to simplify workflow
(git merge feature-delete || true) > /dev/null
echo 'New contents' > conflict.txt
git add conflict.txt
(git commit --no-edit) > /dev/null

- 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.
87 changes: 87 additions & 0 deletions mix_messy_docs/tests/specs/feature_list_branch_missing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
initialization:
steps:
- type: commit
empty: true
message: Empty commit
id: start
- type: new-file
filename: conflict.txt
contents: |
Hello world
- type: add
files:
- conflict.txt
- type: commit
message: Expected branch point
- type: tag
tag-name: v1.0

- type: branch
branch-name: feature-search
- type: edit-file
filename: conflict.txt
contents: |
Hello world!
- type: add
files:
- conflict.txt
- type: commit
message: Feature search changes
- type: checkout
branch-name: main

- type: branch
branch-name: feature-delete
- type: edit-file
filename: conflict.txt
contents: |
Hello world?
- type: add
files:
- conflict.txt
- type: commit
message: Feature delete changes
- type: checkout
branch-name: main

- type: branch
branch-name: other-list
- type: commit
empty: true
message: Feature list changes

- type: checkout
branch-name: main
- type: branch
branch-name: development
- type: commit
empty: true
message: Commit on development
- type: merge
branch-name: feature-search
no-ff: true
- type: bash
runs: |
# Controlling everything through Bash to simplify workflow
(git merge feature-delete || true) > /dev/null
echo 'New contents' > conflict.txt
git add conflict.txt
(git commit --no-edit) > /dev/null

- 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.
87 changes: 87 additions & 0 deletions mix_messy_docs/tests/specs/list_branch_exists.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
initialization:
steps:
- type: commit
empty: true
message: Empty commit
id: start
- type: new-file
filename: conflict.txt
contents: |
Hello world
- type: add
files:
- conflict.txt
- type: commit
message: Expected branch point
- type: tag
tag-name: v1.0

- type: branch
branch-name: feature-search
- type: edit-file
filename: conflict.txt
contents: |
Hello world!
- type: add
files:
- conflict.txt
- type: commit
message: Feature search changes
- type: checkout
branch-name: main

- type: branch
branch-name: feature-delete
- type: edit-file
filename: conflict.txt
contents: |
Hello world?
- type: add
files:
- conflict.txt
- type: commit
message: Feature delete changes
- type: checkout
branch-name: main

- type: branch
branch-name: list
- type: commit
empty: true
message: Feature list changes

- type: checkout
branch-name: main
- type: branch
branch-name: development
- type: commit
empty: true
message: Commit on development
- type: merge
branch-name: feature-search
no-ff: true
- type: bash
runs: |
# Controlling everything through Bash to simplify workflow
(git merge feature-delete || true) > /dev/null
echo 'New contents' > conflict.txt
git add conflict.txt
(git commit --no-edit) > /dev/null

- 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.
6 changes: 6 additions & 0 deletions mix_messy_docs/tests/specs/missing_development.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
initialization:
steps:
- type: commit
empty: true
message: Empty commit
id: start
Loading