-
Notifications
You must be signed in to change notification settings - Fork 572
Fail loudly when preserve-branch-name collides with existing remote branch #27458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -983,6 +983,13 @@ async function main(config = {}) { | |
| } | ||
|
|
||
| if (remoteBranchExists) { | ||
| if (preserveBranchName) { | ||
| throw new Error( | ||
| `Remote branch "${branchName}" already exists and preserve-branch-name is enabled. ` + | ||
| `Refusing to silently rename the branch. Either delete the remote branch, choose a different ` + | ||
| `branch name, or disable preserve-branch-name to allow a random suffix to be appended.` | ||
| ); | ||
| } | ||
| core.warning(`Remote branch ${branchName} already exists - appending random suffix`); | ||
| const extraHex = crypto.randomBytes(4).toString("hex"); | ||
| const oldBranch = branchName; | ||
|
|
@@ -1211,6 +1218,13 @@ gh pr create --title '${title}' --base ${baseBranch} --head ${branchName} --repo | |
| } | ||
|
|
||
| if (remoteBranchExists) { | ||
| if (preserveBranchName) { | ||
| throw new Error( | ||
| `Remote branch "${branchName}" already exists and preserve-branch-name is enabled. ` + | ||
| `Refusing to silently rename the branch. Either delete the remote branch, choose a different ` + | ||
| `branch name, or disable preserve-branch-name to allow a random suffix to be appended.` | ||
| ); | ||
| } | ||
| core.warning(`Remote branch ${branchName} already exists - appending random suffix`); | ||
| const extraHex = crypto.randomBytes(4).toString("hex"); | ||
| const oldBranch = branchName; | ||
|
|
@@ -1374,6 +1388,13 @@ ${patchPreview}`; | |
| } | ||
|
|
||
| if (remoteBranchExists) { | ||
| if (preserveBranchName) { | ||
| throw new Error( | ||
| `Remote branch "${branchName}" already exists and preserve-branch-name is enabled. ` + | ||
| `Refusing to silently rename the branch. Either delete the remote branch, choose a different ` + | ||
| `branch name, or disable preserve-branch-name to allow a random suffix to be appended.` | ||
|
||
| ); | ||
| } | ||
| core.warning(`Remote branch ${branchName} already exists - appending random suffix`); | ||
| const extraHex = crypto.randomBytes(4).toString("hex"); | ||
| const oldBranch = branchName; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The actionable collision error message is duplicated verbatim in three separate remote-branch collision blocks (bundle push, patch push, and allow-empty push). To reduce drift risk and make future edits safer, consider extracting this message into a small helper (e.g.,
makePreserveBranchNameCollisionError(branchName)) or a shared constant.