fix: error detecting initial commits (#1181)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack
2023-05-26 10:48:32 -06:00
committed by GitHub
parent 88fb02bd31
commit 9ad1a5b96a
5 changed files with 39 additions and 29 deletions

View File

@@ -63,6 +63,7 @@ export interface DiffResult {
currentBranch: string
targetBranch: string
diff: string
initialCommit?: boolean
}
export const getSHAForPushEvent = async (
@@ -201,20 +202,15 @@ export const getSHAForPushEvent = async (
})
}
if (previousSha === currentSha) {
if (!(await getParentSha({cwd: workingDirectory}))) {
if (!previousSha || previousSha === currentSha) {
previousSha = await getParentSha({
cwd: workingDirectory
})
if (!previousSha) {
core.warning('Initial commit detected no previous commit found.')
initialCommit = true
previousSha = currentSha
} else {
previousSha = await getParentSha({
cwd: workingDirectory
})
}
} else {
if (!previousSha) {
core.error('Unable to locate a previous commit.')
throw new Error('Unable to locate a previous commit.')
}
}
}
@@ -241,7 +237,8 @@ export const getSHAForPushEvent = async (
currentSha,
currentBranch,
targetBranch,
diff
diff,
initialCommit
}
}