Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Ignore the git diff error for deleted files (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
leordev authored Oct 17, 2023
1 parent bc49716 commit 4d2d953
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getFilesDiffs = async (): Promise<FilesDiffsMap> => {
const filesDiffsMap: FilesDiffsMap = {}

for (const file of diffSummary.files) {
const fileDiffs = await git.diff(['-U0', targetShaOrRef, file.file])
const fileDiffs = await getFileDiffs(targetShaOrRef, file.file)

const changedLines: GitDiffs[] = fileDiffs
.split('\n')
Expand Down Expand Up @@ -75,6 +75,23 @@ export const getFilesDiffs = async (): Promise<FilesDiffsMap> => {
return filesDiffsMap
}

const getFileDiffs = async (
targetShaOrRef: string,
filePath: string
): Promise<string> => {
try {
const diffs = await git.diff(['-U0', targetShaOrRef, filePath])
return diffs
} catch (error) {
if ((error as Error).message?.includes('path not in the working tree')) {
// file was removed, no diffs to be parsed
return ''
} else {
throw error
}
}
}

export const isSourceInChangedScope = (
filesDiffs: FilesDiffsMap,
sourceFilePath: string,
Expand Down

0 comments on commit 4d2d953

Please sign in to comment.