@@ -184,10 +184,129 @@ export interface RepositoryCloneOptions {
184184 recursive ?: boolean ;
185185 fetch ?: FetchOptions ;
186186}
187+ /** Creates a new repository in the specified folder. */
187188export declare function initRepository ( path : string , options ?: RepositoryInitOptions | undefined | null , signal ?: AbortSignal | undefined | null ) : Promise < Repository >
189+ /** Attempt to open an already-existing repository at `path`. */
188190export declare function openRepository ( path : string , options ?: RepositoryOpenOptions | undefined | null , signal ?: AbortSignal | undefined | null ) : Promise < Repository >
191+ /**
192+ * Attempt to open an already-existing repository at or above `path`
193+ *
194+ * This starts at `path` and looks up the filesystem hierarchy
195+ * until it finds a repository.
196+ */
189197export declare function discoverRepository ( path : string , signal ?: AbortSignal | undefined | null ) : Promise < Repository >
198+ /**
199+ * Clone a remote repository.
200+ *
201+ * This will use the options configured so far to clone the specified URL
202+ * into the specified local path.
203+ */
190204export declare function cloneRepository ( url : string , path : string , options ?: RepositoryCloneOptions | undefined | null , signal ?: AbortSignal | undefined | null ) : Promise < Repository >
205+ /** Flags for the Revspec. */
206+ export const enum RevparseMode {
207+ /** The spec targeted a single object (1 << 0) */
208+ Single = 1 ,
209+ /** The spec targeted a range of commits (1 << 1) */
210+ Range = 2 ,
211+ /** The spec used the `...` operator, which invokes special semantics. (1 << 2) */
212+ MergeBase = 4
213+ }
214+ /** Check revparse mode contains specific flags. */
215+ export declare function revparseModeContains ( source : number , target : number ) : boolean
216+ /** A revspec represents a range of revisions within a repository. */
217+ export interface Revspec {
218+ /** Access the `from` range of this revspec. */
219+ from ?: string
220+ /** Access the `to` range of this revspec. */
221+ to ?: string
222+ /** Returns the intent of the revspec. */
223+ mode : number
224+ }
225+ /**
226+ * A Signature is used to indicate authorship of various actions throughout the
227+ * library.
228+ *
229+ * Signatures contain a name, email, and timestamp.
230+ */
231+ export interface Signature {
232+ /** Name on the signature. */
233+ name : string
234+ /** Email on the signature. */
235+ email : string
236+ /** Time in seconds, from epoch */
237+ timestamp : number
238+ }
239+ export interface CreateSignatureOptions {
240+ /** Time in seconds, from epoch */
241+ timestamp : number
242+ /** Timezone offset, in minutes */
243+ offset ?: number
244+ }
245+ /** Create a new action signature. */
246+ export declare function createSignature ( name : string , email : string , options ?: CreateSignatureOptions | undefined | null ) : Signature
247+ /** An enumeration all possible kinds objects may have. */
248+ export const enum ObjectType {
249+ /** Any kind of git object */
250+ Any = 0 ,
251+ /** An object which corresponds to a git commit */
252+ Commit = 1 ,
253+ /** An object which corresponds to a git tree */
254+ Tree = 2 ,
255+ /** An object which corresponds to a git blob */
256+ Blob = 3 ,
257+ /** An object which corresponds to a git tag */
258+ Tag = 4
259+ }
260+ /** A structure to represent a git commit */
261+ export declare class Commit {
262+ /** Get the id (SHA1) of a repository commit */
263+ id ( ) : string
264+ /** Get the author of this commit. */
265+ author ( ) : Signature
266+ /** Get the committer of this commit. */
267+ committer ( ) : Signature
268+ /**
269+ * Get the full message of a commit.
270+ *
271+ * The returned message will be slightly prettified by removing any
272+ * potential leading newlines.
273+ *
274+ * Throws error if the message is not valid utf-8
275+ */
276+ message ( ) : string
277+ /**
278+ * Get the short "summary" of the git commit message.
279+ *
280+ * The returned message is the summary of the commit, comprising the first
281+ * paragraph of the message with whitespace trimmed and squashed.
282+ *
283+ * Throws error if the summary is not valid utf-8.
284+ */
285+ summary ( ) : string | null
286+ /**
287+ * Get the long "body" of the git commit message.
288+ *
289+ * The returned message is the body of the commit, comprising everything
290+ * but the first paragraph of the message. Leading and trailing whitespaces
291+ * are trimmed.
292+ *
293+ * Throws error if the summary is not valid utf-8.
294+ */
295+ body ( ) : string | null
296+ /**
297+ * Get the commit time (i.e. committer time) of a commit.
298+ *
299+ * The first element of the tuple is the time, in seconds, since the epoch.
300+ * The second element is the offset, in minutes, of the time zone of the
301+ * committer's preferred time zone.
302+ */
303+ time ( ) : Date
304+ }
305+ /**
306+ * A structure representing a [remote][1] of a git repository.
307+ *
308+ * [1]: http://git-scm.com/book/en/Git-Basics-Working-with-Remotes
309+ */
191310export declare class Remote {
192311 /**
193312 * Get the remote's name.
@@ -233,7 +352,32 @@ export declare class Remote {
233352 /** Get the remote’s default branch. */
234353 defaultBranch ( signal ?: AbortSignal | undefined | null ) : Promise < string >
235354}
355+ /**
356+ * An owned git repository, representing all state associated with the
357+ * underlying filesystem.
358+ *
359+ * This structure corresponds to a `git_repository` in libgit2.
360+ *
361+ * When a repository goes out of scope, it is freed in memory but not deleted
362+ * from the filesystem.
363+ */
236364export declare class Repository {
365+ /**
366+ * Lookup a reference to one of the commits in a repository.
367+ *
368+ * Returns `null` if the commit does not exist.
369+ */
370+ findCommit ( oid : string ) : Commit | null
371+ /** Lookup a reference to one of the commits in a repository. */
372+ getCommit ( oid : string ) : Commit
373+ /**
374+ * Lookup a reference to one of the objects in a repository.
375+ *
376+ * Returns `null` if the object does not exist.
377+ */
378+ findObject ( oid : string ) : GitObject | null
379+ /** Lookup a reference to one of the objects in a repository. */
380+ getObject ( oid : string ) : GitObject
237381 /** List all remotes for a given repository */
238382 remoteNames ( ) : Array < string >
239383 /**
@@ -246,11 +390,65 @@ export declare class Repository {
246390 findRemote ( name : string ) : Remote | null
247391 /** Add a remote with the default fetch refspec to the repository’s configuration. */
248392 createRemote ( name : string , url : string , options ?: CreateRemoteOptions | undefined | null ) : Remote
393+ /** Tests whether this repository is a bare repository or not. */
249394 isBare ( ) : boolean
395+ /** Tests whether this repository is a shallow clone. */
250396 isShallow ( ) : boolean
397+ /** Tests whether this repository is a worktree. */
251398 isWorktree ( ) : boolean
399+ /** Tests whether this repository is empty. */
252400 isEmpty ( ) : boolean
401+ /**
402+ * Returns the path to the `.git` folder for normal repositories or the
403+ * repository itself for bare repositories.
404+ */
253405 path ( ) : string
406+ /** Returns the current state of this repository */
254407 state ( ) : RepositoryState
408+ /**
409+ * Get the path of the working directory for this repository.
410+ *
411+ * If this repository is bare, then `null` is returned.
412+ */
255413 workdir ( ) : string | null
414+ /**
415+ * Execute a rev-parse operation against the `spec` listed.
416+ *
417+ * The resulting revision specification is returned, or an error is
418+ * returned if one occurs.
419+ */
420+ revparse ( spec : string ) : Revspec
421+ /** Find a single object, as specified by a revision string. */
422+ revparseSingle ( spec : string ) : string
423+ }
424+ /**
425+ * A structure to represent a git [object][1]
426+ *
427+ * [1]: http://git-scm.com/book/en/Git-Internals-Git-Objects
428+ */
429+ export declare class GitObject {
430+ /** Get the id (SHA1) of a repository object */
431+ id ( ) : string
432+ /**
433+ * Get the object type of object.
434+ *
435+ * If the type is unknown, then `null` is returned.
436+ */
437+ type ( ) : ObjectType | null
438+ /**
439+ * Recursively peel an object until an object of the specified type is met.
440+ *
441+ * If you pass `Any` as the target type, then the object will be
442+ * peeled until the type changes (e.g. a tag will be chased until the
443+ * referenced object is no longer a tag).
444+ */
445+ peel ( objType : ObjectType ) : GitObject
446+ /** Recursively peel an object until a commit is found */
447+ peelToCommit ( ) : Commit
448+ /**
449+ * Attempt to view this object as a commit.
450+ *
451+ * Returns `null` if the object is not actually a commit.
452+ */
453+ asCommit ( ) : Commit | null
256454}
0 commit comments