diff --git a/dist/index.js b/dist/index.js index 75ae3c2f07..353cabee82 100644 --- a/dist/index.js +++ b/dist/index.js @@ -285,10 +285,12 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName // // For changes on base this reset is equivalent to a rebase of the pull request branch. const branchCommitsAhead = yield commitsAhead(git, base, branch); - if ((yield git.hasDiff([`${branch}..${tempBranch}`])) || + const shouldReset = (yield git.hasDiff([`${branch}..${tempBranch}`])) || branchCommitsAhead != tempBranchCommitsAhead || !(tempBranchCommitsAhead > 0) || // !isAhead - (yield commitsHaveDiff(git, branch, tempBranch, tempBranchCommitsAhead))) { + (tempBranchCommitsAhead > 0 && + (yield commitsHaveDiff(git, branch, tempBranch, tempBranchCommitsAhead))); + if (shouldReset) { core.info(`Resetting '${branch}'`); // Alternatively, git switch -C branch tempBranch yield git.checkout(branch, tempBranch); diff --git a/src/create-or-update-branch.ts b/src/create-or-update-branch.ts index 746a3a0381..9ecfcb7899 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -311,12 +311,19 @@ export async function createOrUpdateBranch( // // For changes on base this reset is equivalent to a rebase of the pull request branch. const branchCommitsAhead = await commitsAhead(git, base, branch) - if ( + const shouldReset = (await git.hasDiff([`${branch}..${tempBranch}`])) || branchCommitsAhead != tempBranchCommitsAhead || !(tempBranchCommitsAhead > 0) || // !isAhead - (await commitsHaveDiff(git, branch, tempBranch, tempBranchCommitsAhead)) - ) { + (tempBranchCommitsAhead > 0 && + (await commitsHaveDiff( + git, + branch, + tempBranch, + tempBranchCommitsAhead + ))) + + if (shouldReset) { core.info(`Resetting '${branch}'`) // Alternatively, git switch -C branch tempBranch await git.checkout(branch, tempBranch)