Skip to content

Commit

Permalink
avoid collecting git metadata if not a repository
Browse files Browse the repository at this point in the history
  • Loading branch information
souporserious committed Apr 16, 2024
1 parent 94fd7fe commit 635de6c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-parrots-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mdxts": patch
---

Bail early if not a git repository to avoid printing git errors when not initialized yet.
16 changes: 11 additions & 5 deletions packages/mdxts/src/utils/get-git-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { execSync } from 'node:child_process'

let hasCheckedIfShallow = false
let hadGitError = false

/** Returns aggregated metadata about multiple files from git history. */
export function getGitMetadata(filePaths: string[]) {
Expand All @@ -26,11 +27,16 @@ export function getGitMetadata(filePaths: string[]) {

hasCheckedIfShallow = true
} catch {
return {
authors: [],
createdAt: undefined,
updatedAt: undefined,
}
hadGitError = true
}
}

/** Bail early if the repository is shallow cloned or there was a git error (e.g. not a git repository). */
if (hadGitError) {
return {
authors: [],
createdAt: undefined,
updatedAt: undefined,
}
}

Expand Down

0 comments on commit 635de6c

Please sign in to comment.