tiny-commit-walker
Version:
tiny commit walker
115 lines (114 loc) • 3.39 kB
TypeScript
import { Commit } from './commit';
import { Packs } from "./pack";
export declare type REFS_DIR = 'heads' | 'tags' | 'remotes';
export declare type BRANCH_DIR = 'heads' | 'remotes';
export declare type StringMap = Map<string, string>;
export declare type RefMap = Map<string, Ref>;
export declare class Ref {
readonly name: string;
private _gitDir;
private _hash;
private _packs;
private _commit;
constructor(name: string, _gitDir: string, _hash: string, _packs: Packs);
readonly commit: Commit;
}
export interface HEAD {
readonly type: 'branch' | 'commit';
readonly branch?: Ref;
readonly commit?: Commit;
}
export declare class Repository {
readonly gitDir: string;
private _refs;
private _refMaps;
private _packs;
private _refsDir;
constructor(gitDir: string);
/**
* Find a git directory. This function find one from current or parents directories.
*/
static findGitDir(repositoryPath?: string): Promise<string | undefined>;
/**
* Find a git directory sync. This function find one from current or parents directories.
*/
static findGitDirSync(repositoryPath?: string): string | undefined;
private _initRefs();
private _initRefsSync();
private _initRefMaps();
/**
* Read a infomation of `.git/HEAD`.
*
* ```ts
* const head = repo.readHead();
* // if type is 'branch'
* console.log(head.type === 'branch');
* console.log(head.branch);
* // if type is 'commit'
* console.log(head.type === 'commit);
* console.log(head.branch);
* ```
*/
readHead(): Promise<HEAD>;
/**
* Read a infomation of `.git/HEAD` sync.
*/
readHeadSync(): HEAD;
private _readRefs(dir);
private _readRefsSync(dir);
private _findRef(dir, name);
private _readRef(dir, name);
private _readRefSync(dir, name);
/**
* Read branches.
*
* ```ts
* const heads = await repo.readBranches(); // or await repo.readBranches('heads');
* const remotes = await repo.readBranches('remotes');
* const allBranches = await repo.readBranches(['heads', 'remotes']);
* console.log(heads[0].name, heads[0].commit);
* ```
*/
readBranches(dirs?: BRANCH_DIR[] | BRANCH_DIR): Promise<Ref[]>;
/**
* Read branches sync.
*/
readBranchesSync(dirs?: BRANCH_DIR[] | BRANCH_DIR): Ref[];
/**
* Read a commit by branch name.
*
* ```ts
* const masterCommit = await repo.readCommitByBranch('master');
* const originMasterCommit = await repo.readCommitByBranch('origin/master');
* ```
*/
readCommitByBranch(branchName: string, scope?: BRANCH_DIR[] | BRANCH_DIR): Promise<Commit>;
/**
* Read a commit by branch name sync.
*/
readCommitByBranchSync(branchName: string, scope?: BRANCH_DIR[] | BRANCH_DIR): Commit;
/**
* Read tags.
*
* ```ts
* const tags = await repo.readTags();
* ```
*/
readTags(): Promise<Ref[]>;
/**
* Read tags sync.
*/
readTagsSync(): Ref[];
/**
* Read a commit by tag name.
*
* ```ts
* const commit = repo.readCommitByTag('v1.0');
* ```
*/
readCommitByTag(tagName: string): Promise<Commit>;
/**
* Read a commit by tag name sync.
*/
readCommitByTagSync(tagName: string): Commit;
}