fix: handle ambiguous argument failure on diff stat (#3312)

This commit is contained in:
Peter Evans 2024-09-05 09:23:05 +01:00 committed by GitHub
parent 6073f5434b
commit 8867c4aba1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 10 deletions

View file

@ -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<boolean> {
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[] {