-
Notifications
You must be signed in to change notification settings - Fork 25
Implement T8L3/glossary-branch-delete #251
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
Merged
jovnc
merged 9 commits into
git-mastery:main
from
jiaxinnns:feature/glossary-branch-delete
Feb 1, 2026
+161
−0
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4ff8fd8
Implement setup
jiaxinnns 93f9a81
Add verify logic
jiaxinnns d192eca
Change clone target
jiaxinnns d124d28
Implement tests
jiaxinnns 64fcf95
Address PR comments
jiaxinnns 8c9667e
Edit lesson link
jiaxinnns 21ddb28
Change fork repo call
jiaxinnns 5424b39
Add local branch
jiaxinnns 6617a46
Add test
jiaxinnns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "exercise_name": "glossary-branch-delete", | ||
| "tags": [ | ||
| "git-push" | ||
| ], | ||
| "requires_git": true, | ||
| "requires_github": true, | ||
| "base_files": {}, | ||
| "exercise_repo": { | ||
| "repo_type": "local", | ||
| "repo_name": "funny-glossary", | ||
| "repo_title": null, | ||
| "create_fork": null, | ||
| "init": false | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| https://git-mastery.org/lessons/remoteBranchDelete/exercise-glossary-branch-delete.html |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| from exercise_utils.git import checkout | ||
| from exercise_utils.github_cli import ( | ||
| clone_repo_with_gh, | ||
| delete_repo, | ||
| fork_repo, | ||
| get_github_username, | ||
| has_repo, | ||
| ) | ||
|
|
||
| REPO_OWNER = "git-mastery" | ||
| REPO_NAME = "samplerepo-funny-glossary" | ||
|
|
||
|
|
||
| def setup(verbose: bool = False): | ||
| username = get_github_username(verbose) | ||
| FORK_NAME = f"{username}-gitmastery-samplerepo-funny-glossary" | ||
|
|
||
| if has_repo(FORK_NAME, True, verbose): | ||
| delete_repo(FORK_NAME, verbose) | ||
|
|
||
| fork_repo(f"{REPO_OWNER}/{REPO_NAME}", FORK_NAME, verbose, False) | ||
|
|
||
| clone_repo_with_gh(f"https://github.com/{username}/{FORK_NAME}", verbose, ".") | ||
|
|
||
| # creates VWX branch locally, tracking remote branch | ||
| checkout("VWX", False, verbose) | ||
| checkout("main", False, verbose) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| from contextlib import contextmanager | ||
| from typing import Iterator, Tuple | ||
|
|
||
| from exercise_utils.test import ( | ||
| GitAutograderTest, | ||
| GitAutograderTestLoader, | ||
| assert_output, | ||
| ) | ||
| from git_autograder import GitAutograderStatus | ||
| from repo_smith.repo_smith import RepoSmith | ||
|
|
||
| from .verify import ( | ||
| VWX_BRANCH_EXISTS_LOCALLY, | ||
| VWX_BRANCH_EXISTS_REMOTELY, | ||
| verify, | ||
| ) | ||
|
|
||
| REPOSITORY_NAME = "glossary-branch-delete" | ||
|
|
||
| loader = GitAutograderTestLoader(REPOSITORY_NAME, verify) | ||
|
|
||
|
|
||
| @contextmanager | ||
| def base_setup() -> Iterator[Tuple[GitAutograderTest, RepoSmith]]: | ||
| with loader.start(include_remote_repo=True) as (test, rs, rs_remote): | ||
| remote_path = str(rs_remote.repo.git_dir) | ||
| rs.git.remote_add("origin", remote_path) | ||
|
|
||
| # doesnt create a branch on remote | ||
| rs_remote.git.commit(allow_empty=True, message="Initial commit") | ||
| rs_remote.git.checkout("TEST", branch=True) | ||
|
|
||
| # works | ||
| rs.git.checkout("VWX", branch=True) | ||
| rs.git.commit(allow_empty=True, message="Empty commit") | ||
| rs.git.push("origin", "VWX") | ||
|
|
||
| rs.git.checkout("main") | ||
|
|
||
| yield test, rs | ||
|
|
||
|
|
||
| def test_base(): | ||
| with base_setup() as (test, rs): | ||
| rs.git.push("origin", ":VWX") | ||
| rs.repo.delete_head("VWX", force=True) | ||
|
|
||
| output = test.run() | ||
| assert_output(output, GitAutograderStatus.SUCCESSFUL) | ||
|
|
||
|
|
||
| def test_vwx_exists_remotely(): | ||
| with base_setup() as (test, rs): | ||
| output = test.run() | ||
| assert_output( | ||
| output, | ||
| GitAutograderStatus.UNSUCCESSFUL, | ||
| [VWX_BRANCH_EXISTS_REMOTELY], | ||
| ) | ||
|
|
||
|
|
||
| def test_vwx_exists_locally(): | ||
| with base_setup() as (test, rs): | ||
| rs.git.checkout("VWX") | ||
|
|
||
| output = test.run() | ||
| assert_output( | ||
| output, | ||
| GitAutograderStatus.UNSUCCESSFUL, | ||
| [VWX_BRANCH_EXISTS_LOCALLY], | ||
| ) | ||
|
|
||
|
|
||
| def test_vwx_exists_both(): | ||
| with base_setup() as (test, rs): | ||
| rs.git.checkout("VWX") | ||
|
|
||
| output = test.run() | ||
| assert_output( | ||
| output, | ||
| GitAutograderStatus.UNSUCCESSFUL, | ||
| [VWX_BRANCH_EXISTS_LOCALLY, VWX_BRANCH_EXISTS_REMOTELY], | ||
| ) |
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from typing import List | ||
| from git_autograder import ( | ||
| GitAutograderOutput, | ||
| GitAutograderExercise, | ||
| GitAutograderStatus, | ||
| ) | ||
|
|
||
| VWX_BRANCH_EXISTS_REMOTELY = ( | ||
| "Branch 'VWX' still exists on the remote! Remember to delete it from the remote." | ||
| ) | ||
|
|
||
| VWX_BRANCH_EXISTS_LOCALLY = "Branch 'VWX' still exists locally! Remember to delete it from your local repository." | ||
|
|
||
|
|
||
| def verify(exercise: GitAutograderExercise) -> GitAutograderOutput: | ||
| comments: List[str] = [] | ||
|
|
||
| local_branches = [h.name for h in exercise.repo.repo.heads] | ||
| if "VWX" in local_branches: | ||
| comments.append(VWX_BRANCH_EXISTS_LOCALLY) | ||
|
|
||
| try: | ||
| exercise.repo.repo.refs["origin/VWX"] | ||
| comments.append(VWX_BRANCH_EXISTS_REMOTELY) | ||
| except (IndexError, KeyError): | ||
| pass # Branch doesn't exist on remote, which is what we want | ||
|
|
||
| if comments: | ||
| raise exercise.wrong_answer(comments) | ||
|
|
||
| return exercise.to_output( | ||
| ["Great job deleting the VWX branch!"], | ||
| GitAutograderStatus.SUCCESSFUL, | ||
| ) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Uh oh!
There was an error while loading. Please reload this page.
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.
Currently,
download.pydoesn't fetch branchVWXas well, so local repository would only havemainbranch. If we wantVWXin local repository as well, we can add a step to fetch it from remote as well.While the exercise instruction does state to delete both local and remote
VWXbranches, I think it may not be necessary to add in this logic since the purpose of the exercise is to test students interacting with remote repositories.@damithc Do you think we should remove deleting local branch
VWXor stick to the current exercise that requires students to delete both local and remote branches?