Skip to content

fix: restore the original branch after promote - #9

Merged
sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/5-promote-restore-branch
Oct 18, 2026
Merged

sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/5-promote-restore-branch

Conversation

@sujal-maheshwari2004

Copy link
Copy Markdown
Contributor

What was wrong

promptctl promote <file> <from> <to> checked out <to> to commit the prompt, then left it checked out. Running promote acme/a.prompt dev staging from dev left the working copy on staging.

The fix

promote records HEAD before checking out <to>. After the commit it switches back to that branch, or to that commit if HEAD was detached. It switches back even if the commit fails. The write/add/commit steps moved into a small commitFile helper 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.go TestPromoteRestoresBranch: it builds a real go-git repo with main/dev/staging, promotes from dev, and checks that HEAD is still dev, the working tree has dev's content, and staging has the promoted content.

Against the old main.go:

--- FAIL: TestPromoteRestoresBranch (0.23s)
    promote_test.go:51: after promote HEAD is staging, want dev (the branch it started on)

Full suite: GOWORK=off go build ./... && go vet ./... && go test ./... gives ok github.com/priompt/cli/cmd/promptctl

Before / after (real run)

Before (main):

$ git branch --show-current
dev
$ promptctl promote acme/a.prompt dev staging
promoted acme/a.prompt onto staging (d697f09b6255)
now on: staging

After:

on: dev
promoted acme/a.prompt onto staging (311d0057c710)
exit=0
now on: dev
311d005 promote acme/a.prompt: dev -> staging
-- detached HEAD at main:
promoted acme/a.prompt onto staging (311d0057c710)
HEAD: c39baab main=c39baab branch=''

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

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>
@sujal-maheshwari2004
sujal-maheshwari2004 merged commit fc91a37 into main Oct 18, 2026
1 check passed
@sujal-maheshwari2004
sujal-maheshwari2004 deleted the fix/5-promote-restore-branch branch October 18, 2026 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

promptctl promote leaves the repo checked out on the target branch

1 participant