From 66468b3fc27ae7f353334831cfa4f9cf15511cce Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Thu, 5 Sep 2024 08:05:38 +0000 Subject: [PATCH] fix: handle ambiguous argument failure on diff stat --- dist/index.js | 17 ++++++++++++++--- src/create-or-update-branch.ts | 24 +++++++++++++++++------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/dist/index.js b/dist/index.js index ebdaedaa81..d649275188 100644 --- a/dist/index.js +++ b/dist/index.js @@ -46,6 +46,7 @@ exports.buildBranchCommits = buildBranchCommits; exports.createOrUpdateBranch = createOrUpdateBranch; const core = __importStar(__nccwpck_require__(2186)); const uuid_1 = __nccwpck_require__(5840); +const utils = __importStar(__nccwpck_require__(918)); const CHERRYPICK_EMPTY = 'The previous cherry-pick is now empty, possibly due to conflict resolution.'; const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean'; const FETCH_DEPTH_MARGIN = 10; @@ -136,9 +137,19 @@ function isEven(git, branch1, branch2) { // Return true if the specified number of commits on branch1 and branch2 have a diff function commitsHaveDiff(git, branch1, branch2, depth) { return __awaiter(this, void 0, void 0, function* () { - const diff1 = (yield git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`])).stdout.trim(); - const diff2 = (yield git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`])).stdout.trim(); - return diff1 !== diff2; + // Some action use cases lead to the depth being a very large number and the diff fails. + // I've made this check optional for now because it was a fix for an edge case that is + // very rare, anyway. + try { + const diff1 = (yield git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`])).stdout.trim(); + const diff2 = (yield git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`])).stdout.trim(); + return diff1 !== diff2; + } + catch (error) { + core.info('Failed optional check of commits diff; Skipping.'); + core.debug(utils.getErrorMessage(error)); + return false; + } }); } function splitLines(multilineString) { diff --git a/src/create-or-update-branch.ts b/src/create-or-update-branch.ts index f835006924..2eecd45d13 100644 --- a/src/create-or-update-branch.ts +++ b/src/create-or-update-branch.ts @@ -1,6 +1,7 @@ import * as core from '@actions/core' import {GitCommandManager, Commit} from './git-command-manager' import {v4 as uuidv4} from 'uuid' +import * as utils from './utils' const CHERRYPICK_EMPTY = 'The previous cherry-pick is now empty, possibly due to conflict resolution.' @@ -131,13 +132,22 @@ async function commitsHaveDiff( branch2: string, depth: number ): Promise { - const diff1 = ( - await git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`]) - ).stdout.trim() - const diff2 = ( - await git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`]) - ).stdout.trim() - return diff1 !== diff2 + // Some action use cases lead to the depth being a very large number and the diff fails. + // I've made this check optional for now because it was a fix for an edge case that is + // very rare, anyway. + try { + const diff1 = ( + await git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`]) + ).stdout.trim() + const diff2 = ( + await git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`]) + ).stdout.trim() + return diff1 !== diff2 + } catch (error) { + core.info('Failed optional check of commits diff; Skipping.') + core.debug(utils.getErrorMessage(error)) + return false + } } function splitLines(multilineString: string): string[] {