Repository navigation
fix(promote): refuse to run on a dirty tree and never strand HEAD on <to> - #29
Merged
Merged
Conversation
Member
Author
|
Pushed two follow-up commits for Windows line endings. go-git ignores
Correction: the first follow-up commit ( |
…<to> promote round-trips through a checkout of <to>. go-git's Checkout only refuses unstaged edits, so staged edits and staged new files were reset away with exit 0, and when it did refuse it had already moved HEAD, leaving the user on <to> with their work in the tree. promote now checks for staged or modified tracked files up front and stops with "commit or stash first" (untracked files are fine; the checkout leaves them alone). If the checkout of <to> still fails, HEAD is restored to the branch or commit the user started on. Fixes #14 Fixes #15
go-git ignores core.autocrlf when it has to hash a file (a racy index entry right after a checkout, or a touched file), so a clean CRLF checkout of an LF blob shows as modified and the new clean-tree check would block promote on Windows. A worktree-modified file now only counts when it differs from HEAD by more than line endings (changedLines).
…ckout refuse The previous commit let a CRLF-only file through promote's own check, but go-git's Checkout hits the same false positive and refuses with "worktree contains unstaged changes" (TestPromoteAllowsLineEndingOnlyDifferences failed). Such files are now rewritten with their committed content before the round trip; only their line endings change, as for every file go-git checks out. Checkout Force was not an option: it deletes untracked files.
sujal-maheshwari2004
force-pushed
the
fix/promote-dirty-tree
branch
from
November 15, 2026 05:09
7c83267 to
06a3c91
Compare
sujal-maheshwari2004
requested review from
guptadevik2003 and
iamDyeus
as code owners
November 15, 2026 05:09
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.
Fixes #14. Fixes #15.
promotechecks out<to>, commits there, and checks the original branch back out. go-git'sCheckoutonly refuses unstaged edits, which caused two bugs:<to>(e.g. prod) with their work in the tree.Change
promotelists staged or modified tracked files and stops withpromote needs a clean working tree; commit or stash first: <files>.<to>still fails for another reason, HEAD is restored to the starting branch or detached commit before exiting.core.autocrlf=true, go-git's status does not report CRLF-checked-out files as modified, so the check doesn't block Windows users. I verified that separately.Tested
promote_dirty_test.go. The two refusal cases runpromotein a child process because it exits throughlog.Fatal. They check:main, the first two fail: promote reportspromoted acme/a.prompt onto prodwith staged changes, andcheckout prod: worktree contains unstaged changesfor the unstaged case.go vet ./...andgo test ./...pass.