mirror of
https://github.com/tj-actions/changed-files
synced 2024-12-17 13:47:20 +00:00
feat: improve checking local branch history (#1436)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
1e9cd5f299
commit
d4e6e22e93
3 changed files with 53 additions and 5 deletions
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
52
src/utils.ts
52
src/utils.ts
|
@ -786,9 +786,17 @@ export const canDiffCommits = async ({
|
|||
sha2: string
|
||||
diff: string
|
||||
}): Promise<boolean> => {
|
||||
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',
|
||||
['diff', '--name-only', '--ignore-submodules=all', `${sha1}${diff}${sha2}`],
|
||||
['log', '--format=%H', `${mergeBase}..${sha2}`],
|
||||
{
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
|
@ -797,11 +805,51 @@ export const canDiffCommits = async ({
|
|||
)
|
||||
|
||||
if (exitCode !== 0) {
|
||||
core.warning(stderr || `Unable find merge base between ${sha1} and ${sha2}`)
|
||||
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<string | null> => {
|
||||
const {exitCode, stdout} = await exec.getExecOutput(
|
||||
'git',
|
||||
['merge-base', sha1, sha2],
|
||||
{
|
||||
cwd,
|
||||
ignoreReturnCode: true,
|
||||
silent: !core.isDebug()
|
||||
}
|
||||
)
|
||||
|
||||
if (exitCode !== 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
return stdout.trim()
|
||||
}
|
||||
|
||||
export const getDirnameMaxDepth = ({
|
||||
|
|
Loading…
Reference in a new issue