2023-05-25 06:20:57 -04:00
|
|
|
import type {
|
|
|
|
FileDiff,
|
|
|
|
FileRemoved,
|
|
|
|
FileRenamed,
|
|
|
|
FileWithEditable,
|
|
|
|
} from '../services/types/file'
|
2023-04-27 14:45:13 -04:00
|
|
|
|
|
|
|
export function isFileRenamed(fileDiff: FileDiff): fileDiff is FileRenamed {
|
|
|
|
return (fileDiff as FileRenamed).operation === 'renamed'
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isFileRemoved(fileDiff: FileDiff): fileDiff is FileRemoved {
|
|
|
|
return (fileDiff as FileRemoved).operation === 'removed'
|
|
|
|
}
|
2023-05-16 04:17:57 -04:00
|
|
|
|
2023-05-25 06:20:57 -04:00
|
|
|
function isFileWithEditable(fileDiff: FileDiff): fileDiff is FileWithEditable {
|
|
|
|
return 'editable' in (fileDiff as FileWithEditable)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isFileEditable(fileDiff: FileDiff) {
|
|
|
|
return isFileWithEditable(fileDiff)
|
|
|
|
? fileDiff.editable
|
|
|
|
: fileDiff.operation === 'edited'
|
|
|
|
}
|
|
|
|
|
2023-05-16 04:17:57 -04:00
|
|
|
export function fileFinalPathname(fileDiff: FileDiff) {
|
2023-05-25 06:20:57 -04:00
|
|
|
return (
|
|
|
|
(isFileRenamed(fileDiff) ? fileDiff.newPathname : null) || fileDiff.pathname
|
|
|
|
)
|
2023-05-16 04:17:57 -04:00
|
|
|
}
|