Skip to content

Commit e07558c

Browse files
authored
Merge pull request #10 from git-mastery/side-track
Add side-track exercise
2 parents 2b255e5 + 719b749 commit e07558c

16 files changed

+355
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"exercise_name": "side-track",
3+
"tags": [
4+
"git-branch",
5+
"git-checkout"
6+
],
7+
"requires_git": true,
8+
"requires_github": false,
9+
"base_files": {},
10+
"exercise_repo": {
11+
"repo_type": "local",
12+
"repo_name": "branch-me",
13+
"repo_title": null,
14+
"create_fork": null,
15+
"init": true
16+
}
17+
}

side_track/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# side-track
2+
3+
You realized that something is broken with your project and want to fix it. But you are also currently working on a major feature on `main` right now
4+
and you don't want to push that major feature yet.
5+
6+
## Task
7+
8+
### Task 1
9+
10+
Create a bug fix branch named `bug-fix` and go to the branch.
11+
12+
### Task 2
13+
14+
On `bug-fix`, open the `greet.py` file and ensure that the `greet` function prints the `name` variable, not just `Alice`.
15+
16+
Commit and save the fix.
17+
18+
### Task 3
19+
20+
On `bug-fix`, open the `calculator.py` file and ensure that the `add` function returns the sum of two numbers.
21+
22+
Commit and save the fix.
23+
24+
### Task 4
25+
26+
Return to the `main` branch where you're working on your major feature.
27+

side_track/__init__.py

Whitespace-only changes.

side_track/download.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import subprocess
2+
from sys import exit
3+
from typing import List, Optional
4+
5+
__resources__ = {"calculator.py": "calculator.py", "greet.py": "greet.py"}
6+
7+
8+
def run_command(command: List[str], verbose: bool) -> Optional[str]:
9+
try:
10+
result = subprocess.run(
11+
command,
12+
capture_output=True,
13+
text=True,
14+
check=True,
15+
)
16+
if verbose:
17+
print(result.stdout)
18+
return result.stdout
19+
except subprocess.CalledProcessError as e:
20+
if verbose:
21+
print(e.stderr)
22+
exit(1)
23+
24+
25+
def setup(verbose: bool = False):
26+
commits_str = run_command(
27+
["git", "log", "--reverse", "--pretty=format:%h"], verbose
28+
)
29+
assert commits_str is not None
30+
first_commit = commits_str.split("\n")[0]
31+
tag_name = f"git-mastery-start-{first_commit}"
32+
run_command(["git", "tag", tag_name], verbose)

side_track/res/calculator.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def add(a, b):
2+
return a - b
3+
4+
5+
def subtract(a, b):
6+
return a - b
7+
8+
9+
def divide(a, b):
10+
return a / b
11+
12+
13+
def multiply(a, b):
14+
return a * b

side_track/res/greet.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def greet(name):
2+
# TODO: Fix this to print name, not just Alice all the time
3+
print("Hi Alice")
4+
5+
6+
greet("John")
7+
greet("Joe")
8+
greet("Alice")

side_track/tests/__init__.py

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty
6+
id: start
7+
- type: branch
8+
branch-name: bug-fix
9+
- type: new-file
10+
filename: greet.py
11+
contents: |
12+
def greet(name):
13+
print("Hi " + name)
14+
- type: new-file
15+
filename: calculator.py
16+
contents: |
17+
def add(a, b):
18+
return a - b
19+
- type: commit
20+
empty: true
21+
message: Empty
22+
- type: add
23+
files:
24+
- greet.py
25+
- calculator.py
26+
- type: commit
27+
message: Add
28+
- type: checkout
29+
branch-name: main

side_track/tests/specs/base.yml

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
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
initialization:
2+
steps:
3+
- type: commit
4+
empty: true
5+
message: Empty
6+
id: start
7+
- type: branch
8+
branch-name: bug-fix
9+
- type: new-file
10+
filename: greet.py
11+
contents: |
12+
def greet(name):
13+
print("Hi Alice")
14+
- type: new-file
15+
filename: calculator.py
16+
contents: |
17+
def add(a, b):
18+
return a + b
19+
- type: commit
20+
empty: true
21+
message: Empty
22+
- type: add
23+
files:
24+
- greet.py
25+
- calculator.py
26+
- type: commit
27+
message: Add
28+
- type: checkout
29+
branch-name: main

0 commit comments

Comments
 (0)