Skip to content

Commit 387acf7

Browse files
committed
fix: don't do git log on non-existent file
closes #4008
1 parent d837e82 commit 387acf7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/node/utils/getGitTimestamp.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@ export function getGitTimestamp(file: string) {
88
const cached = cache.get(file)
99
if (cached) return cached
1010

11+
if (!fs.existsSync(file)) return 0
12+
1113
return new Promise<number>((resolve, reject) => {
12-
const cwd = dirname(file)
13-
if (!fs.existsSync(cwd)) return resolve(0)
14-
const fileName = basename(file)
15-
const child = spawn('git', ['log', '-1', '--pretty="%ai"', fileName], {
16-
cwd
17-
})
14+
const child = spawn(
15+
'git',
16+
['log', '-1', '--pretty="%ai"', basename(file)],
17+
{ cwd: dirname(file) }
18+
)
19+
1820
let output = ''
1921
child.stdout.on('data', (d) => (output += String(d)))
22+
2023
child.on('close', () => {
2124
const timestamp = +new Date(output)
2225
cache.set(file, timestamp)
2326
resolve(timestamp)
2427
})
28+
2529
child.on('error', reject)
2630
})
2731
}

0 commit comments

Comments
 (0)