Skip to content
Merged
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
45 changes: 45 additions & 0 deletions hands_on/remote_branch_pull.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import os

from exercise_utils.file import append_to_file
from exercise_utils.git import (
add,
checkout,
clone_repo_with_git,
commit,
push
)
from exercise_utils.github_cli import (
get_github_username,
fork_repo,
has_repo,
delete_repo,
)

__requires_git__ = True
__requires_github__ = True


TARGET_REPO = "git-mastery/samplerepo-company"
FORK_NAME = "gitmastery-samplerepo-company"
LOCAL_DIR = "samplerepo-company"


def download(verbose: bool):
username = get_github_username(verbose)
full_repo_name = f"{username}/{FORK_NAME}"

if has_repo(full_repo_name, True, verbose):
delete_repo(full_repo_name, verbose)

fork_repo(TARGET_REPO, FORK_NAME, verbose, False)
clone_repo_with_git(f"https://github.com/{full_repo_name}", verbose, LOCAL_DIR)

os.chdir(LOCAL_DIR)

checkout("hiring", True, verbose)
append_to_file("employees.txt", "Receptionist: Pam\n")
add(["employees.txt"], verbose)
commit("Add Pam to employees.txt", verbose)

push("origin", "hiring", verbose)