feat(undo-last): single-step undo via .bak snapshot#11
Merged
Conversation
Every Store.Save() now writes the previous on-disk contents to
"<path>.bak" before atomically writing the new contents. `tsk
undo-last` swaps the .bak and current file, restoring the most
recent prior state.
Properties
- Single-step: only one snapshot ever exists.
- Involutive: running undo-last twice returns to the original
state, since the swap itself is a save.
- Best-effort: snapshot writes never abort a Save() — read-only
or transient FS failures fall through silently.
- Interactive by default: prompts unless --yes is passed.
Snapshot is created lazily — no .bak appears until at least one
save modifies an existing file. First-time `tsk add` leaves no
.bak behind. This avoids spamming brand-new tsk users with a
mysterious file the moment they run anything.
6715816 to
ebcbdd9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
tsk undo-last— revert the most recent change to the task file. Single-step undo for the common "oops I just deleted/renamed the wrong thing" case.Every
Store.Save()now writes the previous on-disk contents to<path>.bakbefore atomically writing the new contents.tsk undo-lastswaps the live file and the .bak.Properties
undo-lasttwice returns to the state you had before the first undo, because the swap itself is a save..bakappears until at least one save modifies an existing file. A brand-newtsk addon an empty directory leaves no.bakbehind. First-run users don't get a mysterious sidecar file.Flags
--yes,-yWithout
--yes, the command prints what it's about to swap and waits fory/N.Examples
Tests
5 new tests in
internal/commands/undo_last_test.go: