Interface Repo

Index

Methods

Methods

public fetch(remote: Remote, opts: Object, callback: (err: any) => void)

Convenience wrapper that fetches from a remote instance and calls repo.unpack with the resulting packfile stream for you.

Parameters

  • remote: Remote
  • opts: Object
  • callback: (err: any) => void

public getHead(callback: (err: any, ref_name: string) => void)

Read the current active branch.

Parameters

  • callback: (err: any, ref_name: string) => void

public load(hashish: string, callback: (err: any, git_object: JSGit.GitObject) => void)

Load a git object from the database. You can pass in either a hash or a symbolic name like HEAD or refs/tags/v3.1.4.

The object will be of the form: { type: "commit", // Or "tag", "tree", or "blob" body: { ... } // Or an array for tree and a binary value for blob. }

Parameters

  • hashish: string
  • callback: (err: any, git_object: JSGit.GitObject) => void

public loadAs(type: string, hash: string, callback: (err: any, body: any) => void)

This convenience wrapper will call repo.load for you and then check if the type is what you expected. If it is, it will return the body directly. If it's not, it will error.

var commit = yield repo.loadAs("commit", "HEAD"); var tree = yield repo.loadAs("tree", commit.tree);

I'm using yield syntax because it's simpler, you can use callbacks instead if you prefer.

Parameters

  • type: string
  • hash: string
  • callback: (err: any, body: any) => void

public logWalk(hashish: string, callback: (err: any, log_stream: any) => void)

This convenience wrapper creates a readable stream of the history sorted by author date. If you want full history, pass in HEAD for the hash.

Parameters

  • hashish: string
  • callback: (err: any, log_stream: any) => void

public remove(hash: string, callback: (err: any) => void)

Remove an object.

Parameters

  • hash: string
  • callback: (err: any) => void

public resolveHashish(hashish: string, callback: (err: any, hash: string) => void)

Resolve a ref, branch, or tag to a real hash.

Parameters

  • hashish: string
  • callback: (err: any, hash: string) => void

public save(git_object: GitObject, callback: (err: any, hash: string) => void)

Save an object to the database. This will give you back the hash of the cotent by which you can retrieve the value back.

Parameters

  • git_object: GitObject
  • callback: (err: any, hash: string) => void

public saveAs(type: string, body: any, callback: (err: any, hash: string) => void)

Another convenience wrapper, this time to save objects as a specefic type. The body must be in the right format.

var blobHash = yield repo.saveAs("blob", binaryData); var treeHash = yield repo.saveAs("tree", [ { mode: 0100644, name: "file.dat", hash: blobHash } ]); var commitHash = yield repo.saveAs("commit", { tree: treeHash, author: { name: "Tim Caswell", email: "tim@creationix.com", date: new Date }, message: "Save the blob" });

Parameters

  • type: string
  • body: any
  • callback: (err: any, hash: string) => void

public setHead(ref: string, callback: (err: any) => void)

Set the current active branch.

Parameters

  • ref: string
  • callback: (err: any) => void

public treeWalk(hashish: string, callback: (err: any, file_stream: any) => void)

This helper will return a stream of files suitable for traversing a file tree as a linear stream. The hash can be a ref to a commit, a commit hash or a tree hash directly.

Parameters

  • hashish: string
  • callback: (err: any, file_stream: any) => void

public unpack(packFileStream: any, opts: Object, callback: (err: any) => void)

Import a packfile stream (simple-stream format) into the current database. This is used mostly for clone and fetch operations where the stream comes from a remote repo.

opts is a hash of optional configs.

opts.onProgress(progress) - listen to the git progress channel by passing in a event listener. opts.onError(error) - same thing, but for the error channel. opts.deline - If this is truthy, the progress and error messages will be rechunked to be whole lines. They usually come jumbled in the internal sidechannel.

Parameters

  • packFileStream: any
  • opts: Object
  • callback: (err: any) => void

public updateHead(hash: string, callback: (err: any) => void)

Update whatever branch HEAD is pointing to so that it points to hash. You'll usually want to do this after creating a new commint in the HEAD branch.

Parameters

  • hash: string
  • callback: (err: any) => void

public walk(seed: any, scan: any, loadKey: any, compare: any): any

This is the generic helper that logWalk and treeWalk use. See js-git.js source for usage.

Parameters

  • seed: any
  • scan: any
  • loadKey: any
  • compare: any

Returns

any