Namespace: git

git

The module function

It Spawns a child process for the git command line, capturing the output

See:

Example

var git = require('gitftw');

//Execute a `git version`
git(['version'], function(err, data) { console.log(data);});
//or
git(['version']).then(console.log);

Members

staticgit.eventsEventEmmiter2

The event emmiter for GitFTW

  • Fires command the git command executed

  • Fires result the result from the command line

Example
var git = require('gitftw');

//Add a listener to the issued git command. Output it
git.events.on('command', console.info);

//Add a listener to the result of the git command. Output it with >
git.events.on('result', function(res) {
  console.log('> ' + res.split('\n').join('\n> '))
});

Methods

staticgit.add(options, cb){Promise}

Adds filenames to the stashing area Issues git add README.md

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Description
files Resolvable | Array.<String>

The files to be added, relative to the cwd

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

git.add({
  files: ['README.md', 'index.js']
});

staticgit.checkout(options, cb){Promise}

Checkout a local branch

Executes git checkout -B issues/12

If you specify create, it will try to create the branch, or will checkout it if it already exists

If both a branch and a tag are specified, the branch takes precedence

Cannot use create and orphan both together

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Description
branch Resolvable | String

The branch to checkout

tag Resolvable | String optional

The tag to checkout

create Resolvable | Boolean optional

Try to create the branch (-B flag)

oldCreate Resolvable | Boolean optional

Try to create the branch (-b flag). Do not use along with 'create'.

orphan Resolvable | Boolean optional

Create an orphan branch (--orphan flag)

force Resolvable | Boolean optional

When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes. (-f flag)

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

git.checkout({
  branch: 'master'
});

staticgit.clone(options, cb){Promise}

Clones a git repo

If both a branch and a tag are specified, the branch takes precedence

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Description
repository Resolvable | String

The git repository endpoint

directory Resolvable | String optional

The directory where the repo will be cloned By default, git will clone it a new one specifed by the repo name

branch Resolvable | String optional

The remote repo branch to checkout after clone.

tag Resolvable | String optional

The remote repo tag to checkout after clone.

origin Resolvable | String optional

Instead of using the remote name origin to keep track of the upstream repository, use this parameter value

recursive Resolvable | Boolean optional

After the clone is created, initialize all

bare Resolvable | Boolean optional

Make a bare Git repository.: neither remote-tracking branches nor the related configuration variables are created.

depth Resolvable | Number optional

Create a shallow clone with a history truncated to the specified number of revisions.

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

git.clone({
 repository: 'git@github.com:jmendiara/node-lru-cache.git',
 directory: './cache' //optional
});

staticgit.command(fn){function}

Creates a command in this module. Third party developers must use it to create their owns parameters

Name Type Description
fn command

The named function implementing a command

Returns:
The gitftw module, for chainability

staticgit.commit(options, cb){Promise}

Commits the staging area Executes git commit -m "First commit"

It does not fail when there is not anything to commit

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Description
message Resolvable | String

The commit message

force Resolvable | Boolean optional

Replace the tip of the current branch by creating a new commit. The --amend flag

noVerify Resolvable | Boolean optional

This option bypasses the pre-commit and commit-msg hooks

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

git.commit({
  message: 'First commit'
});

staticgit.fetch(options, cb){Promise}

Fetches a remote Executes git fetch origin --tags

remote defaults to "origin", and don't follow configured refspecs for the upstream

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Default Description
remote Resolvable | String "origin" optional

The remote to fetch

tags Resolvable | Boolean optional

Fetch the tags (--tags flag)

prune Resolvable | Boolean optional

remove any remote-tracking references that no longer exist on the remote (--prune)

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

git.fetch(); //fetches origin

staticgit.getCurrentBranch(cb){Promise}

Gets the current branch Executes git rev-parse --abbrev-ref HEAD

Name Type Description
cb callback optional

The execution callback result

Returns:
Resolves with the current branch
Example
var git = require('gitftw');

//while in master...
git.getCurrentBranch().then(console.log); //outputs 'master';

staticgit.getLocalBranches(cb){Promise}

Gets all local branches Executes git for-each-ref --format='%(refname:short)' refs/heads/

Name Type Description
cb callback optional

The execution callback result

Returns:
Resolves with Array
Example
var git = require('gitftw');

//remove local tags in 'origin'
git.getLocalBranches();

staticgit.getRemoteBranches(options, cb){Promise}

Gets all remote branches in a remote Executes git ls-remote --heads origin

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Default Description
remote Resolvable | String "origin" optional

The remote ref to ask for branches

cb callback optional

The execution callback result

Returns:
Resolves with Array
Example
var git = require('gitftw');

//remove local tags in 'origin'
git.getRemoteBranches({
  remote: 'upstream'
});

staticgit.getTags(cb){Promise}

Gets the local tags Executes git tag

Name Type Description
cb callback optional

The execution callback result

Returns:
Resolves with the array of tags
Example
var git = require('gitftw');

git.getTags().then(console.log); //outputs ['v1.0.0', 'v1.0.1']

