mirror of
https://forgejo.stefka.eu/jiriks74/create-pull-request.git
synced 2025-01-18 16:01:06 +01:00
fix: reset branches to handle squash merge
This commit is contained in:
parent
5ea31358e9
commit
16fa12ee5f
3 changed files with 164 additions and 6 deletions
13
dist/index.js
vendored
13
dist/index.js
vendored
|
@ -3080,9 +3080,16 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
|
|||
core.info(`Pull request branch '${branch}' already exists as remote branch '${branchRemoteName}/${branch}'`);
|
||||
// Checkout the pull request branch
|
||||
yield git.checkout(branch);
|
||||
if (yield hasDiff(git, branch, tempBranch)) {
|
||||
// If the branch differs from the recreated temp version then the branch is reset
|
||||
// For changes on base this action is similar to a rebase of the pull request branch
|
||||
// Reset the branch if one of the following conditions is true.
|
||||
// - If the branch differs from the recreated temp branch.
|
||||
// - If the recreated temp branch is not ahead of the base. This means there will be
|
||||
// no pull request diff after the branch is reset. This will reset any undeleted
|
||||
// branches after merging. In particular, it catches a case where the branch was
|
||||
// squash merged but not deleted. We need to reset to make sure it doesn't appear
|
||||
// to have a diff with the base due to different commits for the same changes.
|
||||
// For changes on base this reset is equivalent to a rebase of the pull request branch.
|
||||
if ((yield hasDiff(git, branch, tempBranch)) ||
|
||||
!(yield isAhead(git, base, tempBranch))) {
|
||||
core.info(`Resetting '${branch}'`);
|
||||
// Alternatively, git switch -C branch tempBranch
|
||||
yield git.checkout(branch, tempBranch);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue