diff --git a/dist/index.js b/dist/index.js index 84f31c3b..d38ab569 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/dist/index.js.map b/dist/index.js.map index ce2ebca1..fc1cfdde 100644 Binary files a/dist/index.js.map and b/dist/index.js.map differ diff --git a/src/utils.ts b/src/utils.ts index c57ba838..477e5a44 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -786,9 +786,58 @@ export const canDiffCommits = async ({ sha2: string diff: string }): Promise => { - const {exitCode, stderr} = await exec.getExecOutput( + if (diff === '...') { + const mergeBase = await getMergeBase(cwd, sha1, sha2) + + if (!mergeBase) { + core.warning(`Unable to find merge base between ${sha1} and ${sha2}`) + return false + } + + const {exitCode, stderr} = await exec.getExecOutput( + 'git', + ['log', '--format=%H', `${mergeBase}..${sha2}`], + { + cwd, + ignoreReturnCode: true, + silent: !core.isDebug() + } + ) + + if (exitCode !== 0) { + core.warning(stderr || `Error checking commit history`) + return false + } + + return true + } else { + const {exitCode, stderr} = await exec.getExecOutput( + 'git', + ['diff', '--quiet', sha1, sha2], + { + cwd, + ignoreReturnCode: true, + silent: !core.isDebug() + } + ) + + if (exitCode !== 0) { + core.warning(stderr || `Error checking commit history`) + return false + } + + return true + } +} + +const getMergeBase = async ( + cwd: string, + sha1: string, + sha2: string +): Promise => { + const {exitCode, stdout} = await exec.getExecOutput( 'git', - ['diff', '--name-only', '--ignore-submodules=all', `${sha1}${diff}${sha2}`], + ['merge-base', sha1, sha2], { cwd, ignoreReturnCode: true, @@ -797,11 +846,10 @@ export const canDiffCommits = async ({ ) if (exitCode !== 0) { - core.warning(stderr || `Unable find merge base between ${sha1} and ${sha2}`) - return false + return null } - return true + return stdout.trim() } export const getDirnameMaxDepth = ({