From 0544860d02bc9fedfecf88dfed3528064aba51da Mon Sep 17 00:00:00 2001 From: desmondwong1215 Date: Sat, 8 Nov 2025 15:15:05 +0800 Subject: [PATCH 1/2] Implement hands on hp-reset-commits --- hands_on/reset_commits.py | 114 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 hands_on/reset_commits.py diff --git a/hands_on/reset_commits.py b/hands_on/reset_commits.py new file mode 100644 index 0000000..57b177b --- /dev/null +++ b/hands_on/reset_commits.py @@ -0,0 +1,114 @@ +import os + +from exercise_utils.file import append_to_file, create_or_update_file +from exercise_utils.git import add, commit, init, tag + +__requires_git__ = True +__requires_github__ = False + + +def download(verbose: bool): + os.makedirs("things") + os.chdir("things") + init(verbose) + + create_or_update_file( + "fruits.txt", + """ + apples + bananas + cherries + dragon fruits + """ + ) + add(["fruits.txt"], verbose) + commit("Add fruits.txt", verbose) + + append_to_file( + "fruits.txt", + """ + elderberries + figs + """) + add(["fruits.txt"], verbose) + commit("Add elderberries and figs into fruits.txt", verbose) + + create_or_update_file( + "colours.txt", + """ + a file for colours + """ + ) + create_or_update_file( + "shapes.txt", + """ + a file for shapes + """ + ) + add(["colours.txt", "shapes.txt"], verbose) + commit("Add colours.txt, shapes.txt", verbose) + tag("0.9", verbose) + + create_or_update_file( + "fruits.txt", + """ + apples, apricots + bananas + blueberries + cherries + dragon fruits + figs + """) + add(["fruits.txt"], verbose) + commit("Update fruits list", verbose) + + append_to_file( + "colours.txt", + """ + bad colour + """ + ) + add(["colours.txt"], verbose) + commit("Incorrectly update colours.txt", verbose) + + append_to_file( + "shapes.txt", + """ + bad shape + """ + ) + add(["shapes.txt"], verbose) + commit("Incorrectly update shapes.txt", verbose) + + append_to_file( + "fruits.txt", + """ + bad fruit + """ + ) + add(["fruits.txt"], verbose) + commit("Incorrectly update fruits.txt", verbose) + + create_or_update_file( + "incorrect.txt", + """ + bad line + """ + ) + add(["incorrect.txt"], verbose) + commit("Add incorrect.txt", verbose) + + append_to_file( + "colours.txt", + """ + another bad colour + """ + ) + add(["colours.txt"], verbose) + + append_to_file( + "shapes.txt", + """ + another bad shape + """ + ) \ No newline at end of file From 92e6bae3cac16e49becd0a68b9cc5e26d0de22d5 Mon Sep 17 00:00:00 2001 From: desmondwong1215 Date: Fri, 21 Nov 2025 00:17:48 +0800 Subject: [PATCH 2/2] Fix formatting issue --- hands_on/reset_commits.py | 34 +++++++++------------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/hands_on/reset_commits.py b/hands_on/reset_commits.py index 57b177b..f6fc753 100644 --- a/hands_on/reset_commits.py +++ b/hands_on/reset_commits.py @@ -35,15 +35,11 @@ def download(verbose: bool): create_or_update_file( "colours.txt", - """ - a file for colours - """ + "a file for colours\n" ) create_or_update_file( "shapes.txt", - """ - a file for shapes - """ + "a file for shapes\n" ) add(["colours.txt", "shapes.txt"], verbose) commit("Add colours.txt, shapes.txt", verbose) @@ -64,51 +60,39 @@ def download(verbose: bool): append_to_file( "colours.txt", - """ - bad colour - """ + "bad colour\n" ) add(["colours.txt"], verbose) commit("Incorrectly update colours.txt", verbose) append_to_file( "shapes.txt", - """ - bad shape - """ + "bad shape\n" ) add(["shapes.txt"], verbose) commit("Incorrectly update shapes.txt", verbose) append_to_file( "fruits.txt", - """ - bad fruit - """ + "bad fruit\n" ) add(["fruits.txt"], verbose) commit("Incorrectly update fruits.txt", verbose) create_or_update_file( "incorrect.txt", - """ - bad line - """ + "bad line\n" ) add(["incorrect.txt"], verbose) commit("Add incorrect.txt", verbose) append_to_file( "colours.txt", - """ - another bad colour - """ + "another bad colour\n" ) add(["colours.txt"], verbose) append_to_file( "shapes.txt", - """ - another bad shape - """ - ) \ No newline at end of file + "another bad shape\n" + )