Skip to content

Commit d9bf0bf

Browse files
[hp-remote-branch-pull-new] Implement remote-branch-pull-new
1 parent aa3c4a4 commit d9bf0bf

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

hands_on/remote_branch_pull_new.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
3+
from exercise_utils.file import append_to_file
4+
from exercise_utils.git import delete_remote_tracking_branch_locally, remove_remote, add, checkout, commit, push
5+
from exercise_utils.github_cli import (
6+
get_github_username, fork_repo,
7+
has_repo,
8+
delete_repo,
9+
clone_repo_with_gh,
10+
)
11+
12+
__requires_git__ = True
13+
__requires_github__ = True
14+
15+
TARGET_REPO = "git-mastery/samplerepo-company"
16+
FORK_NAME = "gitmastery-samplerepo-company"
17+
LOCAL_DIR = "samplerepo-company"
18+
19+
def download(verbose: bool):
20+
username = get_github_username(verbose)
21+
full_repo_name = f"{username}/{FORK_NAME}"
22+
23+
if has_repo(full_repo_name, True, verbose):
24+
delete_repo(full_repo_name, verbose)
25+
26+
fork_repo(TARGET_REPO, FORK_NAME, verbose, False)
27+
clone_repo_with_gh(full_repo_name, verbose, LOCAL_DIR)
28+
29+
os.chdir(LOCAL_DIR)
30+
31+
remove_remote("upstream", verbose)
32+
delete_remote_tracking_branch_locally("origin", "track-sales", verbose)
33+
34+
checkout("hiring", True, verbose)
35+
append_to_file("employees.txt", "Receptionist: Pam\n")
36+
add(["employees.txt"], verbose)
37+
commit("Add Pam to employees.txt", verbose)
38+
39+
push("origin", "hiring", verbose)

0 commit comments

Comments
 (0)