staticgit.isClean(cb){Promise}

Gets the current workspace is clean or has something in the working tree Executes git diff-index --quiet HEAD .

Name Type Description
cb callback optional

The execution callback result

Returns:
Resolves with true if the workspace is clean. false otherwise
Example
var git = require('gitftw');

git.isClean()
    .then(function(clean) {
      if (clean) {
        console.log('The git workspace is clean');
      } else {
        console.log('The git workspace is dirty');
      }
    });

staticgit.merge(options, cb){Promise}

Merges branches a branch in the current one Executes `git merge --no-ff origin/issues13 -m "Remote branch merge"

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Description
remote Resolvable | String optional

The remote where the branch is located

branch Resolvable | String

The branch to merge

message Resolvable | String

The merge message

noFF Resolvable | Boolean optional

Make a no fast forward merge, creating a new sha (--no-ff flag)

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

//while in master...
git.merge({
  branch: 'issue/12',
  message: 'Merge branch issue/12 into master'
});

staticgit.pull(options, cb){Promise}

Pulls a remote branch into the current one Executes git pull origin master

remote defaults to "origin", and don't follow configured refspecs for the upstream

If both a branch and a tag are specified, the branch takes precedence

When no branch and tag are specifies, this command will try to pull the actual local branch name from the remote

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Default Description
remote Resolvable | String "origin" optional

The remote

branch Resolvable | String currentBranch optional

The remote branch to pull

tag Resolvable | String optional

The remote tag to pull

rebase Resolvable | Boolean optional

Make a rebase (--rebase tag)

cb callback optional

The execution callback result

Returns:
with undefined
Example
var git = require('gitftw');

//While in master...
git.getCurrentBranch().then(console.log)
//Outputs: master

//Pulls origin/master into the current branch (master)
git.pull()

staticgit.push(options, cb){Promise}

Push the change sets to server Executes git push origin master

Defaults to "origin", and don't follow configured refspecs for the upstream

If both a branch and a tag are specified, the branch takes precedence

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Default Description
remote Resolvable | String "origin" optional

The remote ref to push to

branch Resolvable | String "HEAD" optional

The branch to push. HEAD will push the current branch

tag Resolvable | String optional

The tag to push

force Resolvable | Boolean optional

Force a remote update. Can cause the remote repository to lose commits; use it with care. --force flag

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

git.push(); //the current branch to `origin`

staticgit.removeLocalBranch(options, cb){Promise}

Removes a local branch

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Description
branch Resolvable | String

The branch name

force Resolvable | Boolean optional

force the delete (-D)

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

//while in master...
git.removeLocalBranch({
  branch: 'master'
});

staticgit.removeLocalTags(options, cb){Promise}

Removes a set of tags from the local repo Executes git tag -d v1.0.0

It does not fail when the tag does not exists

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Description
tags Resolvable | Array.<String>

The tags to remove

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

//remove all local tags
git.removeLocalTags({
  tags: git.getTags //It's a resolvable. You can specify also ['v1.0.0', 'v1.0.1']
});

staticgit.removeRemoteBranch(options, cb){Promise}

Removes a remote branch

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Default Description
branch Resolvable | String

The branch name

remote Resolvable | String "origin" optional

The remote ref where the branch will be removed

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

//while in master...
git.removeRemoteBranch({
  branch: 'master'
});

staticgit.removeRemoteTags(options, cb){Promise}

Removes a tag from the remote repo Executes git push origin :refs/tags/v1.0.0

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Default Description
remote Resolvable | String "origin" optional

The remote ref where the tag will be removed

tags Resolvable | Array.<String>

The tags to remove

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

//remove local tags in 'origin'
git.removeRemoteTags({
  tags: git.getTags //It's a resolvable. You can specify also ['v1.0.0', 'v1.0.1']
});

staticgit.removeTags(options, cb){Promise}

Removes a set of tags from the remote and local repo

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Default Description
remote Resolvable | String "origin" optional

The remote ref where the tag will be removed

tags Resolvable | Array.<String>

The tags to remove

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

//remove all local tags in local and remote 'origin'
git.removeTags({
  tags: git.getTags //It's a resolvable. You can specify also ['v1.0.0', 'v1.0.1']
});

staticgit.tag(options, cb){Promise}

Creates a git tag Executes git tag v1.0.0 -m "v1.0.0" -a

Name Type Description
options Object

The options object. All its properties are Resolvable

Name Type Description
tag Resolvable | String

The tag name

message Resolvable | String optional

The tag message. Mandatory when creating an annotated tag

annotated Resolvable | Boolean optional

Should this tag be annotated?

cb callback optional

The execution callback result

Returns:
Resolves with undefined
Example
var git = require('gitftw');

git.tag({
 tag: 'v1.2.0'
})

staticgit.version(){Promise}

Gets current installed git version Executes git version

Returns:
Resolves with the git version
Example
var git = require('gitftw');

git.version().then(console.log) //outputs 1.8.2.3

Events

command

Name Type Description
String String

the command issued

result

Name Type Description
String String

the captured output