Class: PromisedGit

Class Name PromisedGit
Superclass Object
File src/promised-git.coffee

Description

Main class. Instances represent the whole git repository.

You must provide a valid working directory to the constructor.

Example

Git = require 'promised-git'
git = new Git('/tmp/exampleRepo')
# Add all unstaged files to the index.
git.add().then ->
  # Commit them.
  git.commit('Much important changes, sir').then ->
    # What did we commit?
    git.show('HEAD', {stat: true}).then (o) ->
      console.log(o)
      # commit d4e73a81525749e0538ab91a8cf9dd2e4a85a682
      # Author: Maximilian Schüßler <git@mschuessler.org>
      # Date:   Tue Jul 8 10:01:21 2014 +0200
      #
      #     Much important changes, sir
      #
      #  a.coffee } | { 2 +-
      #  b.coffee } | { 2 +-
      #  d.coffee } | { 4 ++++
      #  3 files changed, 6 insertions(+), 2 deletions(-)

::Promise

Expose bluebird instance as ‘Promise’ property.

::constructor(cwd)

Construct a new PromisedGit instance.

Argument Description
cwd The path of the git repository as String.
::add(file)

Add file(s) to the index.

Example

  Git = require 'promised-git'
  git = new Git('/tmp/exampleRepo')
  git.add()                       # => Adds all unstaged changes to the index.
  git.add('a.coffee')             # => Adds 'a.coffee' to the index.
  git.add('a.coffee', 'b.coffee') # => Adds 'a.coffee' and 'b.coffee' to the index.

You can use instances of File instead of the path:

  Git = require 'promised-git'
  git = new Git('/tmp/exampleRepo')
  git.status().then (o) ->
    file = o.unstaged[0]
    git.add(file)                 # => Adds the first unstaged <a class='reference' href='File'>File</a> to the index.
Argument Description
file The file(s) to add as String | File | Array.
Return Values
Returns a Promise.
::amend()

Amend HEAD.

Return Values
Returns a Promise that resolves to an instance of Amend.
::branches()
Return Values
Returns the local branches.
Returns the local branches as Array of Branch.
::checkout(oid, options)

Checkout a oid.

Argument Description
oid The oid to checkout as String | Treeish.
options The options as plain Object.
Return Values
Returns a Promise.
::checkoutFile(file, oid)

Checkout file.

Argument Description
file The file(s) to add to the index as String | File | Array.
oid The oid to check the file out to.
Return Values
Returns: Promise.
::cmd(command, options, args)

Access to the {GitWrapper}. Use it to execute custom git commands.

Argument Description
command The command to execute as String.
options The options to pass as Object.
  • treeish — Set a treeish range, for example HEAD..HEAD~5.
args The args to pass as String | Array.
Return Values
Returns a Promise that resolves to the git cli output.
::commit(message, options)

Commit the staged changes.

Argument Description
message The message or the path to the commit message file as String.
options The options as Object.
  • cleanup — Defaults to ‘strip’.
Return Values
Returns a Promise
::getCommit(oid, options)

Return the Commit at oid.

Argument Description
oid The oid as String.
options The options as plain Object.
Return Values
Returns the commit at oid as Commit.
::getDiff(file, options)

Get the diff for a file.

Argument Description
file The file(s) to diff as String | File | Array. If you pass no file path(s), it will diff all modified files.
options The Object with options for git-diff.
  • cachedBoolean Show the diff from index.
Return Values
Returns a Promise resolving to Diff if you passed a single path or to an Array of Diffs if you passed an Array or nothing for file.
::getTags(maxCount)

Retrieve the maxCount newest tags.

Argument Description
maxCount The maximum amount of tags to return as Number.
Return Values
Returns a Promise that resolves to an Array of Tags.
::init()

Initialize the git repository.

::log(ref, limit)

Get the log for the current repository.

Argument Description
ref The ref to get the log for as String.
limit The maximum amount of commits to show as Number.
Return Values
Returns a Promise resolving to an Array of Commits.
::refreshIndex()

Refresh the git index.

Return Values
Returns a Promise.
::remoteBranches()
Return Values
Returns the remote branches.
Returns an Array of Branch.
::reset(oid, options)

Reset repo to oid.

Argument Description
oid The oid to reset to as String.
options The Object with flags for git CLI.
  • soft — {Boolean)
  • mixed — {Boolean) [Default]
  • hard — {Boolean)
  • merge — {Boolean)
  • keep — {Boolean)
Return Values
Returns a Promise.
::revParse(oid)

git-rev-parse oid.

Argument Description
oid The oid to rev-parse as String | Treeish.
Return Values
Returns a Promise that resolves to the rev-parsed oid.
::show(oid, file, options)

Wrapper for git-show. If you pass oid and file you get the file at oid. If you only pass oid you get the head of oid. If you only pass file you get the changes made by HEAD to file.

Argument Description
oid The treeish to show as String | Treeish.
file The file to show as String | File.
options The options as plain Object.
Return Values
Returns a Promise.
::status()

Get the repo status.

Return Values
Returns a Promise resolving to an instance of Status.
::unstage(file)

Unstage file(s) from the index.

Argument Description
file The file(s) to unstage as String | File | Array. If you pass nothing or a ‘.’ it will unstage all files from index.
Return Values
Returns a Promise.