Repository navigation
fix: restore the original branch after promote - #9
Merged
Merged
Conversation
promptctl promote checked out the target branch to commit the prompt and left it checked out, so `promote x.prompt dev staging` run from dev left the working copy on staging. promote now records HEAD before the checkout and switches back to it afterwards: the branch it started on, or the commit if HEAD was detached. It switches back even when the commit fails. Fixes #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 was wrong
promptctl promote <file> <from> <to>checked out<to>to commit the prompt, then left it checked out. Runningpromote acme/a.prompt dev stagingfromdevleft the working copy onstaging.The fix
promoterecordsHEADbefore checking out<to>. After the commit it switches back to that branch, or to that commit ifHEADwas detached. It switches back even if the commit fails. The write/add/commit steps moved into a smallcommitFilehelper that returns the error instead of exiting, so the switch back still runs. The README's Environments section notes that you stay on your branch.Tests
New
cmd/promptctl/promote_test.goTestPromoteRestoresBranch: it builds a real go-git repo withmain/dev/staging, promotes fromdev, and checks thatHEADis stilldev, the working tree has dev's content, andstaginghas the promoted content.Against the old
main.go:Full suite:
GOWORK=off go build ./... && go vet ./... && go test ./...givesok github.com/priompt/cli/cmd/promptctlBefore / after (real run)
Before (main):
After:
Independent of #7 (still open). A local merge of #7 + main + this branch applied cleanly and
go test ./...passed.Fixes #5
🤖 Generated with Claude Code