Skip to content

Commit 32b9afe

Browse files
committed
[bonsai-tree] Add bonsai-tree exercise
1 parent dfa84cb commit 32b9afe

19 files changed

+634
-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": "bonsai-tree",
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": "care-notes",
13+
"repo_title": null,
14+
"create_fork": null,
15+
"init": true
16+
}
17+
}

bonsai_tree/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# bonsai-tree
2+
3+
You are an aspiring botanist and you are starting to take notes of the various botany facts related to [bonsai trees]()
4+
5+
## Task
6+
7+
Create a new file titled `dangers-to-bonsais.txt` on the `main` branch with the following text:
8+
9+
```text
10+
Bonsai trees are delicate and vulnerable to threats like overwatering, pests, fungal infections, and extreme temperatures. Poor pruning or wiring can cause lasting damage, while dehydration and root rot are common killers. Without careful maintenance, these miniature trees can quickly decline.
11+
```
12+
13+
Create a new branch `history` and add another file `history-of-bonsais.txt` with the following text:
14+
15+
```text
16+
Bonsai originated in China over a thousand years ago as "penjing," the art of miniature landscape cultivation. The practice later spread to Japan, where it evolved into the refined bonsai we know today, emphasizing simplicity, balance, and harmony with nature. Traditionally associated with Zen Buddhism, bonsai became a symbol of patience and artistic expression. Over time, it gained global popularity, with enthusiasts worldwide cultivating these miniature trees as a blend of horticulture and art.
17+
```
18+
19+
Finally, create a final branch that goes off of `history` called `care` and edit the empty `bonsai-care.txt` file with the following text:
20+
21+
```text
22+
Proper bonsai care involves balancing water, light, and nutrients to maintain a healthy tree. Bonsais require well-draining soil and regular watering, but overwatering can lead to root rot. They need adequate sunlight, with indoor varieties thriving near bright windows and outdoor species requiring seasonal adjustments. Pruning and wiring help shape the tree, while repotting every few years ensures root health. Protecting bonsais from pests, extreme temperatures, and diseases is essential for their longevity, making their care both an art and a discipline.
23+
```
24+
25+
Ultimately, your Git tree should look like this:
26+
27+
![Expected tree](./res/expected-tree.png)
28+

bonsai_tree/__init__.py

Whitespace-only changes.

bonsai_tree/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__ = {"bonsai-care.txt": "bonsai-care.txt"}
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)

bonsai_tree/res/bonsai-care.txt

Whitespace-only changes.

bonsai_tree/res/expected-tree.png

23.3 KB
Loading

bonsai_tree/tests/__init__.py

Whitespace-only changes.

bonsai_tree/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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
initialization:
2+
steps:
3+
- type: new-file
4+
filename: bonsai-care.txt
5+
contents:
6+
- type: add
7+
files:
8+
- bonsai-care.txt
9+
- type: commit
10+
message: Start
11+
id: start
12+
- type: new-file
13+
filename: dangers-to-bonsais.txt
14+
contents: |
15+
Bonsai trees are delicate and vulnerable to threats like overwatering, pests, fungal infections, and extreme temperatures. Poor pruning or wiring can cause lasting damage, while dehydration and root rot are common killers. Without careful maintenance, these miniature trees can quickly decline.
16+
- type: add
17+
files:
18+
- dangers-to-bonsais.txt
19+
- type: commit
20+
message: Add dangers
21+
- type: branch
22+
branch-name: history
23+
- type: new-file
24+
filename: history-of-bonsais.txt
25+
contents: |
26+
Bonsai originated in China over a thousand years ago as "penjing," the art of miniature landscape cultivation. The practice later spread to Japan, where it evolved into the refined bonsai we know today, emphasizing simplicity, balance, and harmony with nature. Traditionally associated with Zen Buddhism, bonsai became a symbol of patience and artistic expression. Over time, it gained global popularity, with enthusiasts worldwide cultivating these miniature trees as a blend of horticulture and art.
27+
- type: add
28+
files:
29+
- history-of-bonsais.txt
30+
- type: commit
31+
message: Add history
32+
- type: branch
33+
branch-name: care
34+
- type: edit-file
35+
filename: bonsai-care.txt
36+
contents: |
37+
Proper bonsai care involves balancing water, light, and nutrients to maintain a healthy tree. Bonsais require well-draining soil and regular watering, but overwatering can lead to root rot. They need adequate sunlight, with indoor varieties thriving near bright windows and outdoor species requiring seasonal adjustments. Pruning and wiring help shape the tree, while repotting every few years ensures root health. Protecting bonsais from pests, extreme temperatures, and diseases is essential for their longevity, making their care both an art and a discipline.
38+
- type: add
39+
files:
40+
- bonsai-care.txt
41+
- type: commit
42+
message: Add bonsai care
43+
- type: checkout
44+
branch-name: main
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
initialization:
2+
steps:
3+
- type: new-file
4+
filename: bonsai-care.txt
5+
contents:
6+
- type: add
7+
files:
8+
- bonsai-care.txt
9+
- type: commit
10+
message: Start
11+
id: start
12+
- type: new-file
13+
filename: dangers-to-bonsais.txt
14+
contents: |
15+
Bonsai trees are delicate and vulnerable to threats like overwatering, pests, fungal infections, and extreme temperatures. Poor pruning or wiring can cause lasting damage, while dehydration and root rot are common killers. Without careful maintenance, these miniature trees can quickly decline.
16+
- type: add
17+
files:
18+
- dangers-to-bonsais.txt
19+
- type: commit
20+
message: Add dangers
21+
- type: branch
22+
branch-name: history
23+
- type: new-file
24+
filename: history-of-bonsais.txt
25+
contents: |
26+
Bonsai originated in China over a thousand years ago as "penjing," the art of miniature landscape cultivation. The practice later spread to Japan, where it evolved into the refined bonsai we know today, emphasizing simplicity, balance, and harmony with nature. Traditionally associated with Zen Buddhism, bonsai became a symbol of patience and artistic expression. Over time, it gained global popularity, with enthusiasts worldwide cultivating these miniature trees as a blend of horticulture and art.
27+
- type: add
28+
files:
29+
- history-of-bonsais.txt
30+
- type: commit
31+
message: Add history
32+
- type: branch
33+
branch-name: care
34+
- type: edit-file
35+
filename: bonsai-care.txt
36+
contents: |
37+
bonsai care involves balancing water, light, and nutrients to maintain a healthy tree. Bonsais require well-draining soil and regular watering, but overwatering can lead to root rot. They need adequate sunlight, with indoor varieties thriving near bright windows and outdoor species requiring seasonal adjustments. Pruning and wiring help shape the tree, while repotting every few years ensures root health. Protecting bonsais from pests, extreme temperatures, and diseases is essential for their longevity, making their care both an art and a discipline.
38+
- type: add
39+
files:
40+
- bonsai-care.txt
41+
- type: commit
42+
message: Add bonsai care
43+
- type: checkout
44+
branch-name: main

0 commit comments

Comments
 (0)