UNPKG

10.3 kBTypeScriptView Raw
1import { AnnotatedCommit } from './annotated-commit';
2import { Blob } from './blob';
3import { CheckoutOptions } from './checkout-options';
4import { Commit } from './commit';
5import { Config } from './config';
6import { DiffLine } from './diff-line';
7import { Error } from './error';
8import { FetchOptions } from './fetch-options';
9import { Index } from './index_';
10import { Merge } from './merge';
11import { MergeOptions } from './merge-options';
12import { Odb } from './odb';
13import { Oid } from './oid';
14import { Refdb } from './ref-db';
15import { Reference } from './reference';
16import { Remote } from './remote';
17import { Revwalk } from './rev-walk';
18import { Signature } from './signature';
19import { StatusFile } from './status-file';
20import { StatusOptions } from './status-options';
21import { Submodule } from './submodule';
22import { Tag } from './tag';
23import { Tree } from './tree';
24import { Treebuilder } from './tree-builder';
25import { Worktree } from './worktree';
26
27export interface RepositoryInitOptions {
28 description?: string;
29 flags?: number;
30 initialHead?: string;
31 mode?: number;
32 originUrl?: string;
33 templatePath?: string;
34 version?: number;
35 workdirPath?: string;
36}
37
38export class Repository {
39 /**
40 * Creates a branch with the passed in name pointing to the commit
41 */
42 static discover(startPath: string, acrossFs: number, ceilingDirs: string): Promise<string>;
43 static init(path: string, isBare: number): Promise<Repository>;
44 static initExt(repoPath: string, options?: RepositoryInitOptions): Promise<Repository>;
45 static open(path: string): Promise<Repository>;
46 static openBare(barePath: string): Promise<Repository>;
47 static openExt(path: string, flags?: number, ceilingDirs?: string): Promise<Repository>;
48 static openFromWorktree(wt: Worktree): Promise<Repository>;
49 static wrapOdb(odb: Odb): Promise<Repository>;
50
51 cleanup(): Promise<void>;
52 commondir(): string;
53 config(): Promise<Config>;
54 configSnapshot(): Promise<Config>;
55 detachHead(): number;
56 fetchheadForeach(callback?: Function): Promise<any>;
57
58 free(): void;
59 getNamespace(): string;
60 getSubmodules(): Promise<Submodule[]>;
61 head(): Promise<Reference>;
62 headDetached(): number;
63 headUnborn(): number;
64 index(): Promise<Index>;
65 isBare(): number;
66 isEmpty(): number;
67 isShallow(): number;
68 itemPath(item: number): Promise<string>;
69 mergeheadForeach(callback?: Function): Promise<any>;
70 messageRemove(): number;
71 odb(): Promise<Odb>;
72 path(): string;
73 refdb(): Promise<Refdb>;
74 refreshReferences(): Promise<void>;
75 setHead(refname: string): Promise<number>;
76 setHeadDetached(commitish: Oid): number;
77 setHeadDetachedFromAnnotated(commitish: AnnotatedCommit): number;
78 setIdent(name: string, email: string): number;
79 setNamespace(nmspace: string): number;
80 setWorkdir(workdir: string, updateGitLink: number): number;
81 state(): number;
82 stateCleanup(): number;
83 workdir(): string;
84 /**
85 * Creates a branch with the passed in name pointing to the commit
86 */
87 createBranch(name: string, commit: Commit | string | Oid, force?: boolean): Promise<Reference>;
88 /**
89 * Look up a refs's commit.
90 */
91 getReferenceCommit(name: string | Reference): Promise<Commit>;
92 /**
93 * Look up a branch. Alias for getReference
94 */
95 getBranch(name: string | Reference): Promise<Reference>;
96 /**
97 * Look up a branch's most recent commit. Alias to getReferenceCommit
98 */
99 getBranchCommit(name: string | Reference): Promise<Commit>;
100 /**
101 * Gets the branch that HEAD currently points to Is an alias to head()
102 */
103 getCurrentBranch(): Promise<Reference>;
104 /**
105 * Lookup the reference with the given name.
106 */
107 getReference(name: string | Reference): Promise<Reference>;
108 /**
109 * Lookup references for a repository.
110 */
111 getReferences(): Promise<Reference[]>;
112 /**
113 * Lookup reference names for a repository.
114 */
115 getReferenceNames(type: Reference.TYPE): Promise<string[]>;
116 getCommit(string: string | Commit | Oid): Promise<Commit>;
117 /**
118 * Retrieve the blob represented by the oid.
119 */
120 getBlob(string: string | Oid): Promise<Blob>;
121 /**
122 * Retrieve the tree represented by the oid.
123 */
124 getTree(string: string | Oid): Promise<Tree>;
125 createTag(string: string | Oid, name: string, message: string): Promise<Tag>;
126 /**
127 * Creates a new lightweight tag
128 */
129 createLightweightTag(string: string | Oid, name: string): Promise<Reference>;
130 /**
131 * Retrieve the tag represented by the oid.
132 */
133 getTag(string: string | Oid): Promise<Tag>;
134 /**
135 * Retrieve the tag represented by the tag name.
136 */
137 getTagByName(Short: string): Promise<Tag>;
138 /**
139 * Deletes a tag from a repository by the tag name.
140 */
141 deleteTagByName(Short: string): Promise<number>;
142 /**
143 * Instantiate a new revision walker for browsing the Repository"s history. See also Commit.prototype.history()
144 */
145 createRevWalk(): Revwalk;
146 /**
147 * Retrieve the master branch commit.
148 */
149 getMasterCommit(): Promise<Commit>;
150 /**
151 * Retrieve the commit that HEAD is currently pointing to
152 */
153 getHeadCommit(): Promise<Commit>;
154 createCommit(
155 updateRef: string,
156 author: Signature,
157 committer: Signature,
158 message: string,
159 Tree: Tree | Oid | string,
160 parents: Array<string | Commit | Oid>,
161 callback?: Function,
162 ): Promise<Oid>;
163 createCommitWithSignature(
164 updateRef: string,
165 author: Signature,
166 committer: Signature,
167 message: string,
168 Tree: Tree | Oid | string,
169 parents: Array<string | Commit | Oid>,
170 onSignature: (
171 data: string,
172 ) =>
173 | Promise<{ code: Error.CODE; field?: string | undefined; signedData: string }>
174 | { code: Error.CODE; field?: string | undefined; signedData: string },
175 ): Promise<Oid>;
176 /**
177 * Creates a new commit on HEAD from the list of passed in files
178 */
179 createCommitOnHead(filesToAdd: string[], author: Signature, committer: Signature, message: string): Promise<Oid>;
180 /**
181 * Create a blob from a buffer
182 */
183 createBlobFromBuffer(buffer: Buffer): Promise<Oid>;
184 treeBuilder(tree: Tree): Promise<Treebuilder>;
185 /**
186 * Gets the default signature for the default user and now timestamp
187 */
188 defaultSignature(): Signature;
189 /**
190 * Lists out the names of remotes in the given repository.
191 */
192 getRemoteNames(): Promise<string[]>;
193 /**
194 * Lists out the remotes in the given repository.
195 */
196 getRemotes(callback?: Function): Promise<Remote[]>;
197 /**
198 * Gets a remote from the repo
199 */
200 getRemote(remote: string | Remote, callback?: Function): Promise<Remote>;
201 /**
202 * Fetches from a remote
203 */
204 fetch(remote: string | Remote, fetchOptions?: FetchOptions): Promise<void>;
205 /**
206 * Fetches from all remotes. This is done in series due to deadlocking issues with fetching from many remotes that can happen.
207 */
208 fetchAll(fetchOptions?: FetchOptions, callback?: Function): Promise<void>;
209 mergeBranches(
210 to: string | Reference,
211 from: string | Reference,
212 signature?: Signature,
213 mergePreference?: Merge.PREFERENCE,
214 mergeOptions?: MergeOptions,
215 ): Promise<Oid>;
216 /**
217 * Rebases a branch onto another branch
218 */
219 rebaseBranches(
220 branch: string,
221 upstream: string,
222 onto: string,
223 signature: Signature,
224 beforeNextFn: Function,
225 ): Promise<Oid>;
226 continueRebase(signature: Signature, beforeNextFn: Function): Promise<Oid>;
227 /**
228 * Get the status of a repo to it's working directory
229 */
230 getStatus(opts?: StatusOptions): Promise<StatusFile[]>;
231 /**
232 * Get extended statuses of a repo to it's working directory. Status entries have status, headToIndex delta, and indexToWorkdir deltas
233 */
234 getStatusExt(opts?: StatusOptions): Promise<StatusFile[]>;
235 /**
236 * Get the names of the submodules in the repository.
237 */
238 getSubmoduleNames(): Promise<string[]>;
239 /**
240 * This will set the HEAD to point to the reference and then attempt to update the index and working tree to match the content of the latest commit on that reference
241 */
242 checkoutRef(reference: Reference, opts?: CheckoutOptions): Promise<Reference>;
243 /**
244 * This will set the HEAD to point to the local branch and then attempt to update the index and working tree to match the content of the latest commit on that branch
245 */
246 checkoutBranch(branch: string | Reference, opts?: CheckoutOptions): Promise<Reference>;
247 /**
248 * Stages or unstages line selection of a specified file
249 */
250 stageFilemode(filePath: string | string[], stageNew: boolean): Promise<number>;
251 /**
252 * Stages or unstages line selection of a specified file
253 */
254 stageLines(filePath: string, newLines: DiffLine[], isStaged: boolean): Promise<number>;
255 /**
256 * Returns true if the repository is in the default NONE state.
257 */
258 isDefaultState(): boolean;
259 /**
260 * Returns true if the repository is in the APPLY_MAILBOX or APPLY_MAILBOX_OR_REBASE state.
261 */
262 isApplyingMailbox(): boolean;
263 /**
264 * Returns true if the repository is in the BISECT state.
265 */
266 isBisecting(): boolean;
267 /**
268 * Returns true if the repository is in the CHERRYPICK state.
269 */
270 isCherrypicking(): boolean;
271 /**
272 * Returns true if the repository is in the MERGE state.
273 */
274 isMerging(): boolean;
275 /**
276 * Returns true if the repository is in the REBASE, REBASE_INTERACTIVE, or REBASE_MERGE state.
277 */
278 isRebasing(): boolean;
279 /**
280 * Returns true if the repository is in the REVERT state.
281 */
282 isReverting(): boolean;
283 /**
284 * Discard line selection of a specified file. Assumes selected lines are unstaged.
285 */
286 discardLines(filePath: string, selectedLines: DiffLine[]): Promise<number>;
287 /**
288 * Grabs a fresh copy of the index from the repository. Invalidates all previously grabbed indexes
289 */
290 refreshIndex(): Promise<Index>;
291}