-
Notifications
You must be signed in to change notification settings - Fork 25
Implement hands-on checkout commits #113
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import os | ||
|
|
||
| from exercise_utils.cli import run_command | ||
| from exercise_utils.gitmastery import create_start_tag | ||
| from exercise_utils.git import init, add, commit, tag | ||
| from pathlib import Path | ||
|
|
||
| __requires_git__ = True | ||
| __requires_github__ = False | ||
|
|
||
| def download(verbose: bool): | ||
| """ | ||
| hp-checkout-commits (T4L4) | ||
| - Creates a local repo 'things' with multiple commits and tags. | ||
| - Students can practice checking out commits by hash, tag, or HEAD~N references. | ||
| """ | ||
|
|
||
| target_dir = Path("things") | ||
|
|
||
| # Clean existing sandbox if re-downloading | ||
| if target_dir.exists(): | ||
| import shutil | ||
| shutil.rmtree(target_dir) | ||
|
Comment on lines
+18
to
+23
Member
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 already happens via the app: https://git-mastery.github.io/developers/docs/architecture/download-workflow/#hands-on-download So this check can be omitted |
||
|
|
||
| # Create sandbox folder | ||
| target_dir.mkdir() | ||
| os.chdir(target_dir) | ||
|
Comment on lines
+25
to
+27
Member
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. I think conventionally, |
||
|
|
||
| # Initialize git repo | ||
| init(verbose) | ||
|
|
||
| # Step 1: Add fruits.txt (first commit) | ||
| with open("fruits.txt", "w") as f: | ||
| f.write("apples\nbananas\ncherries\ndragon fruits\n") | ||
|
Comment on lines
+33
to
+34
Member
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. Please use the given |
||
| add(["fruits.txt"], verbose) | ||
| commit("Add fruits.txt", verbose) | ||
|
|
||
| # Step 2: Update fruits.txt and commit | ||
| with open("fruits.txt", "a") as f: | ||
| f.write("elderberries\nfigs\n") | ||
|
Comment on lines
+39
to
+40
Member
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. Please use the given |
||
| add(["fruits.txt"], verbose) | ||
| commit("Add elderberries and figs into fruits.txt", verbose) | ||
|
|
||
| # Step 3: Create colours.txt and shapes.txt, commit, tag 0.9 | ||
| with open("colours.txt", "w") as f: | ||
| f.write("a file for colours\n") | ||
| with open("shapes.txt", "w") as f: | ||
| f.write("a file for shapes\n") | ||
|
Comment on lines
+45
to
+48
Member
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. Use the given |
||
| add(["colours.txt", "shapes.txt"], verbose) | ||
| commit("Add colours.txt, shapes.txt", verbose) | ||
| tag("0.9", verbose) | ||
|
|
||
| # Step 4: Update fruits.txt again | ||
| with open("fruits.txt", "w") as f: | ||
| f.write("apples, apricots\nbananas\nblueberries\ncherries\ndragon fruits\nfigs\n") | ||
|
Comment on lines
+54
to
+55
Member
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. Use the given |
||
| add(["fruits.txt"], verbose) | ||
| commit("Update fruits list", verbose) | ||
|
|
||
| # Step 5: Update colours.txt and commit, tag 1.0 | ||
| with open("colours.txt", "a") as f: | ||
| f.write("blue\nred\nwhite\n") | ||
|
Comment on lines
+60
to
+61
Member
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. Use |
||
| add(["colours.txt"], verbose) | ||
| commit("colours.txt: Add some colours", verbose) | ||
| tag("1.0", verbose) | ||
|
|
||
| # Step 6: Update shapes.txt and commit | ||
| with open("shapes.txt", "a") as f: | ||
| f.write("circle\noval\nrectangle\nsquare\n") | ||
|
Comment on lines
+67
to
+68
Member
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. Use |
||
| add(["shapes.txt"], verbose) | ||
| commit("shapes.txt: Add some shapes", verbose) | ||
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.
You can remove this comment