Skip to content

Commit 3465b57

Browse files
committed
Do not error on empty git repo
1 parent c77603d commit 3465b57

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

npm-app/src/utils/git.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { execFileSync } from 'child_process'
22
import fs, { existsSync, statSync } from 'fs'
33
import gitUrlParse from 'git-url-parse'
4-
import { getConfig, listFiles, log } from 'isomorphic-git'
4+
import { getConfig, listFiles, log, ReadCommitResult } from 'isomorphic-git'
55
import path from 'path'
66
import { getWorkingDirectory } from '../project-files'
77
import { logger } from './logger'
@@ -78,7 +78,15 @@ export async function getRepoMetrics(providedRemoteUrl?: string): Promise<{
7878

7979
const gitDir = path.join(root, '.git')
8080

81-
const commitsArr = await log({ fs, dir: root, gitdir: gitDir })
81+
const commitsArr = await log({ fs, dir: root, gitdir: gitDir }).catch(
82+
(error) => {
83+
logger.error(
84+
{ error },
85+
'Error fetching git log. Is this an empty git repo?'
86+
)
87+
return [] as ReadCommitResult[]
88+
}
89+
)
8290
const firstCommit = commitsArr.at(-1) // earliest
8391

8492
const tracked = await listFiles({ fs, dir: root, gitdir: gitDir })

0 commit comments

Comments
 (0)