fix(pr): resolve unexpected behavior in create-pull-request #4197

This commit is contained in:
BLACKBOX Agent 2025-11-06 16:29:18 +00:00
parent 0edc001d28
commit 77b62e2232
2 changed files with 14 additions and 5 deletions

6
dist/index.js vendored
View File

@ -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);

View File

@ -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)