Safe batch operations: dry-run, marker, and dirty repository
Adding a link back in forty repositories, swapping a footer on a hundred pages, fixing a canonical across the whole site: this is where the agent saves you hours, and this is where one mistake spreads. Three protections solve almost everything: show before you do, don't duplicate, and don't touch what someone else is working on.
1Dry-run by default: see what it would do before doing it
2Marker: running twice doesn't duplicate
3Skip the repository with unsaved work
4Check it live by sample after the push
Goal: run an operation across several repositories with a dry-run, a marker against duplicating, and skipping dirty repos, checking by sample.
01 · The path of a safe batch
Tap each block.
Click each block in the diagram to see what it does.
Three protections: dry-run, marker, and skipping a dirty repository.
02 · The protections, one by one
Tap each step.
1. Dry-run
The script's default is not to write. Writing requires asking for it: --apply. That way a mistake in the map shows up in the list, not on the site.
Ask any agent for the same thing: first the list of what it would do, then the run.
2. Marker
The written block goes between two comments with the marker link-de-volta:v1. Before writing, the script looks for the marker: if it's already there, it answers "OK: já tinha".
This is what lets you run it again after a failure without creating two links on the same page.
3. Dirty repository
If the repository has an uncommitted change, the script skips it. It's almost always another session (yours or another agent's) working on it.
It also skips a repository that's not on the expected branch and one that has no HTML. In INEMA, repositories skipped because of a dirty working tree were left for the next round.
4. Where the link goes
If index.html is just a redirect (meta refresh), the link goes on the destination page. If the HTML is generated by a script, the link goes in the generator, otherwise it disappears on the next build.
In INEMA: 35 of 40 repositories on 09/24, another 25 on 10/02, and another 21 on 10/05.
python3 tools/link_de_volta.py mapa.json # dry-run: só mostra
python3 tools/link_de_volta.py mapa.json --apply # grava, sem commit
python3 tools/link_de_volta.py mapa.json --apply --commit # grava, commita e faz push
Request to the agent
Build the mapa.json with the repositories from the list and run link_de_volta.py with NO options (dry-run).
Show me the full output and stop.
Don't use --apply or --commit until I reply "aplica".
Repository with PULA: don't force it, don't stash, don't commit for it. Just tell me which one it is.
Example from the repository
$ python3 tools/link_de_volta.py mapa.json
repos/curso-pao: DRY: entraria em index.html
repos/curso-cafe: PULA: alterações não commitadas
repos/curso-queijo: OK: já tinha
repos/curso-vinho: DRY: entraria em landing.html
$ python3 tools/link_de_volta.py mapa.json --apply
repos/curso-pao: APLICADO em index.html
repos/curso-cafe: PULA: alterações não commitadas
repos/curso-queijo: OK: já tinha
repos/curso-vinho: APLICADO em landing.html
Four test repositories set up for the lesson.
curso-pao: clean, gets the block in index.html.
curso-cafe: has an unsaved change; skipped in both rounds.
curso-queijo: the marker was already there; nothing changes.
curso-vinho: index.html is just a redirect, so the block goes in landing.html.
After --apply without --commit, curso-pao and curso-vinho are left with an uncommitted change: running again without committing makes the script skip both. Commit or discard before the next round.
04 · See the batch with interruption and resume
Run it, interrupt halfway, and run it again. What's already done isn't redone.
to do/
applying/
done (with marker)/
skipped/
Illustrative simulation in the browser: nothing is actually written. The skip is on purpose, to show the dirty repository.
05 · Practice: a real batch, over the network
Use 3 or more of your own repositories (or create test repositories with a simple index.html).
E1 · The dry-run
25 min
Ask the agent for the mapa.json and the dry-run, using the request above. Leave one repository with an uncommitted change on purpose.
Done when: the output shows at least one DRY and one PULA with the reason, and the git status of the repositories did not change.
E2 · Apply and check
25 min
Reply "aplica", run with --apply, check the diff of each repository, commit (or use --commit), and run the dry-run again.
Done when: the second run answers "OK: já tinha" in the repositories you applied, and you opened at least 2 published pages and saw the link in the HTML.
06 · Test what you learned
The explanation appears after your answer.
Question 1 of 4
What does link_de_volta.py do when you run it with no options?skill
Correct
Dry-run is the default. Writing requires --apply; publishing requires --commit. The common mistake is the reverse: a script that writes by default and needs an option to simulate.
Not this one
Dry-run is the default. Writing requires --apply; publishing requires --commit. The common mistake is the reverse: a script that writes by default and needs an option to simulate.Review: The path of a safe batch
Question 2 of 4
A repository shows up as "PULA: alterações não commitadas". What should you do?
Correct
An unsaved change is someone's work. Forcing it mixes your commit with theirs. In INEMA, the skipped ones were left for the next round.
Not this one
An unsaved change is someone's work. Forcing it mixes your commit with theirs. In INEMA, the skipped ones were left for the next round.Review: The protections, one by one
Question 3 of 4
What is the link-de-volta:v1 marker for?
Correct
Before writing, the script looks for the marker. If it already exists, it answers "OK: já tinha". That is what makes resuming safe.
A course's index.html is just a redirect. Where should the link go?
Correct
The search engine follows the redirect and reads the destination. A link in the redirect file is not seen. If the HTML is generated, the link goes in the generator.
Not this one
The search engine follows the redirect and reads the destination. A link in the redirect file is not seen. If the HTML is generated, the link goes in the generator.Review: The link back in batch
Quiz complete
You got {a} of {n} right. Get them all right and the lesson is marked as complete.
Choose an option. The explanation appears after your attempt.
07 · To take with you
Dry-run by defaultSee the list first; write only with --apply.
MarkerRunning twice does not duplicate; resuming is safe.
Dirty means someone else'sA repository with an unsaved change is skipped, not forced.
Push is publishing--commit does a push: go through the gate before it and check a sample after.