From 6696c83cc75f615a95f42b47aaee19772a3f6dbf Mon Sep 17 00:00:00 2001 From: YuLetian Date: Tue, 4 Nov 2025 20:26:19 +0800 Subject: [PATCH 1/4] Add and update fruit.txt --- hands_on/diff_changes.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 hands_on/diff_changes.py diff --git a/hands_on/diff_changes.py b/hands_on/diff_changes.py new file mode 100644 index 0000000..2eb3b89 --- /dev/null +++ b/hands_on/diff_changes.py @@ -0,0 +1,36 @@ +import os + +from exercise_utils.cli import run_command +from exercise_utils.gitmastery import create_start_tag +from exercise_utils.git import add, init, commit +from exercise_utils.file import create_or_update_file, append_to_file + +__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 to fruits.txt", verbose) + + From d65b9349540bfba2d70369cd29f59bd66178ff3d Mon Sep 17 00:00:00 2001 From: YuLetian Date: Tue, 4 Nov 2025 20:47:22 +0800 Subject: [PATCH 2/4] Update fruit, color and shape.txt --- hands_on/diff_changes.py | 49 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/hands_on/diff_changes.py b/hands_on/diff_changes.py index 2eb3b89..8933598 100644 --- a/hands_on/diff_changes.py +++ b/hands_on/diff_changes.py @@ -2,7 +2,7 @@ from exercise_utils.cli import run_command from exercise_utils.gitmastery import create_start_tag -from exercise_utils.git import add, init, commit +from exercise_utils.git import add, init, commit, tag from exercise_utils.file import create_or_update_file, append_to_file __requires_git__ = True @@ -33,4 +33,49 @@ def download(verbose: bool): add(["fruits.txt"], verbose) commit("Add elderberries and figs to 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("v0.9", verbose) + + append_to_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", + """ + blue + red + white + """ + ) + add(["colours.txt"], verbose) + commit("colours.txt: Add some colours", verbose) + + append_to_file("shapes.txt", + """ + circle + oval + rectangle + square + """ + ) + add(["shapes.txt"], verbose) + commit("shapes.txt: Add some shapes", verbose) From 13c71b44e2b919237b6efc91e8c3ef838be24533 Mon Sep 17 00:00:00 2001 From: YuLetian Date: Tue, 4 Nov 2025 21:01:51 +0800 Subject: [PATCH 3/4] Remove deprecated import --- hands_on/diff_changes.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hands_on/diff_changes.py b/hands_on/diff_changes.py index 8933598..2c8ecf7 100644 --- a/hands_on/diff_changes.py +++ b/hands_on/diff_changes.py @@ -1,9 +1,7 @@ import os -from exercise_utils.cli import run_command -from exercise_utils.gitmastery import create_start_tag -from exercise_utils.git import add, init, commit, tag from exercise_utils.file import create_or_update_file, append_to_file +from exercise_utils.git import add, init, commit, tag __requires_git__ = True __requires_github__ = False From 777d4cfce4160b153f0446a5c055a8548734c496 Mon Sep 17 00:00:00 2001 From: YuLetian Date: Tue, 4 Nov 2025 21:12:25 +0800 Subject: [PATCH 4/4] Fix new line symbol --- hands_on/diff_changes.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hands_on/diff_changes.py b/hands_on/diff_changes.py index 2c8ecf7..e0efbe4 100644 --- a/hands_on/diff_changes.py +++ b/hands_on/diff_changes.py @@ -33,18 +33,19 @@ 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) tag("v0.9", verbose) - append_to_file("fruits.txt", + # Replace the whole contents of fruits.txt + create_or_update_file("fruits.txt", """ apples, apricots bananas @@ -58,11 +59,11 @@ def download(verbose: bool): commit("Update fruits list", verbose) append_to_file("colours.txt", - """ - blue - red - white - """ + """ + blue + red + white + """ ) add(["colours.txt"], verbose) commit("colours.txt: Add some colours", verbose)