From 318ebe5c3b98d65c68715d446d11babae791101a Mon Sep 17 00:00:00 2001 From: TheMythologist Date: Sun, 9 Nov 2025 21:19:39 +0800 Subject: [PATCH 1/2] Implement hands on hp-force-push --- hands_on/force_push.py | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 hands_on/force_push.py diff --git a/hands_on/force_push.py b/hands_on/force_push.py new file mode 100644 index 0000000..d0f4d80 --- /dev/null +++ b/hands_on/force_push.py @@ -0,0 +1,46 @@ +from pathlib import Path +import shutil +from exercise_utils.cli import run_command + +__requires_git__ = True +__requires_github__ = True + +REPO_NAME = "samplerepo-things-force-push" +UPSTREAM_REPO = "git-mastery/samplerepo-things" +WORK_DIR = "things" + + +def download(verbose: bool): + """ + hp-force-push (T4L5) + - Fork https://github.com/git-mastery/samplerepo-things to user account as "samplerepo-things-force-push" + - Clone the fork locally as 'samplerepo-things' + """ + + gh_username = run_command(["gh", "api", "user", "-q", ".login"], verbose) + if not gh_username: + raise RuntimeError("Your Github CLI is not setup correctly") + + work_dir = Path(WORK_DIR) + if work_dir.exists(): + shutil.rmtree(work_dir) + + # Fork to user's account and clone + run_command( + [ + "gh", + "repo", + "fork", + UPSTREAM_REPO, + "--default-branch-only", + "--fork-name", + REPO_NAME, + "--clone=true", + "--", + WORK_DIR, + ], + verbose, + ) + + if not work_dir.is_dir(): + raise RuntimeError("Fork/clone failed") From b413646cee3d74f4f8574e3a8a0042846cbafa02 Mon Sep 17 00:00:00 2001 From: TheMythologist Date: Tue, 11 Nov 2025 09:43:59 +0800 Subject: [PATCH 2/2] Remove unnecessary functions --- hands_on/force_push.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/hands_on/force_push.py b/hands_on/force_push.py index d0f4d80..3607ebc 100644 --- a/hands_on/force_push.py +++ b/hands_on/force_push.py @@ -11,16 +11,6 @@ def download(verbose: bool): - """ - hp-force-push (T4L5) - - Fork https://github.com/git-mastery/samplerepo-things to user account as "samplerepo-things-force-push" - - Clone the fork locally as 'samplerepo-things' - """ - - gh_username = run_command(["gh", "api", "user", "-q", ".login"], verbose) - if not gh_username: - raise RuntimeError("Your Github CLI is not setup correctly") - work_dir = Path(WORK_DIR) if work_dir.exists(): shutil.rmtree(work_dir) @@ -41,6 +31,3 @@ def download(verbose: bool): ], verbose, ) - - if not work_dir.is_dir(): - raise RuntimeError("Fork/clone failed")