Skip to content

Commit 8867c4a

Browse files
authored
fix: handle ambiguous argument failure on diff stat (#3312)
1 parent 6073f54 commit 8867c4a

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

dist/index.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ exports.buildBranchCommits = buildBranchCommits;
4646
exports.createOrUpdateBranch = createOrUpdateBranch;
4747
const core = __importStar(__nccwpck_require__(2186));
4848
const uuid_1 = __nccwpck_require__(5840);
49+
const utils = __importStar(__nccwpck_require__(918));
4950
const CHERRYPICK_EMPTY = 'The previous cherry-pick is now empty, possibly due to conflict resolution.';
5051
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean';
5152
const FETCH_DEPTH_MARGIN = 10;
@@ -136,9 +137,19 @@ function isEven(git, branch1, branch2) {
136137
// Return true if the specified number of commits on branch1 and branch2 have a diff
137138
function commitsHaveDiff(git, branch1, branch2, depth) {
138139
return __awaiter(this, void 0, void 0, function* () {
139-
const diff1 = (yield git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`])).stdout.trim();
140-
const diff2 = (yield git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`])).stdout.trim();
141-
return diff1 !== diff2;
140+
// Some action use cases lead to the depth being a very large number and the diff fails.
141+
// I've made this check optional for now because it was a fix for an edge case that is
142+
// very rare, anyway.
143+
try {
144+
const diff1 = (yield git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`])).stdout.trim();
145+
const diff2 = (yield git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`])).stdout.trim();
146+
return diff1 !== diff2;
147+
}
148+
catch (error) {
149+
core.info('Failed optional check of commits diff; Skipping.');
150+
core.debug(utils.getErrorMessage(error));
151+
return false;
152+
}
142153
});
143154
}
144155
function splitLines(multilineString) {

src/create-or-update-branch.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from '@actions/core'
22
import {GitCommandManager, Commit} from './git-command-manager'
33
import {v4 as uuidv4} from 'uuid'
4+
import * as utils from './utils'
45

56
const CHERRYPICK_EMPTY =
67
'The previous cherry-pick is now empty, possibly due to conflict resolution.'
@@ -131,13 +132,22 @@ async function commitsHaveDiff(
131132
branch2: string,
132133
depth: number
133134
): Promise<boolean> {
134-
const diff1 = (
135-
await git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`])
136-
).stdout.trim()
137-
const diff2 = (
138-
await git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`])
139-
).stdout.trim()
140-
return diff1 !== diff2
135+
// Some action use cases lead to the depth being a very large number and the diff fails.
136+
// I've made this check optional for now because it was a fix for an edge case that is
137+
// very rare, anyway.
138+
try {
139+
const diff1 = (
140+
await git.exec(['diff', '--stat', `${branch1}..${branch1}~${depth}`])
141+
).stdout.trim()
142+
const diff2 = (
143+
await git.exec(['diff', '--stat', `${branch2}..${branch2}~${depth}`])
144+
).stdout.trim()
145+
return diff1 !== diff2
146+
} catch (error) {
147+
core.info('Failed optional check of commits diff; Skipping.')
148+
core.debug(utils.getErrorMessage(error))
149+
return false
150+
}
141151
}
142152

143153
function splitLines(multilineString: string): string[] {

0 commit comments

Comments
 (0)