Skip to content

Commit dba3ff5

Browse files
BioPhotonmatejchalk
authored andcommitted
fix: handle repos without git gracefully
1 parent dbc5b8d commit dba3ff5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/utils/src/lib/git/git.commits-and-tags.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
import { type LogOptions as SimpleGitLogOptions, simpleGit } from 'simple-git';
22
import { type Commit, commitSchema } from '@code-pushup/models';
3+
import { stringifyError } from '../errors.js';
4+
import { ui } from '../logging.js';
35
import { isSemver } from '../semver.js';
46

57
export async function getLatestCommit(
68
git = simpleGit(),
79
): Promise<Commit | null> {
8-
const log = await git.log({
9-
maxCount: 1,
10-
// git log -1 --pretty=format:"%H %s %an %aI" - See: https://git-scm.com/docs/pretty-formats
11-
format: { hash: '%H', message: '%s', author: '%an', date: '%aI' },
12-
});
13-
return commitSchema.parse(log.latest);
10+
try {
11+
const log = await git.log({
12+
maxCount: 1,
13+
// git log -1 --pretty=format:"%H %s %an %aI" - See: https://git-scm.com/docs/pretty-formats
14+
format: { hash: '%H', message: '%s', author: '%an', date: '%aI' },
15+
});
16+
return commitSchema.parse(log.latest);
17+
} catch (e) {
18+
ui().logger.error(stringifyError(e));
19+
return null;
20+
}
1421
}
1522

1623
export async function getCurrentBranchOrTag(

0 commit comments

Comments
 (0)