Repository navigation
Conversation
When running `git node release --promote` from a release-line worktree while the default branch is already checked out in another worktree, `git checkout <defaultBranch>` fails with exit code 128. Inspect `git worktree list --porcelain` in `checkoutDefaultBranch()` to detect when the default branch is checked out in another worktree, ask the user before switching to it, guard dirty target worktrees with an explicit stash confirmation, and restore any target stash and original working directory in `finally`. Also resolve linked-worktree `.git` files in `Session.prototype.gitDir` and use `cherryPickInProgress()`. Fixes: nodejs#906 Signed-off-by: ychampion <68075205+ychampion@users.noreply.github.com>
Contributor
|
What's your use-case for running |
This branch has not been deployed
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.
Summary
Fixes: #906
When running
git node release --promotefrom a release-line worktree (such asv23.x) while the repository's default branch (main) is already checked out in another worktree,ReleasePromotion.prototype.checkoutDefaultBranch()failed with:Changes
lib/promote_release.js:git worktree list --porcelainviaparseWorktreeList()to detect whetherrefs/heads/<defaultBranch>is already checked out in another non-bare, non-prunable worktree (comparing normalized realpaths againstgit rev-parse --show-toplevel).git status --porcelain, warn and prompt withdefaultAnswer: falseto stash them before proceeding, aborting cleanly if declined).process.chdir+this.dir) in afinallyblock insidepromote()(and on early errors incheckoutDefaultBranch()), sowrapStash()incomponents/git/release.jsalways pops the starting worktree's stash in the original directory.git checkout <defaultBranch>behavior unchanged when the default branch is not checked out in another worktree or is already checked out in the current worktree.existsSync('.git/CHERRY_PICK_HEAD')incherryPickReleaseCommit()withthis.cherryPickInProgress()so linked worktrees (where.gitis a file) work properly.lib/session.js:gitdir:indirection inSession.prototype.gitDirwhen.gitis a linked-worktree file (falling back to<dir>/.gitandprocess.cwd()whenthis.diris unset), ensuringcherryPickInProgress(),rebaseInProgress(), andamInProgress()work inside linked worktrees.test/unit/promote_release.test.js:parseWorktreeList()and end-to-end worktree tests using temporarygit init+git worktree addrepositories covering switching/cherry-picking/restoringcwd, declining to switch, dirty target worktree decline and stash/restore-on-error, normal checkout when branch is free, no-op when already on default-branch worktree, andgitDir/cherryPickInProgress()in a linked worktree.Verification
node --test test/unit/promote_release.test.js(17/17 passing)node --test test/unit/prepare_release.test.js test/unit/cherry_pick.test.js test/unit/amend.test.js test/unit/run.test.js test/unit/cli.test.js(all passing)npm run lint(eslint . --cache: 0 errors, 0 warnings)