({
path,
}: {
path: string,
})
| 431 | * is empty or if there's an error retrieving the timestamp. |
| 432 | */ |
| 433 | export const getLatestCommitTimestamp = async ({ |
| 434 | path, |
| 435 | }: { |
| 436 | path: string, |
| 437 | }): Promise<Date | undefined> => { |
| 438 | const git = createGitClientForPath(path); |
| 439 | |
| 440 | try { |
| 441 | // git log --all -1 --format=%aI returns the author date of the most recent commit |
| 442 | // across all branches in ISO 8601 format |
| 443 | const result = await git.raw(['log', '--all', '-1', '--format=%aI']); |
| 444 | const trimmed = result.trim(); |
| 445 | |
| 446 | if (!trimmed) { |
| 447 | return undefined; // Empty repository |
| 448 | } |
| 449 | |
| 450 | const date = new Date(trimmed); |
| 451 | if (isNaN(date.getTime())) { |
| 452 | logger.warn(`Failed to parse commit timestamp: ${trimmed}`); |
| 453 | return undefined; |
| 454 | } |
| 455 | |
| 456 | return date; |
| 457 | } catch (error) { |
| 458 | logger.debug(`Failed to get latest commit timestamp for ${path}:`, error); |
| 459 | return undefined; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * Returns true if the git repository at the given path has no commits. |
no test coverage detected