From 4ac2426b850e98b9f2d263dc49999c7dc1878b45 Mon Sep 17 00:00:00 2001 From: thejesh23 <35212698+thejesh23@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:47:33 -0800 Subject: [PATCH 1/7] Bots: accept a first commit carried into an Exercise 2 pull request A tester's Exercise 2 PR (#47) carried their unmerged first-commit file, because the branch started from the fork's main. The first-commit bot told them to undo their exercise files, and the Exercise 2 bot would have rejected the PR. Now the first-commit bot stays quiet on Exercise 2 PRs, and the Exercise 2 bot checks the carried file and explains it. Co-Authored-By: Claude Fable 5.2 --- tests/test_check_exercise_2.py | 52 ++++++++++++++++++++++++++++++++ tests/test_check_first_commit.py | 32 ++++++++++++++++++++ tools/check_exercise_2.py | 36 ++++++++++++++++++++-- tools/check_first_commit.py | 12 ++++++-- 4 files changed, 128 insertions(+), 4 deletions(-) diff --git a/tests/test_check_exercise_2.py b/tests/test_check_exercise_2.py index e90f055..4bae335 100644 --- a/tests/test_check_exercise_2.py +++ b/tests/test_check_exercise_2.py @@ -171,3 +171,55 @@ def git(*args): code = main(["--login", "ada", "--base", base, "--head", "HEAD", "--tests", "success"]) assert code == NOT_A_LEARNER_PR assert capsys.readouterr().out == "" + + +def _repo(tmp_path): + def git(*args): + return subprocess.run(["git", *args], cwd=tmp_path, check=True, capture_output=True, text=True).stdout.strip() + + git("init", "-q", "-b", "main") + git("config", "user.email", "t@example.com") + git("config", "user.name", "t") + for folder in ("practice/greetings", "practice/tests", "first-commits"): + (tmp_path / folder).mkdir(parents=True) + (tmp_path / "practice/README.md").write_text("hi\n") + git("add", ".") + git("commit", "-qm", "base") + return git + + +FIRST_COMMIT = 'name = "Ada"\ngithub = "ada"\nmessage = "Hello"\n' + + +def test_first_commit_carried_along_is_accepted_and_explained(tmp_path, monkeypatch): + """PR #47: the first PR isn't merged yet, and the Exercise 2 branch started from the fork's main.""" + git = _repo(tmp_path) + base = git("rev-parse", "HEAD") + (tmp_path / "first-commits/ada.py").write_text(FIRST_COMMIT) + git("add", ".") + git("commit", "-qm", "first commit, on the fork's main") + (tmp_path / "practice/greetings/ada.py").write_text(GREETING) + (tmp_path / "practice/tests/test_ada.py").write_text(TEST.replace("thejesh23", "ada")) + git("add", ".") + git("commit", "-qm", "exercise 2") + monkeypatch.chdir(tmp_path) + + result = validate("ada", base, git("rev-parse", "HEAD")) + assert result.ok, result.errors + comment = format_comment(result, "ada", "success", "https://run") + assert "maintainer will review" in comment + assert "first-commits/ada.py" in comment and "upstream/main" in comment + + # The carried file gets the first-commit checks too. + (tmp_path / "first-commits/ada.py").write_text('name = "Ada"\ngithub = "ada"\nmessage = "Hello\n') + git("commit", "-qam", "break the quote") + errors = validate("ada", base, git("rev-parse", "HEAD")).errors + assert any("first-commit file" in e and "valid Python" in e for e in errors), errors + + +def test_someone_elses_first_commit_file_is_still_rejected(): + changes = [("A", "practice/greetings/ada.py"), ("A", "practice/tests/test_ada.py"), ("A", "first-commits/bob.py")] + result = check_changes(changes, "ada") + assert any("first-commits/bob.py" in e for e in result.errors) + deleted = [("A", "practice/greetings/ada.py"), ("A", "practice/tests/test_ada.py"), ("D", "first-commits/ada.py")] + assert any("first-commits/ada.py" in e for e in check_changes(deleted, "ada").errors) diff --git a/tests/test_check_first_commit.py b/tests/test_check_first_commit.py index 640ed62..e812e49 100644 --- a/tests/test_check_first_commit.py +++ b/tests/test_check_first_commit.py @@ -112,3 +112,35 @@ def test_is_learner_pr(paths, expected): from check_first_commit import is_learner_pr assert is_learner_pr(paths) is expected + + +def test_main_is_silent_on_an_exercise_2_pr_that_carries_the_first_commit(tmp_path, monkeypatch, capsys): + """PR #47: the Exercise 2 bot reviews it, so this bot must not ask to undo the exercise files.""" + from check_first_commit import NOT_A_LEARNER_PR, main + + def git(*args): + return subprocess.run(["git", *args], cwd=tmp_path, check=True, capture_output=True, text=True).stdout.strip() + + git("init", "-q", "-b", "main") + git("config", "user.email", "t@example.com") + git("config", "user.name", "t") + (tmp_path / "README.md").write_text("hi\n") + git("add", ".") + git("commit", "-qm", "base") + base = git("rev-parse", "HEAD") + for folder in ("first-commits", "practice/greetings", "practice/tests"): + (tmp_path / folder).mkdir(parents=True) + (tmp_path / "first-commits/ada.py").write_text(GOOD) + git("add", ".") + git("commit", "-qm", "first commit") + first = git("rev-parse", "HEAD") + (tmp_path / "practice/greetings/ada.py").write_text("def greet(name: str) -> str:\n return name\n") + (tmp_path / "practice/tests/test_ada.py").write_text("from greetings.ada import greet\n") + git("add", ".") + git("commit", "-qm", "exercise 2") + monkeypatch.chdir(tmp_path) + + assert main(["--login", "ada", "--base", base, "--head", first]) == 0 # the first PR itself is still checked + capsys.readouterr() + assert main(["--login", "ada", "--base", base, "--head", git("rev-parse", "HEAD")]) == NOT_A_LEARNER_PR + assert capsys.readouterr().out == "" diff --git a/tools/check_exercise_2.py b/tools/check_exercise_2.py index 87b9822..e19a2ef 100644 --- a/tools/check_exercise_2.py +++ b/tools/check_exercise_2.py @@ -10,6 +10,10 @@ must not import anything or call dangerous built-ins. The tests themselves run in the read-only "Exercise 2 tests" workflow; its result is passed in here. +One more file is accepted: the learner's own ``first-commits/.py``. A +branch made from the fork's ``main`` carries it along until the learner's +first pull request is merged. It gets the same checks as in that pull request. + Usage (in CI):: python tools/check_exercise_2.py --login LOGIN --base BASE --head HEAD --tests success --run-url URL @@ -29,7 +33,8 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) -from check_first_commit import LOGIN_RE, Result, _git # noqa: E402 +from check_first_commit import FOLDER as FIRST_COMMITS # noqa: E402 +from check_first_commit import LOGIN_RE, Result, _git, check_source # noqa: E402 MAX_BYTES = 3_000 BANNED_NAMES = { @@ -84,6 +89,19 @@ def expected_paths(login: str) -> tuple[str, str]: return f"practice/greetings/{mod}.py", f"practice/tests/test_{mod}.py" +def carried_first_commit(changes: list[tuple[str, str]], login: str) -> str | None: + """The learner's own first-commit file, if this PR adds or edits it too. + + Lesson 02's commit sits on the fork's ``main``. Until that pull request is + merged, a branch made from the fork's ``main`` brings the file along. + """ + mine = f"{FIRST_COMMITS}/{login}.py" + for status, path in changes: + if path == mine and status in ("A", "M"): + return path + return None + + def check_changes(changes: list[tuple[str, str]], login: str, existing: set[str] | None = None) -> Result: """Check which files the PR touches. @@ -96,7 +114,15 @@ def check_changes(changes: list[tuple[str, str]], login: str, existing: set[str] wanted = {greet_path, test_path} touched = {path for _, path in changes} - others = sorted(touched - wanted) + carried = carried_first_commit(changes, login) + if carried: + result.notes.append( + f"This pull request also carries your first commit (`{carried}`), because your first pull " + "request isn't merged yet and this branch started from your fork's `main`. That's fine here. " + "Next time, start the branch from the original repo, as Lesson 05 shows: " + "`git switch -c my-branch upstream/main`." + ) + others = sorted(touched - wanted - {carried}) if others: listed = ", ".join(f"`{p}`" for p in others[:5]) result.errors.append( @@ -211,11 +237,13 @@ def format_comment(result: Result, login: str, tests: str, run_url: str) -> str: "scroll to the red โœ˜ step and read the last lines of its output.", }.get(tests, f"โš ๏ธ The test run finished with `{tests}`. [Open it]({run_url}) to see why.") if result.ok and tests == "success": + notes = "".join(f"\n\n{note}" for note in result.notes) return ( f"๐ŸŽ‰ Nice work, @{login}! {tests_line} A maintainer will review your pull " "request and merge it soon.\n\n" "You just did what real Python contributors do every day: write code, test it, " "pass CI and ask for review. Next up: Lesson 06, the house rules every project has." + f"{notes}" ) parts = [f"Thanks, @{login}! Not quite there yet:\n", tests_line] if result.errors: @@ -243,6 +271,10 @@ def validate(login: str, base: str, head: str) -> Result: result = check_changes(changes, login, existing) # type: ignore[arg-type] if not result.ok: return result + carried = carried_first_commit(changes, login) # type: ignore[arg-type] + if carried: + problems = check_source(_git("show", f"{head}:{carried}"), login).errors + result.errors.extend(f"Your first-commit file (`{carried}`): {problem}" for problem in problems) result.errors.extend(check_greeting(_git("show", f"{head}:{greet_path}")).errors) result.errors.extend(check_test(_git("show", f"{head}:{test_path}"), login).errors) return result diff --git a/tools/check_first_commit.py b/tools/check_first_commit.py index 8f9aa05..7a69720 100644 --- a/tools/check_first_commit.py +++ b/tools/check_first_commit.py @@ -13,7 +13,9 @@ Prints a Markdown comment for the PR and exits 0 if the PR is valid, 1 if not. Exits 3, printing nothing, when the PR doesn't add or change any ``first-commits/.py`` (for example a maintainer editing the folder's -README), so the bot stays quiet. +README), so the bot stays quiet. It also stays quiet on an Exercise 2 pull +request that carries the learner's first commit along (their first pull +request isn't merged yet): ``check_exercise_2.py`` reviews that one. """ from __future__ import annotations @@ -43,6 +45,7 @@ def is_learner_pr(paths: list[str]) -> bool: @dataclass class Result: errors: list[str] = field(default_factory=list) + notes: list[str] = field(default_factory=list) # said in the comment, but not a problem @property def ok(self) -> bool: @@ -201,8 +204,13 @@ def main(argv: list[str] | None = None) -> int: parser.add_argument("--base", required=True) parser.add_argument("--head", required=True) args = parser.parse_args(argv) - if not is_learner_pr(_git("diff", "--no-renames", "--name-only", f"{args.base}...{args.head}").splitlines()): + paths = _git("diff", "--no-renames", "--name-only", f"{args.base}...{args.head}").splitlines() + if not is_learner_pr(paths): return NOT_A_LEARNER_PR + from check_exercise_2 import is_learner_pr as is_exercise_2_pr # imported here: that module imports this one + + if is_exercise_2_pr(paths): + return NOT_A_LEARNER_PR # an Exercise 2 PR carrying the first commit: the Exercise 2 bot reviews it result = validate(args.login, args.base, args.head) print(format_comment(result, args.login)) return 0 if result.ok else 1 From 412980fd2cef689da6fbe6e74b45754862ef412b Mon Sep 17 00:00:00 2001 From: thejesh23 <35212698+thejesh23@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:48:30 -0800 Subject: [PATCH 2/7] Lesson 03: fetch from upstream instead of pulling A learner's main holds their first commit until it is merged. Once upstream has moved, git pull upstream main stops with 'Need to specify how to reconcile divergent branches'. Co-Authored-By: Claude Fable 5.2 --- lessons/03-set-up-your-machine/README.md | 11 ++++++++--- lessons/03-set-up-your-machine/exercise.md | 2 +- lessons/03-set-up-your-machine/script.md | 6 +++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lessons/03-set-up-your-machine/README.md b/lessons/03-set-up-your-machine/README.md index c125f92..912b961 100644 --- a/lessons/03-set-up-your-machine/README.md +++ b/lessons/03-set-up-your-machine/README.md @@ -114,14 +114,19 @@ gh adds `upstream` for you because it knows your repo is a fork. ## Step 6: Get the latest changes, then run the doctor -Other learners' commits have landed since you forked. Bring your copy up to -date, then run the course's checker: +Other learners' commits have landed since you forked. Download them, then +run the course's checker: ```bash norun -git pull upstream main +git fetch upstream python3 tools/doctor.py ``` +`git fetch` only downloads: it changes none of your files. (Why not +`git pull`? Your `main` holds your first commit, which may not be merged +yet, and git refuses to pull when both sides have new commits. In Lesson 05 +you start a branch from what you just fetched.) + Each line should be a green โœ”: ```text diff --git a/lessons/03-set-up-your-machine/exercise.md b/lessons/03-set-up-your-machine/exercise.md index 14ab38a..d92e8f0 100644 --- a/lessons/03-set-up-your-machine/exercise.md +++ b/lessons/03-set-up-your-machine/exercise.md @@ -5,7 +5,7 @@ - [ ] Set `user.name`, `user.email` and `init.defaultBranch` with `git config --global` - [ ] `gh auth login` - [ ] `gh repo clone YOUR-USERNAME/first-python-contribution` and `cd` into it -- [ ] `git pull upstream main` +- [ ] `git fetch upstream` - [ ] `python3 tools/doctor.py` shows only green โœ” **Stuck on a red โœ˜?** The message says what to fix. If it still fails, diff --git a/lessons/03-set-up-your-machine/script.md b/lessons/03-set-up-your-machine/script.md index 79bc927..63a3689 100644 --- a/lessons/03-set-up-your-machine/script.md +++ b/lessons/03-set-up-your-machine/script.md @@ -177,7 +177,7 @@ visual: terminal focus: 1 | 2 | 3-10 | 12 code: ``` -$ git pull upstream main +$ git fetch upstream $ python3 tools/doctor.py โœ” Python 3.13.1 โœ” venv module available @@ -191,8 +191,8 @@ $ python3 tools/doctor.py All set. You're ready for Lesson 04. ``` -> Last step. Other learners' commits have landed since you forked. So pull -> from upstream, to bring your copy up to date. +> Last step. Other learners' commits have landed since you forked. So fetch +> from upstream. That downloads them, and changes none of your files. > Then run the course's checker. Python three, tools, slash, doctor > {.py|dot p y}. From fe4102f73c8beffadf4f2ba4e3a8476059504ae3 Mon Sep 17 00:00:00 2001 From: thejesh23 <35212698+thejesh23@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:48:30 -0800 Subject: [PATCH 3/7] Lesson 05: start the branch from upstream/main A branch made from the fork's main carries the unmerged first commit into the Exercise 2 pull request (seen in #47). Co-Authored-By: Claude Fable 5.2 --- lessons/05-second-pr-from-terminal/README.md | 23 +++++++++----- .../05-second-pr-from-terminal/exercise.md | 4 +-- lessons/05-second-pr-from-terminal/script.md | 31 ++++++++++--------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/lessons/05-second-pr-from-terminal/README.md b/lessons/05-second-pr-from-terminal/README.md index 2b443a3..7ae1e47 100644 --- a/lessons/05-second-pr-from-terminal/README.md +++ b/lessons/05-second-pr-from-terminal/README.md @@ -25,12 +25,12 @@ if you get it wrong.) ```bash norun cd first-python-contribution -git switch main -git pull upstream main +git fetch upstream ``` (Commands in this lesson are marked as not run in CI because they need your -fork.) Always start new work from an up-to-date `main`. +fork.) `git fetch` downloads the original repo's newest commits without +changing your files. You start your branch from them in Step 3. ## Step 2: Make a virtual environment @@ -57,10 +57,14 @@ never commits it. ## Step 3: Make a branch ```bash norun -git switch -c exercise-2 +git switch -c exercise-2 upstream/main ``` -Never work on `main` directly. One branch per pull request. +`upstream/main` is the original repo's newest commit, as you just fetched +it. **Always start new work from there**, not from your own `main`: your +`main` still holds your first commit from Lesson 02, which may not be merged +yet, and it would come along into this pull request. One branch per pull +request, one change per branch. Never work on `main` directly. ## Step 4: Write the test first @@ -155,8 +159,8 @@ git commit -m "Add exercise 2 greeting for ada-lovelace" ``` `git status` should show only your two new files. Add exactly those. (If -you see `.venv/` listed, your `.gitignore` is missing: run -`git pull upstream main` again.) +you see `.venv/` listed, your `.gitignore` is missing: check that you made +the branch from `upstream/main` in Step 3.) ## Step 8: Push your branch to your fork @@ -240,4 +244,9 @@ git branch -d exercise-2 `main` now includes your merged work, so the `exercise-2` branch can go. +If `git pull` says you have **divergent branches**, your Lesson 02 pull +request isn't merged yet. Leave `main` as it is and try again after the +merge. [Troubleshooting, section 8](../A-troubleshooting/#8-your-fork-is-out-of-date) +explains why. + Next: [Lesson 06: house rules](../06-house-rules/), the rules every project expects you to read first. diff --git a/lessons/05-second-pr-from-terminal/exercise.md b/lessons/05-second-pr-from-terminal/exercise.md index 2915c5a..984562e 100644 --- a/lessons/05-second-pr-from-terminal/exercise.md +++ b/lessons/05-second-pr-from-terminal/exercise.md @@ -1,8 +1,8 @@ # Exercise 05: A function, a test, a green CI -- [ ] `git switch main` and `git pull upstream main` +- [ ] `git fetch upstream` - [ ] Create and activate `.venv`, then `python -m pip install pytest ruff` -- [ ] `git switch -c exercise-2` +- [ ] `git switch -c exercise-2 upstream/main` - [ ] Write `practice/tests/test_YOUR_NAME.py` and watch it fail - [ ] Write `practice/greetings/YOUR_NAME.py` and watch it pass - [ ] `ruff format practice` and `ruff check practice` are clean diff --git a/lessons/05-second-pr-from-terminal/script.md b/lessons/05-second-pr-from-terminal/script.md index c7f25c9..2a3ba80 100644 --- a/lessons/05-second-pr-from-terminal/script.md +++ b/lessons/05-second-pr-from-terminal/script.md @@ -61,24 +61,20 @@ bullets: ## Scene 4: Start from the latest upstream visual: terminal -focus: 1 | 2 | 3 +focus: 1 | 2 notes: - Go into your copy of the course repo -- Always start new work from `main` -- `upstream` is the original repo. This gets its newest commits. +- `upstream` is the original repo. This downloads its newest commits. code: ``` $ cd first-python-contribution -$ git switch main -$ git pull upstream main +$ git fetch upstream ``` > Step one. Open your terminal, and go into the course folder. -> Switch to main. - -> Then pull from upstream. Now your main is up to date. Always start new work -> from an up to date main. +> Then fetch from upstream. That downloads the original repo's newest +> commits, and changes none of your files. ## Scene 5: Make a virtual environment visual: terminal @@ -108,19 +104,26 @@ $ source .venv/bin/activate ## Scene 6: Make a branch visual: terminal -focus: 1 | 1-2 +focus: 1 | 1 | 1-3 notes: -- `-c` means create +- `-c` means create. `upstream/main` is where the branch starts. +- Your own `main` may still hold your first commit. This leaves it out. - One branch per pull request. Never work on `main`. code: ``` -(.venv) $ git switch -c exercise-2 +(.venv) $ git switch -c exercise-2 upstream/main Switched to a new branch 'exercise-2' +branch 'exercise-2' set up to track 'upstream/main'. ``` -> Step three. Make a branch. Git switch, dash c, {exercise-2|exercise two}. +> Step three. Make a branch. Git switch, dash c, {exercise-2|exercise two}, +> upstream slash main. + +> That starts the branch from the original repo's newest commit. Your own +> main branch may still hold your first commit, waiting to be merged. This +> way, it stays out of your new pull request. -> Never work on main directly. One branch per pull request. +> Always start new work like this. One branch per pull request. ## Scene 7: Write the test first visual: code From 26b082c96015242f85cb01258f0bac794cfe8bcf Mon Sep 17 00:00:00 2001 From: thejesh23 <35212698+thejesh23@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:48:30 -0800 Subject: [PATCH 4/7] Lessons 09 and 10: no pull into main; branch from upstream/main Co-Authored-By: Claude Fable 5.2 --- lessons/09-opening-an-issue/exercise.md | 3 ++- lessons/10-making-the-change/README.md | 5 ++--- lessons/10-making-the-change/exercise.md | 2 +- lessons/10-making-the-change/script.md | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lessons/09-opening-an-issue/exercise.md b/lessons/09-opening-an-issue/exercise.md index 4f756df..ac66875 100644 --- a/lessons/09-opening-an-issue/exercise.md +++ b/lessons/09-opening-an-issue/exercise.md @@ -3,7 +3,8 @@ `bug-hunt/splitbill.py` has **five** bugs on purpose. Find one and report it the way a maintainer would want. -- [ ] Get the latest course files: `git switch main` and `git pull upstream main` +- [ ] In the course folder, check the bug hunt is there: `ls bug-hunt`. (Missing? Your fork is older than this + lesson: `git fetch upstream`, then `git switch -c bug-hunt upstream/main`.) - [ ] Read [`bug-hunt/README.md`](../../bug-hunt/README.md): it's the spec, what splitbill *should* do - [ ] Try splitbill with different bills, people, tips and tax, and compare with the README - [ ] Found something different? Make it **minimal**: the smallest numbers and fewest options that still show it diff --git a/lessons/10-making-the-change/README.md b/lessons/10-making-the-change/README.md index d5b1b41..59f4234 100644 --- a/lessons/10-making-the-change/README.md +++ b/lessons/10-making-the-change/README.md @@ -22,9 +22,8 @@ request for it, because the next learner needs the bug. ## Step 1: Branch, then reproduce ```bash norun -git switch main -git pull upstream main -git switch -c fix-slugify +git fetch upstream +git switch -c fix-slugify upstream/main cd practice python -c "from textkit import slugify; print(repr(slugify('Hello World')))" cd .. diff --git a/lessons/10-making-the-change/exercise.md b/lessons/10-making-the-change/exercise.md index 1756007..bae1914 100644 --- a/lessons/10-making-the-change/exercise.md +++ b/lessons/10-making-the-change/exercise.md @@ -3,7 +3,7 @@ Exercise 3 happens on your machine. **Don't open a pull request**: the bug has to stay for the next learner. -- [ ] `git switch main`, `git pull upstream main`, `git switch -c fix-slugify` +- [ ] `git fetch upstream`, then `git switch -c fix-slugify upstream/main` - [ ] Reproduce the bug from the lesson's bug report - [ ] Add a parametrized test to `practice/tests/test_textkit.py` and watch it fail - [ ] Fix `slugify` in `practice/textkit.py`, and update its docstring diff --git a/lessons/10-making-the-change/script.md b/lessons/10-making-the-change/script.md index b14e1fa..1510d83 100644 --- a/lessons/10-making-the-change/script.md +++ b/lessons/10-making-the-change/script.md @@ -43,12 +43,12 @@ bullets: visual: terminal focus: 1 | 2-3 | 4 notes: -- A new branch for the fix +- A new branch for the fix, from the newest upstream (`git fetch upstream` first) - Call the function yourself - Two hyphens. The bug is real. code: ``` -$ git switch -c fix-slugify +$ git switch -c fix-slugify upstream/main $ cd practice $ python -c "from textkit import slugify; print(repr(slugify('Hello World')))" 'hello--world' From f44ae823ce383e73856aee108aa81888d42e81ed Mon Sep 17 00:00:00 2001 From: thejesh23 <35212698+thejesh23@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:48:30 -0800 Subject: [PATCH 5/7] Troubleshooting: divergent branches, and when not to reset main Co-Authored-By: Claude Fable 5.2 --- lessons/A-troubleshooting/README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lessons/A-troubleshooting/README.md b/lessons/A-troubleshooting/README.md index b041249..7ae70be 100644 --- a/lessons/A-troubleshooting/README.md +++ b/lessons/A-troubleshooting/README.md @@ -19,6 +19,7 @@ read the fix. | Wrong files or message in your last commit | [7. Fix your last commit](#7-fix-your-last-commit) | | `This branch has conflicts that must be resolved` | [Lesson 12](../12-ci-and-review/) | | Your fork says "X commits behind" | [8. Fork out of date](#8-your-fork-is-out-of-date) | +| `fatal: Need to specify how to reconcile divergent branches` | [8. Fork out of date](#8-your-fork-is-out-of-date) | | `nothing to commit, working tree clean` but you changed something | [9. Nothing to commit](#9-nothing-to-commit) | | `error: externally-managed-environment` | [10. Python environment](#10-python-and-pip-problems) | | `No module named pytest` / `command not found: pytest` | [10. Python environment](#10-python-and-pip-problems) | @@ -240,9 +241,19 @@ git push origin main Or without touching your computer: `gh repo sync YOUR-USERNAME/REPO`, or the **Sync fork** button on your fork's page. -If `git pull upstream main` says your branches have **diverged** (common -after a project squash-merged your PR), and your fork's `main` has nothing you -need, reset it to match upstream: +If `git pull upstream main` stops with `Need to specify how to reconcile +divergent branches`, your `main` and the original's `main` each have commits +the other lacks. + +**In this course**, that means your Lesson 02 pull request isn't merged yet: +its commit is on your `main`. Don't reset anything, because that pull +request is made from your fork's `main`. You don't need the pull: start new +work with `git fetch upstream` and `git switch -c my-branch upstream/main`, +as Lesson 05 does. After the merge, `git pull upstream main` works again. + +**In a real project**, it's common after your PR was squash-merged. If your +fork's `main` has nothing you need and no open pull request is made from it, +reset it to match upstream: ```bash norun git switch main From b6426571f16c0dd124cfb486a727bd78229bde2c Mon Sep 17 00:00:00 2001 From: thejesh23 <35212698+thejesh23@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:49:32 -0800 Subject: [PATCH 6/7] Bots: say a syntax error's line number once Reported in #45: 'unterminated string literal (detected at line 3) (line 3)'. Co-Authored-By: Claude Fable 5.2 --- tests/test_check_first_commit.py | 9 +++++++++ tools/check_exercise_2.py | 4 ++-- tools/check_first_commit.py | 8 +++++++- tools/check_graduate.py | 4 ++-- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/test_check_first_commit.py b/tests/test_check_first_commit.py index e812e49..9db9782 100644 --- a/tests/test_check_first_commit.py +++ b/tests/test_check_first_commit.py @@ -144,3 +144,12 @@ def git(*args): capsys.readouterr() assert main(["--login", "ada", "--base", base, "--head", git("rev-parse", "HEAD")]) == NOT_A_LEARNER_PR assert capsys.readouterr().out == "" + + +def test_a_syntax_error_says_its_line_once(): + """Python adds "(detected at line 3)" to some messages; the bot used to add "(line 3)" after it.""" + errors = check_source('name = "Ada"\ngithub = "ada"\nmessage = "Hello\n', "ada").errors + assert errors == [ + "Your file isn't valid Python: unterminated string literal (line 3). " + 'A missing quote `"` is the most common cause.' + ] diff --git a/tools/check_exercise_2.py b/tools/check_exercise_2.py index e19a2ef..3163468 100644 --- a/tools/check_exercise_2.py +++ b/tools/check_exercise_2.py @@ -34,7 +34,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent)) from check_first_commit import FOLDER as FIRST_COMMITS # noqa: E402 -from check_first_commit import LOGIN_RE, Result, _git, check_source # noqa: E402 +from check_first_commit import LOGIN_RE, Result, _git, check_source, syntax_problem # noqa: E402 MAX_BYTES = 3_000 BANNED_NAMES = { @@ -157,7 +157,7 @@ def _parse(source: str, label: str, result: Result) -> ast.Module | None: try: return ast.parse(source) except SyntaxError as exc: - result.errors.append(f"{label} isn't valid Python: {exc.msg} (line {exc.lineno}).") + result.errors.append(f"{label} isn't valid Python: {syntax_problem(exc)}.") return None diff --git a/tools/check_first_commit.py b/tools/check_first_commit.py index 7a69720..049d759 100644 --- a/tools/check_first_commit.py +++ b/tools/check_first_commit.py @@ -98,6 +98,12 @@ def check_changes(changes: list[tuple[str, str]], login: str) -> tuple[Result, s return result, path +def syntax_problem(exc: SyntaxError) -> str: + """ "unterminated string literal (line 3)": Python's message, with the line number said once.""" + message = re.sub(r"\s*\(detected at line \d+\)", "", str(exc.msg)) + return f"{message} (line {exc.lineno})" + + def check_source(source: str, login: str) -> Result: """Check the contents of a learner's file without running it.""" result = Result() @@ -110,7 +116,7 @@ def check_source(source: str, login: str) -> Result: tree = ast.parse(source) except SyntaxError as exc: hint = ' A missing quote `"` is the most common cause.' if "string" in str(exc.msg).lower() else "" - result.errors.append(f"Your file isn't valid Python: {exc.msg} (line {exc.lineno}).{hint}") + result.errors.append(f"Your file isn't valid Python: {syntax_problem(exc)}.{hint}") return result values: dict[str, str] = {} diff --git a/tools/check_graduate.py b/tools/check_graduate.py index 4278851..d83d700 100644 --- a/tools/check_graduate.py +++ b/tools/check_graduate.py @@ -35,7 +35,7 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) -from check_first_commit import LOGIN_RE, Result, _git # noqa: E402 +from check_first_commit import LOGIN_RE, Result, _git, syntax_problem # noqa: E402 FOLDER = "graduates" REQUIRED = ("name", "github", "pr", "message") @@ -83,7 +83,7 @@ def parse_source(source: str) -> tuple[Result, dict[str, str]]: try: tree = ast.parse(source) except SyntaxError as exc: - result.errors.append(f"Your file isn't valid Python: {exc.msg} (line {exc.lineno}).") + result.errors.append(f"Your file isn't valid Python: {syntax_problem(exc)}.") return result, values for node in tree.body: if ( From 5d6ae208cc6daf220350cb08e646d028e86b6217 Mon Sep 17 00:00:00 2001 From: thejesh23 <35212698+thejesh23@users.noreply.github.com> Date: Thu, 26 Nov 2026 14:49:32 -0800 Subject: [PATCH 7/7] Lesson 09: use the form, because learners can't add the label from gh Reported in #45 (#48 was opened with gh issue create --label and the bot skipped it). Co-Authored-By: Claude Fable 5.2 --- lessons/09-opening-an-issue/exercise.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lessons/09-opening-an-issue/exercise.md b/lessons/09-opening-an-issue/exercise.md index ac66875..6e9d00e 100644 --- a/lessons/09-opening-an-issue/exercise.md +++ b/lessons/09-opening-an-issue/exercise.md @@ -17,7 +17,9 @@ the way a maintainer would want. - [ ] Search the [issues](https://github.com/thejesh23/first-python-contribution/issues) for your bug. Here a duplicate is fine, since other learners hunt the same bugs; in a real project, add to the existing issue instead -- [ ] Open **Issues โ†’ New issue โ†’ Bug hunt: report a splitbill bug**, fill in every field, and submit +- [ ] Open **Issues โ†’ New issue โ†’ Bug hunt: report a splitbill bug**, fill in every field, and submit. + Use the form in the browser, not `gh issue create`: the form adds the `bug-hunt` label the bot looks for, + and only maintainers can add labels from the command line - [ ] Read the bot's comment. Fix any โœ˜ by editing your issue (**ยทยทยท** โ†’ **Edit**); the bot checks again when you save Please **don't** open a pull request that fixes the bug: the next learner