-
Notifications
You must be signed in to change notification settings - Fork 25
Implement exercise T6L2/ff-undo #101
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
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
87d6f65
Add the ff-undo exercise
vanphuc1201 966108e
Add yml file for test_verify
vanphuc1201 dace21b
Add README file and also fix the verify to check the mistake
vanphuc1201 7abe28c
Change the notification for not undo merge
vanphuc1201 fe2f02d
Final ver
vanphuc1201 f627ddc
Use the git cli command instead of run command
vanphuc1201 66b2131
Fix the test cases
vanphuc1201 5504d3f
[ff-unfo] Update README
jovnc f225878
[ff-unfo] Run ruff format and clean up download.py
jovnc 139a3c2
[ff-undo] Update verify to include initial commit
jovnc 03f4a4a
[ff-undo] Clean up code for verify.py
jovnc d2a7aa3
[ff-undo] Remove .DS_Store file
jovnc 09d7cd3
[ff-undo] Update error messages
jovnc 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,18 @@ | ||
| { | ||
| "exercise_name": "ff-undo", | ||
| "tags": [ | ||
| "git-branch", | ||
| "git-merge", | ||
| "git-reset" | ||
| ], | ||
| "requires_git": true, | ||
| "requires_github": false, | ||
| "base_files": {}, | ||
| "exercise_repo": { | ||
| "repo_type": "local", | ||
| "repo_name": "play-characters", | ||
| "repo_title": null, | ||
| "create_fork": null, | ||
| "init": true | ||
| } | ||
| } |
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 @@ | ||
| See https://git-mastery.github.io/lessons/merge/exercise-ff-undo.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,62 @@ | ||
| from exercise_utils.git import ( | ||
| add, | ||
| commit, | ||
| checkout, | ||
| merge, | ||
| ) | ||
| from exercise_utils.file import ( | ||
| create_or_update_file, | ||
| append_to_file, | ||
| ) | ||
|
|
||
|
|
||
| def setup(verbose: bool = False): | ||
| create_or_update_file( | ||
| "rick.txt", | ||
| """ | ||
| Hero | ||
| """, | ||
| ) | ||
| add(["."], verbose) | ||
| commit("Add Rick", verbose) | ||
|
|
||
| create_or_update_file( | ||
| "morty.txt", | ||
| """ | ||
| Boy | ||
| """, | ||
| ) | ||
| add(["."], verbose) | ||
| commit("Add Morty", verbose) | ||
|
|
||
| checkout("others", True, verbose) | ||
|
|
||
| create_or_update_file( | ||
| "birdperson.txt", | ||
| """ | ||
| No job | ||
| """, | ||
| ) | ||
| add(["."], verbose) | ||
| commit("Add Birdperson", verbose) | ||
|
|
||
| append_to_file( | ||
| "birdperson.txt", | ||
| """ | ||
| Cyborg | ||
| """, | ||
| ) | ||
| add(["."], verbose) | ||
| commit("Add Cyborg to birdperson.txt", verbose) | ||
|
|
||
| create_or_update_file( | ||
| "tammy.txt", | ||
| """ | ||
| Spy | ||
| """, | ||
| ) | ||
| add(["."], verbose) | ||
| commit("Add Tammy", verbose) | ||
|
|
||
| checkout("main", False, verbose) | ||
| merge("others", True, verbose) |
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,22 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Set initial state | ||
| id: start | ||
| - type: commit | ||
| message: "Add Rick" | ||
| - type: commit | ||
| message: "Add Morty" | ||
| - type: branch | ||
| branch-name: others | ||
| - type: checkout | ||
| branch-name: others | ||
| - type: commit | ||
| message: "Add Birdperson" | ||
| - type: commit | ||
| message: "Add Cyborg to birdperson.txt" | ||
| - type: commit | ||
| message: "Add Tammy" | ||
| - type: checkout | ||
| branch-name: main |
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,10 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Set initial state | ||
| id: start | ||
| - type: commit | ||
| message: "Add Rick" | ||
| - type: commit | ||
| message: "Add Morty" |
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,18 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Set initial state | ||
| id: start | ||
| - type: commit | ||
| message: "Add Morty" | ||
| - type: branch | ||
| branch-name: others | ||
| - type: checkout | ||
| branch-name: others | ||
| - type: commit | ||
| message: "Add Birdperson" | ||
| - type: commit | ||
| message: "Add Cyborg to birdperson.txt" | ||
| - type: commit | ||
| message: "Add Tammy" |
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,26 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Set initial state | ||
| id: start | ||
| - type: commit | ||
| message: "Add Rick" | ||
| - type: commit | ||
| message: "Add Morty" | ||
| - type: branch | ||
| branch-name: others | ||
| - type: checkout | ||
| branch-name: others | ||
| - type: commit | ||
| message: "Add Birdperson" | ||
| - type: commit | ||
| message: "Add Cyborg to birdperson.txt" | ||
| - type: commit | ||
| message: "Add Tammy" | ||
| - type: checkout | ||
| branch-name: main | ||
| - type: merge | ||
| branch-name: others | ||
| no-ff: false | ||
| message: "Introduce others" |
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,18 @@ | ||
| initialization: | ||
| steps: | ||
| - type: commit | ||
| empty: true | ||
| message: Set initial state | ||
| id: start | ||
| - type: commit | ||
| message: "Add Rick" | ||
| - type: commit | ||
| message: "Add Morty" | ||
| - type: branch | ||
| branch-name: others | ||
| - type: checkout | ||
| branch-name: others | ||
| - type: commit | ||
| message: "Add Birdperson" | ||
| - type: commit | ||
| message: "Add Tammy" |
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,42 @@ | ||
| from git_autograder import GitAutograderTestLoader, assert_output | ||
| from git_autograder.status import GitAutograderStatus | ||
| from ..verify import ( | ||
| MERGE_NOT_UNDONE, | ||
| MAIN_COMMITS_INCORRECT, | ||
| OTHERS_COMMITS_INCORRECT, | ||
| OTHERS_BRANCH_MISSING, | ||
| verify, | ||
| ) | ||
|
|
||
| REPOSITORY_NAME = "ff-undo" | ||
|
|
||
| loader = GitAutograderTestLoader(__file__, REPOSITORY_NAME, verify) | ||
|
|
||
|
|
||
| def test_correct_solution(): | ||
| with loader.load("specs/base.yml") as output: | ||
| assert_output(output, GitAutograderStatus.SUCCESSFUL) | ||
|
|
||
|
|
||
| def test_merge_not_undone(): | ||
| with loader.load("specs/merge_not_undone.yml") as output: | ||
| assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [MERGE_NOT_UNDONE]) | ||
|
|
||
|
|
||
| def test_branch_missing(): | ||
| with loader.load("specs/branch_missing.yml") as output: | ||
| assert_output(output, GitAutograderStatus.UNSUCCESSFUL, [OTHERS_BRANCH_MISSING]) | ||
|
|
||
|
|
||
| def test_main_commits_incorrect(): | ||
| with loader.load("specs/main_commits_incorrect.yml") as output: | ||
| assert_output( | ||
| output, GitAutograderStatus.UNSUCCESSFUL, [MAIN_COMMITS_INCORRECT] | ||
| ) | ||
|
|
||
|
|
||
| def test_others_commits_incorrect(): | ||
| with loader.load("specs/others_commits_incorrect.yml") as output: | ||
| assert_output( | ||
| output, GitAutograderStatus.UNSUCCESSFUL, [OTHERS_COMMITS_INCORRECT] | ||
| ) |
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,52 @@ | ||
| from git_autograder import ( | ||
| GitAutograderOutput, | ||
| GitAutograderExercise, | ||
| GitAutograderStatus, | ||
| ) | ||
|
|
||
| ADD_RICK = "Add Rick" | ||
| ADD_MORTY = "Add Morty" | ||
| ADD_BIRDPERSON = "Add Birdperson" | ||
| ADD_CYBORG = "Add Cyborg to birdperson.txt" | ||
| ADD_TAMMY = "Add Tammy" | ||
|
|
||
| MERGE_NOT_UNDONE = "The merge has not been undone properly." | ||
| MAIN_COMMITS_INCORRECT = "The main branch does not contain the expected commits." | ||
| OTHERS_COMMITS_INCORRECT = "The others branch does not contain the expected commits." | ||
| OTHERS_BRANCH_MISSING = "Missing branch 'others'." | ||
|
|
||
|
|
||
| def verify(exercise: GitAutograderExercise) -> GitAutograderOutput: | ||
| main_branch = exercise.repo.branches.branch("main") | ||
| others_branch = exercise.repo.branches.branch_or_none("others") | ||
|
|
||
| if others_branch is None: | ||
| raise exercise.wrong_answer([OTHERS_BRANCH_MISSING]) | ||
|
|
||
| # Verify commits in main branch | ||
| commit_messages_in_main = [c.commit.message.strip() for c in main_branch.commits] | ||
| if any( | ||
| msg in commit_messages_in_main | ||
| for msg in [ADD_BIRDPERSON, ADD_CYBORG, ADD_TAMMY] | ||
| ): | ||
| raise exercise.wrong_answer([MERGE_NOT_UNDONE]) | ||
|
|
||
| if len(commit_messages_in_main) != 3 or not all( | ||
| msg in commit_messages_in_main for msg in [ADD_RICK, ADD_MORTY] | ||
| ): | ||
| raise exercise.wrong_answer([MAIN_COMMITS_INCORRECT]) | ||
|
|
||
| # Verify commits in others branch | ||
| commit_messages_in_others = [ | ||
| c.commit.message.strip() for c in others_branch.commits | ||
| ] | ||
| if len(commit_messages_in_others) != 6 or not all( | ||
| msg in commit_messages_in_others | ||
| for msg in [ADD_BIRDPERSON, ADD_CYBORG, ADD_TAMMY, ADD_RICK, ADD_MORTY] | ||
| ): | ||
| raise exercise.wrong_answer([OTHERS_COMMITS_INCORRECT]) | ||
|
|
||
| return exercise.to_output( | ||
| ["You have successfully undone the merge of branch 'others'."], | ||
| 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.