From c6f963d0abb301b1adc746a7f32b0597592f115a Mon Sep 17 00:00:00 2001 From: peter-evans Date: Fri, 11 Nov 2022 05:59:11 +0000 Subject: [PATCH] [CI] test built --- dist/index.js | 29 ++++++++++++++++++++++++----- report.txt | 1 + 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 report.txt diff --git a/dist/index.js b/dist/index.js index 23b649f..81ec939 100644 --- a/dist/index.js +++ b/dist/index.js @@ -74,18 +74,30 @@ function tryFetch(git, remote, branch) { }); } exports.tryFetch = tryFetch; +// Return the number of commits that branch2 is ahead of branch1 +function commitsAhead(git, branch1, branch2) { + return __awaiter(this, void 0, void 0, function* () { + const result = yield git.revList([`${branch1}...${branch2}`], ['--right-only', '--count']); + return Number(result); + }); +} // Return true if branch2 is ahead of branch1 function isAhead(git, branch1, branch2) { return __awaiter(this, void 0, void 0, function* () { - const result = yield git.revList([`${branch1}...${branch2}`], ['--right-only', '--count']); - return Number(result) > 0; + return (yield commitsAhead(git, branch1, branch2)) > 0; + }); +} +// Return the number of commits that branch2 is behind branch1 +function commitsBehind(git, branch1, branch2) { + return __awaiter(this, void 0, void 0, function* () { + const result = yield git.revList([`${branch1}...${branch2}`], ['--left-only', '--count']); + return Number(result); }); } // Return true if branch2 is behind branch1 function isBehind(git, branch1, branch2) { return __awaiter(this, void 0, void 0, function* () { - const result = yield git.revList([`${branch1}...${branch2}`], ['--left-only', '--count']); - return Number(result) > 0; + return (yield commitsBehind(git, branch1, branch2)) > 0; }); } // Return true if branch2 is even with branch1 @@ -214,9 +226,16 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName // 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. + // - If the number of commits ahead of the base branch differs between the branch and + // temp branch. This catches a case where the base branch has been force pushed to + // a new commit. // For changes on base this reset is equivalent to a rebase of the pull request branch. + const tempBranchCommitsAhead = yield commitsAhead(git, base, tempBranch); + const branchCommitsAhead = yield commitsAhead(git, base, branch); if ((yield git.hasDiff([`${branch}..${tempBranch}`])) || - !(yield isAhead(git, base, tempBranch))) { + branchCommitsAhead != tempBranchCommitsAhead || + !(tempBranchCommitsAhead > 0) // !isAhead + ) { core.info(`Resetting '${branch}'`); // Alternatively, git switch -C branch tempBranch yield git.checkout(branch, tempBranch); diff --git a/report.txt b/report.txt new file mode 100644 index 0000000..3c1d49c --- /dev/null +++ b/report.txt @@ -0,0 +1 @@ +1668146350