Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions hands_on/move_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from exercise_utils.cli import run_command
from exercise_utils.gitmastery import create_start_tag

import os
from pathlib import Path

__requires_git__ = True
__requires_github__ = True


def download(verbose: bool):
"""
hp-move-tags (T4L2)
- Fork https://github.com/git-mastery/samplerepo-preferences to user account
- Clone the fork locally as 'samplerepo-preferences'
- Create:
* lightweight tag `v1.0` on HEAD
* annotated tag `v0.9` on HEAD~2 with message "First beta release"
"""
Comment on lines +12 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this


# Ensure GitHub CLI is authenticated
gh_user = run_command(["gh", "api", "user", "--jq", ".login"], verbose).strip()
if not gh_user:
raise RuntimeError("GitHub CLI not authenticated. Run `gh auth login` and retry.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already handled when you set __requires_github__ to True


upstream = "git-mastery/samplerepo-preferences"
target_dir = Path("samplerepo-preferences")

# Fresh sandbox, if re-downloading
if target_dir.exists():
import shutil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would avoid local imports, there's no issues with importing it at the start of the script

shutil.rmtree(target_dir)

# Fork to user's account and clone here; origin -> user's fork, upstream -> original
run_command(["gh", "repo", "fork", upstream, "--clone=true", "--remote=true"], verbose)

if not target_dir.exists():
raise RuntimeError("Expected 'samplerepo-preferences' not found after fork/clone.")

os.chdir(target_dir)

# Prepare the tags
run_command(["git", "tag", "v1.0"], verbose) # lightweight on HEAD
run_command(["git", "tag", "-a", "v0.9", "HEAD~2", "-m", "First beta release"], verbose)