Skip to content

Commit

Permalink
feat: add option to exclude submodules when detecting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Apr 17, 2024
1 parent 82edce4 commit b4af382
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ export const processChangedFiles = async ({
export const getRenamedFiles = async ({
inputs,
workingDirectory,
hasSubmodule,
diffSubmodule,
diffResult,
submodulePaths
}: {
inputs: Inputs
workingDirectory: string
hasSubmodule: boolean
diffSubmodule: boolean
diffResult: DiffResult
submodulePaths: string[]
}): Promise<{paths: string; count: string}> => {
Expand All @@ -139,7 +139,7 @@ export const getRenamedFiles = async ({
oldNewSeparator: inputs.oldNewSeparator
})

if (hasSubmodule) {
if (diffSubmodule) {
for (const submodulePath of submodulePaths) {
const submoduleShaResult = await gitSubmoduleDiffSHA({
cwd: workingDirectory,
Expand Down Expand Up @@ -217,7 +217,7 @@ export type ChangedFiles = {

export const getAllDiffFiles = async ({
workingDirectory,
hasSubmodule,
diffSubmodule,
diffResult,
submodulePaths,
outputRenamedFilesAsDeletedAndAdded,
Expand All @@ -226,7 +226,7 @@ export const getAllDiffFiles = async ({
failOnSubmoduleDiffError
}: {
workingDirectory: string
hasSubmodule: boolean
diffSubmodule: boolean
diffResult: DiffResult
submodulePaths: string[]
outputRenamedFilesAsDeletedAndAdded: boolean
Expand All @@ -243,7 +243,7 @@ export const getAllDiffFiles = async ({
failOnInitialDiffError
})

if (hasSubmodule) {
if (diffSubmodule) {
for (const submodulePath of submodulePaths) {
const submoduleShaResult = await gitSubmoduleDiffSHA({
cwd: workingDirectory,
Expand Down
16 changes: 8 additions & 8 deletions src/commitSha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ interface SHAForNonPullRequestEvent {
env: Env
workingDirectory: string
isShallow: boolean
hasSubmodule: boolean
diffSubmodule: boolean
gitFetchExtraArgs: string[]
isTag: boolean
remoteName: string
Expand All @@ -102,7 +102,7 @@ export const getSHAForNonPullRequestEvent = async ({
env,
workingDirectory,
isShallow,
hasSubmodule,
diffSubmodule,
gitFetchExtraArgs,
isTag,
remoteName
Expand Down Expand Up @@ -152,7 +152,7 @@ export const getSHAForNonPullRequestEvent = async ({
})
}

if (hasSubmodule) {
if (diffSubmodule) {
await gitFetchSubmodules({
cwd: workingDirectory,
args: [
Expand All @@ -164,7 +164,7 @@ export const getSHAForNonPullRequestEvent = async ({
})
}
} else {
if (hasSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
if (diffSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
await gitFetchSubmodules({
cwd: workingDirectory,
args: [
Expand Down Expand Up @@ -323,7 +323,7 @@ interface SHAForPullRequestEvent {
inputs: Inputs
workingDirectory: string
isShallow: boolean
hasSubmodule: boolean
diffSubmodule: boolean
gitFetchExtraArgs: string[]
remoteName: string
}
Expand All @@ -332,7 +332,7 @@ export const getSHAForPullRequestEvent = async ({
inputs,
workingDirectory,
isShallow,
hasSubmodule,
diffSubmodule,
gitFetchExtraArgs,
remoteName
}: SHAForPullRequestEvent): Promise<DiffResult> => {
Expand Down Expand Up @@ -390,7 +390,7 @@ export const getSHAForPullRequestEvent = async ({
]
})

if (hasSubmodule) {
if (diffSubmodule) {
await gitFetchSubmodules({
cwd: workingDirectory,
args: [
Expand All @@ -403,7 +403,7 @@ export const getSHAForPullRequestEvent = async ({
}
}
} else {
if (hasSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
if (diffSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
await gitFetchSubmodules({
cwd: workingDirectory,
args: [
Expand Down
18 changes: 9 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ const getChangedFilesFromLocalGitHistory = async ({
}

const isShallow = await isRepoShallow({cwd: workingDirectory})
let hasSubmodule = false
let diffSubmodule = false
let gitFetchExtraArgs = ['--no-tags', '--prune']

if (inputs.excludeSubmodules) {
core.info('Excluding submodules from the diff')
} else {
hasSubmodule = await submoduleExists({cwd: workingDirectory})
diffSubmodule = await submoduleExists({cwd: workingDirectory})
}

if (hasSubmodule) {
if (diffSubmodule) {
gitFetchExtraArgs.push('--recurse-submodules')
}

Expand All @@ -83,7 +83,7 @@ const getChangedFilesFromLocalGitHistory = async ({
inputs.outputRenamedFilesAsDeletedAndAdded
let submodulePaths: string[] = []

if (hasSubmodule) {
if (diffSubmodule) {
submodulePaths = await getSubmodulePath({cwd: workingDirectory})
}

Expand All @@ -100,7 +100,7 @@ const getChangedFilesFromLocalGitHistory = async ({
env,
workingDirectory,
isShallow,
hasSubmodule,
diffSubmodule,
gitFetchExtraArgs,
isTag,
remoteName
Expand All @@ -115,7 +115,7 @@ const getChangedFilesFromLocalGitHistory = async ({
inputs,
workingDirectory,
isShallow,
hasSubmodule,
diffSubmodule,
gitFetchExtraArgs,
remoteName
})
Expand All @@ -133,7 +133,7 @@ const getChangedFilesFromLocalGitHistory = async ({

const allDiffFiles = await getAllDiffFiles({
workingDirectory,
hasSubmodule,
diffSubmodule,
diffResult,
submodulePaths,
outputRenamedFilesAsDeletedAndAdded,
Expand All @@ -159,7 +159,7 @@ const getChangedFilesFromLocalGitHistory = async ({
deletedFiles: allDiffFiles[ChangeTypeEnum.Deleted],
recoverPatterns,
diffResult,
hasSubmodule,
diffSubmodule,
submodulePaths
})
}
Expand All @@ -177,7 +177,7 @@ const getChangedFilesFromLocalGitHistory = async ({
const allOldNewRenamedFiles = await getRenamedFiles({
inputs,
workingDirectory,
hasSubmodule,
diffSubmodule,
diffResult,
submodulePaths
})
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1413,15 +1413,15 @@ export const recoverDeletedFiles = async ({
deletedFiles,
recoverPatterns,
diffResult,
hasSubmodule,
diffSubmodule,
submodulePaths
}: {
inputs: Inputs
workingDirectory: string
deletedFiles: string[]
recoverPatterns: string[]
diffResult: DiffResult
hasSubmodule: boolean
diffSubmodule: boolean
submodulePaths: string[]
}): Promise<void> => {
let recoverableDeletedFiles = deletedFiles
Expand Down Expand Up @@ -1451,7 +1451,7 @@ export const recoverDeletedFiles = async ({

const submodulePath = submodulePaths.find(p => deletedFile.startsWith(p))

if (hasSubmodule && submodulePath) {
if (diffSubmodule && submodulePath) {
const submoduleShaResult = await gitSubmoduleDiffSHA({
cwd: workingDirectory,
parentSha1: diffResult.previousSha,
Expand Down

0 comments on commit b4af382

Please sign in to comment.