|
1 | | -import subprocess |
2 | | -from sys import exit |
3 | | -from typing import List, Optional |
4 | | - |
5 | | - |
6 | | -def run_command(command: List[str], verbose: bool) -> Optional[str]: |
7 | | - try: |
8 | | - result = subprocess.run( |
9 | | - command, |
10 | | - capture_output=True, |
11 | | - text=True, |
12 | | - check=True, |
13 | | - ) |
14 | | - if verbose: |
15 | | - print(result.stdout) |
16 | | - return result.stdout |
17 | | - except subprocess.CalledProcessError as e: |
18 | | - if verbose: |
19 | | - print(e.stderr) |
20 | | - exit(1) |
| 1 | +from exercise_utils.file import create_or_update_file |
| 2 | +from exercise_utils.git import add |
| 3 | +from exercise_utils.gitmastery import create_start_tag |
21 | 4 |
|
22 | 5 |
|
23 | 6 | def setup(verbose: bool = False): |
24 | 7 | names = ["alice", "bob", "joe", "jim", "carrey"] |
25 | 8 | for name in names: |
26 | | - open(f"{name}.txt", "a").close() |
27 | | - run_command(["git", "add", "jim.txt"], verbose) |
28 | | - run_command(["git", "add", "carrey.txt"], verbose) |
29 | | - commits_str = run_command( |
30 | | - ["git", "log", "--reverse", "--pretty=format:%h"], verbose |
31 | | - ) |
32 | | - assert commits_str is not None |
33 | | - first_commit = commits_str.split(" ")[0] |
34 | | - tag_name = f"git-mastery-start-{first_commit}" |
35 | | - run_command(["git", "tag", tag_name], verbose) |
| 9 | + create_or_update_file(f"{name}.txt", "a") |
| 10 | + add(["jim.txt", "carrey.txt"], verbose) |
| 11 | + create_start_tag(verbose) |
0 commit comments