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(-)
Construct a new PromisedGit instance.
Argument | Description |
---|---|
cwd | The path of the git repository as String. |
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 HEAD.
Return Values |
---|
Returns a Promise that resolves to an instance of Amend. |
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.
|
args | The args to pass as String | Array. |
Return Values |
---|
Returns a Promise that resolves to the git cli output. |
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.
|
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. |
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. |
Get the repo status.
Return Values |
---|
Returns a Promise resolving to an instance of Status. |