CHAPTER 41: Selected contents, branches and recorded reversals

41a: Staging remembers the contents you selected
41b: A branch selects a recorded version of the report

HOW TO RUN
Open a terminal in the extracted companion folder, the folder containing
automation, sql and visual_labs. Run:

    python visual_labs/ch41/walkthrough.py

Use python3 or py instead of python if that is the command established in
Chapter 15. No extra Python package is needed. Run it only after predicting
the displayed states. The exact output is also in expected_output.txt.

When a lab imports the automation examples, its short Path/sys.path setup
locates those existing modules relative to this file. It changes where this
Python process looks for imports; it does not change your operating-system
configuration. Preserve the extracted folder structure.

REQUIREMENT AND SCOPE
Python's standard library and Git installed as explained in Chapter 41.
No online account, remote repository or network request is used. The helper
creates two temporary repositories with a fictional local identity. It never
initialises Git in your project, changes global settings or edits your files.

FOLLOW BEFORE YOU RUN
Draw three columns: working file, staging area, last commit. Start each at 20.
Write down the state after editing to 21, staging, editing again to 22 and
committing. Predict what running the file would print versus what the commit
contains. In the second independent example, trace the presence of the cost
line as the active branch changes.

PREDICT, RUN, COMPARE
The helper executes real Git operations in disposable folders and prints
stable business states instead of changing commit hashes. It reads the staged
file using git show :report.py and the committed file using
git show HEAD:report.py. These are inspection commands, not edits. The first
example then stages again to verify the confirmed count of 22 is committed.

ONE MORE INPUT TO REASON THROUGH
Starting with a committed 20 and a staged, working 21, what happens after
git restore --staged report.py? Which number does running the file display?

EXPLAINED ANSWER
The working file remains 21, the staged snapshot returns to committed 20, and
the last commit remains 20. Running the file still prints 21. This removes a
selection from the next commit; it does not discard the edit. Practise this
manually only in the disposable git_practice repository from the chapter.

ABOUT THE SMALL HARNESS
subprocess.run asks the operating system to run a command. Its cwd argument
names the disposable folder in which that command acts. check=True stops the
demo if a Git command fails. TemporaryDirectory removes the practice folders
after the block finishes. Captured command output lets the lab display the
meaningful states; the ordinary manual commands remain in the chapter.

EXPECTED OUTPUT (verified by execution)

41a: After staging 21, then editing the working file to 22
Working: Enquiries: 22
Staged: Enquiries: 21
Committed: Enquiries: 20
After commit: Enquiries: 21
After adding again: Enquiries: 22
41b: A separate clean branch example
On add-cost, cost line present: True
On main before merge, cost line present: False
On main after merge, cost line present: True
On main after revert, cost line present: False
Harbour Office daily report
Enquiries: 21
On unchanged add-cost branch, cost line present: True

All data in this lab are fictional teaching examples.
