MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / getLatestCommitTimestamp

Function getLatestCommitTimestamp

packages/backend/src/git.ts:433–461  ·  view source on GitHub ↗
({
    path,
}: {
    path: string,
})

Source from the content-addressed store, hash-verified

431 * is empty or if there's an error retrieving the timestamp.
432 */
433export 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.

Callers 1

onJobCompletedMethod · 0.85

Calls 1

createGitClientForPathFunction · 0.85

Tested by

no test coverage detected