UNPKG

4.22 kBTypeScriptView Raw
1import { EventEmitter } from "events";
2
3import { Buf } from "./buf";
4import { Diff } from "./diff";
5import { Error } from "./error";
6import { Object } from "./object";
7import { Oid } from "./oid";
8import { Repository } from "./repository";
9import { Signature } from "./signature";
10import { Tree } from "./tree";
11import { TreeEntry } from "./tree-entry";
12
13export interface HistoryEventEmitter extends EventEmitter {
14 start(): void;
15}
16
17export class Commit {
18 static create(
19 repo: Repository,
20 updateRef: string,
21 author: Signature,
22 committer: Signature,
23 messageEncoding: string,
24 message: string,
25 tree: Tree,
26 parentCount: number,
27 parents: any[],
28 ): Oid;
29 static createV(
30 id: Oid,
31 repo: Repository,
32 updateRef: string,
33 author: Signature,
34 committer: Signature,
35 messageEncoding: string,
36 message: string,
37 tree: Tree,
38 parentCount: number,
39 ): number;
40 /**
41 * Retrieves the commit pointed to by the oid
42 */
43 static lookup(repo: Repository, id: string | Oid | Commit): Promise<Commit>;
44 static lookupPrefix(repo: Repository, id: Oid, len: number): Promise<Commit>;
45 static createWithSignature(
46 repo: Repository,
47 commitContent: string,
48 signature: string,
49 signatureField: string,
50 ): Promise<Oid>;
51
52 amend(
53 updateRef: string,
54 author: Signature,
55 committer: Signature,
56 messageEncoding: string,
57 message: string,
58 tree: Tree | Oid,
59 ): Promise<Oid>;
60 amendWithSignature(
61 updateRef: string,
62 author: Signature,
63 committer: Signature,
64 messageEncoding: string,
65 message: string,
66 tree: Tree | Oid,
67 onSignature: (
68 data: string,
69 ) =>
70 | Promise<{ code: Error.CODE; field?: string | undefined; signedData: string }>
71 | { code: Error.CODE; field?: string | undefined; signedData: string },
72 ): Promise<Oid>;
73 author(): Signature;
74 committer(): Signature;
75
76 headerField(field: string): Promise<Buf>;
77 id(): Oid;
78 message(): string;
79 messageEncoding(): string;
80 messageRaw(): string;
81 nthGenAncestor(n: number): Promise<Commit>;
82 owner(): Repository;
83 parent(n: number): Promise<Commit>;
84 parentId(n: number): Oid;
85 parentcount(): number;
86 rawHeader(): string;
87 summary(): string;
88 time(): number;
89 timeOffset(): number;
90 tree(treeOut: Tree): number;
91 treeId(): Oid;
92 /**
93 * Retrieve the SHA.
94 */
95 sha(): string;
96 /**
97 * Retrieve the commit time as a unix timestamp.
98 */
99 timeMs(): number;
100 /**
101 * Retrieve the commit time as a Date object.
102 */
103 date(): Date;
104 /**
105 * Get the tree associated with this commit.
106 */
107 getTree(): Promise<Tree>;
108 /**
109 * Retrieve the entry represented by path for this commit. Path must be relative to repository root.
110 */
111 getEntry(path: string): Promise<TreeEntry>;
112 /**
113 * Walk the history from this commit backwards.
114 * An EventEmitter is returned that will emit a "commit" event for each commit in the history, and one "end"
115 * event when the walk is completed. Don't forget to call start() on the returned EventEmitter.
116 */
117 history(): HistoryEventEmitter;
118 /**
119 * Retrieve the commit's parents as commit objects.
120 */
121 getParents(limit: number, callback?: Function): Promise<Commit[]>;
122 /**
123 * Retrieve the commit's parent shas.
124 */
125 parents(): Oid[];
126 /**
127 * Generate an array of diff trees showing changes between this commit and its parent(s).
128 */
129 getDiff(callback?: Function): Promise<Diff[]>;
130 /**
131 * Generate an array of diff trees showing changes between this commit and its parent(s).
132 */
133 getDiffWithOptions(options: Object, callback?: Function): Promise<Diff[]>;
134 /**
135 * The sha of this commit
136 */
137 toString(): string;
138 dup(): Promise<Commit>;
139 /**
140 * consists of a summary
141 */
142 body(): string;
143
144 getSignature(field?: string): Promise<{
145 signature: string;
146 signedData: string;
147 }>;
148}