Repository
Usage
import { Repository } from '@napi-rs/simple-git'
Repository.init('/path/to/repo')
const repo = new Repository('/path/to/repo')
const timestamp = new Date(repo.getFileLatestModifiedDate('build.rs'))
console.log(timestamp)
const timestampFromAsync = new Date(await repo.getFileLatestModifiedDateAsync('build.rs'))
console.log(timestamp)
API
export class Repository {
static init(p: string): Repository
constructor(gitDir: string)
head(): Reference
getFileLatestModifiedDate(filepath: string): number
getFileLatestModifiedDateAsync(filepath: string, signal?: AbortSignal | undefined | null): Promise<unknown>
}
Reference
Usage
import { Repository } from '@napi-rs/simple-git'
const repo = new Repository('/path/to/repo')
const headReference = repo.head()
headReference.shorthand()
headReference.name()
headReference.target()
API
export const enum ReferenceType {
Direct = 0,
Symbolic = 1,
Unknown = 2
}
export class Reference {
static isValidName(name: string): boolean
isBranch(): boolean
isNote(): boolean
isRemote(): boolean
isTag(): boolean
kind(): ReferenceType
name(): string | undefined | null
shorthand(): string | undefined | null
target(): string | undefined | null
targetPeel(): string | undefined | null
symbolicTarget(): string | undefined | null
}
Performance
Compared with the exec
function, which gets the file's latest modified date by spawning a child process. Getting the latest modified date from the file 1000 times:
Child process took 1.9s
@napi-rs/simple-git took 65ms