fix: don't do git log on non-existent file

closes #4008
pull/4014/head
Divyansh Singh 6 months ago
parent d837e82bc8
commit 387acf71aa

@ -8,20 +8,24 @@ export function getGitTimestamp(file: string) {
const cached = cache.get(file) const cached = cache.get(file)
if (cached) return cached if (cached) return cached
if (!fs.existsSync(file)) return 0
return new Promise<number>((resolve, reject) => { return new Promise<number>((resolve, reject) => {
const cwd = dirname(file) const child = spawn(
if (!fs.existsSync(cwd)) return resolve(0) 'git',
const fileName = basename(file) ['log', '-1', '--pretty="%ai"', basename(file)],
const child = spawn('git', ['log', '-1', '--pretty="%ai"', fileName], { { cwd: dirname(file) }
cwd )
})
let output = '' let output = ''
child.stdout.on('data', (d) => (output += String(d))) child.stdout.on('data', (d) => (output += String(d)))
child.on('close', () => { child.on('close', () => {
const timestamp = +new Date(output) const timestamp = +new Date(output)
cache.set(file, timestamp) cache.set(file, timestamp)
resolve(timestamp) resolve(timestamp)
}) })
child.on('error', reject) child.on('error', reject)
}) })
} }

Loading…
Cancel
Save