Add sp promote: graduate a scratch into the working tree - #20
Merged
Conversation
5 tasks
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.
Closes #8
What
Adds
sp promote <id> [dest]— the "oops, keep this" escape hatch. It moves a scratch's content file out of the store and into the working tree, then drops the entry from the index so the promoted file is the repo's to keep (and the reaper can't touch it).Behavior
sp promote <id>→ moves into the current dir, named from a slug of the scratch's name (its id when unnamed), preserving the extension.sp promote <id> ./dir→ existing-directory dest drops the file inside as<slug>.<ext>.sp promote <id> path/keep.md→ any other dest is the full target path (renames on the way out), creating parent dirs as needed.--force→ overwrite an existing destination. Without it, promote refuses and leaves the scratch untouched in the store (non-destructive guard).--no-open→ skip opening the promoted file in$EDITOR. A missing$EDITORis never fatal — the move already happened.Acceptance criteria
sp promote <id> [dest]moves the scratch out of the store into cwd (ordest)--force$EDITORafter moving (unless--no-open)Implementation notes
store.Promote(reuses the existing cross-device-safemoveFile); it moves content first and only drops the index entry after the content has safely landed, rolling the move back if the index write fails — so a scratch is never lost between the two steps.store.ErrDestinationExistsdrives the CLI's--forcehint.Tests
internal/store/promote_test.go— move-out + index drop, promote from morgue, overwrite refusal (non-destructive),--force, nested-dir creation.internal/cli/promote_test.go— full CLI flow: default cwd, directory-dest slugging, explicit rename,--force, prefix resolution, unknown-id error, refused-overwrite leaves scratch listed.go build ./...,go vet ./...,go test ./..., andgofmt -lall clean; no new dependencies (go.mod stays tidy). README updated with asp promotesection + quickstart line.