-
Notifications
You must be signed in to change notification settings - Fork 25
Implement hands on hp-update-remote #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
f3adb79
2730e8c
31b7d9d
414eaa7
b8e4a7c
a1320e8
cad35b3
ede54a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,60 @@ | ||||||||||||||
| import os | ||||||||||||||
| import subprocess | ||||||||||||||
|
|
||||||||||||||
| from exercise_utils.cli import run_command | ||||||||||||||
| from exercise_utils.file import create_or_update_file, append_to_file | ||||||||||||||
| from exercise_utils.git import add, init, commit | ||||||||||||||
|
|
||||||||||||||
| __requires_git__ = True | ||||||||||||||
| __requires_github__ = True | ||||||||||||||
|
|
||||||||||||||
| REPO_NAME = "gitmastery-things" | ||||||||||||||
|
|
||||||||||||||
| def download(verbose: bool): | ||||||||||||||
| username = run_command(["gh", "api", "user", "-q", ".login"], verbose).strip() | ||||||||||||||
| os.makedirs("things") | ||||||||||||||
| os.chdir("things") | ||||||||||||||
| init(verbose) | ||||||||||||||
| create_or_update_file("fruits.txt", """ | ||||||||||||||
| apples | ||||||||||||||
| bananas | ||||||||||||||
| cherries | ||||||||||||||
| dragon fruits | ||||||||||||||
| """, | ||||||||||||||
| ) | ||||||||||||||
| add(["fruits.txt"], verbose) | ||||||||||||||
| append_to_file("fruits.txt", """ | ||||||||||||||
| figs | ||||||||||||||
| """, | ||||||||||||||
| ) | ||||||||||||||
| add(["fruits.txt"], verbose) | ||||||||||||||
| commit("Insert figs into fruits.txt", verbose) | ||||||||||||||
| create_or_update_file("colours.txt", """ | ||||||||||||||
| a file for colours | ||||||||||||||
| """, | ||||||||||||||
| ) | ||||||||||||||
| create_or_update_file("shapes.txt", """ | ||||||||||||||
| a file for shapes | ||||||||||||||
| """, | ||||||||||||||
| ) | ||||||||||||||
| add(["colours.txt", "shapes.txt"], verbose) | ||||||||||||||
| commit("Add colours.txt, shapes.txt", verbose) | ||||||||||||||
damithc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
| repo_check = subprocess.run( | ||||||||||||||
| ["gh", "repo", "view", f"{username}/{REPO_NAME}"], | ||||||||||||||
| capture_output=True, | ||||||||||||||
| text=True | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| if repo_check.returncode == 0: | ||||||||||||||
| run_command(["gh", "repo", "delete", REPO_NAME, "--yes"], verbose) | ||||||||||||||
|
|
||||||||||||||
| run_command(["gh", "repo", "create", REPO_NAME, "--public"], verbose) | ||||||||||||||
| run_command(["git", "remote", "add", "origin", f"https://github.com/{username}/{REPO_NAME}"], verbose) | ||||||||||||||
|
|
||||||||||||||
| default_branch = run_command(["git", "branch", "--list", "main", "master"], verbose).strip() | ||||||||||||||
| if "main" in default_branch: | ||||||||||||||
| default_branch = "main" | ||||||||||||||
| else: | ||||||||||||||
| default_branch = "master" | ||||||||||||||
|
||||||||||||||
| default_branch = run_command(["git", "branch", "--list", "main", "master"], verbose).strip() | |
| if "main" in default_branch: | |
| default_branch = "main" | |
| else: | |
| default_branch = "master" | |
| default_branch = "main" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't catch that. Let me push a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first
addon line 25 stages fruits.txt when it hasn't been committed yet. This adds the initial fruits content to the staging area, then appends 'figs' to the file, and stages it again before committing. However, no commit is made after the firstadd, so both the initial content and the appended 'figs' will be in the same commit. This differs from the pattern in other exercises (like stage_modified.py) and may not demonstrate the intended workflow. Consider adding a commit after line 25 if you want to show two separate commits, or remove the firstaddif you want one commit with all content.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the intended behaviour, as it follows what was laid out in the exercise discussion.