Move files without losing the ratchet
At the end of this guide, a file or folder you moved keeps its counts in the baseline under its new name, and
ashlar check passes.
The baseline holds counts by file path. A moved file has a new path that the baseline doesn't name, and a path the baseline doesn't name holds none, so every break the file carried counts as a rise.
-
Move the file, and run the check:
Terminal window git mv packages/money/src/total.ts packages/money/src/sum.tsTerminal window $ pnpm exec ashlar checkAshlar checked 9 files in 0.2 s: 1 count rose.packages/money/src/sum.ts moved from packages/money/src/total.ts: `ashlar move packages/money/src/total.ts packages/money/src/sum.ts` takes its counts with it.no-comment in packages/money/src/sum.ts: 1, up from 0packages/money/src/sum.ts:1:1Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.The comment was there before the move. Ashlar sees that git renamed the file, and says which command takes its counts along.
-
Take the counts to the new name with
ashlar move:Terminal window $ pnpm exec ashlar move packages/money/src/total.ts packages/money/src/sum.tspackages/money/src/total.ts → packages/money/src/sum.ts: 1 break moved."no-comment": {"apps/api/src/orders/index.ts": 1,"packages/money/src/total.ts": 1"packages/money/src/sum.ts": 1},Terminal window $ pnpm exec ashlar checkAshlar checked 9 files in 0.2 s: no count rose.Commit the baseline with the move.
ashlar moveworks before or after you move the files, as long as exactly one of the two paths exists. Give it several pairs at once:ashlar move <from> <to> <from> <to>. -
Or let
check --shrinktake the renames git sees. On the same move, instead ofashlar move:Terminal window $ pnpm exec ashlar check --shrinkAshlar checked 9 files in 0.2 s: no count rose.The baseline now holds 6 breaks.--shrinkgives each file git saw renamed the counts of its old name, then lowers counts as it always does. Git sees a rename between the branch's start onmainand your working tree when the move is committed or staged (git mvstages it) and the file kept enough of its content. A file moved with a plainmvand not added, or changed too much on the way, looks like a file deleted and another added: useashlar movefor it. -
Move a folder the same way. Every file in it keeps its counts:
Terminal window git mv apps/api/src/orders apps/api/src/salesTerminal window $ pnpm exec ashlar move apps/api/src/orders apps/api/src/salesapps/api/src/orders → apps/api/src/sales: 1 break moved. -
Fix a move that takes in new breaks. Each file keeps what it holds now, up to what the baseline held for it, so a moved file can't carry more breaks than before. If someone added one on the way, the move is refused, and the baseline stays as it was:
Terminal window $ pnpm exec ashlar move packages/money/src/total.ts packages/money/src/sum.tsAshlar moved no counts: the move would take in new breaks.packages/money/src/total.ts → packages/money/src/sum.ts: no-comment rose to 2, up from 1Fix the moved code, or give `--accept-rise` to take the rise into the baseline.It exits with 2. Take the new break out and move again. If a person accepts the rise,
--accept-risetakes it in and says so:Terminal window $ pnpm exec ashlar move packages/money/src/total.ts packages/money/src/sum.ts --accept-risepackages/money/src/total.ts → packages/money/src/sum.ts: 2 breaks moved.no-comment rose to 2, up from 1: taken in with --accept-rise.
When it refuses
Section titled “When it refuses”| Ashlar says | Why |
|---|---|
There is no baseline to move counts in yet: take it first with ashlar check --shrink. |
The project has no baseline, so there are no counts to move. |
| Ashlar can't tell where packages/money/src/a.ts's counts go: exactly one of packages/money/src/a.ts and packages/money/src/b.ts must exist. | Both paths are files on disk, or neither is on disk and the baseline holds no file under the first. |
| Ashlar moved no counts: the move would take in new breaks. | The moved code holds more breaks than the baseline held for it. |
ashlar move --json prints each move: its from, its to, its kind (file or folder), the breaks it
moved and the rises it took in.
Related
Section titled “Related”- The ratchet
- Adopt Ashlar in an existing repository
- CLI, for
ashlar moveandashlar check - JSON outputs, for
ashlar move --json