The module function
It Spawns a child process for the git command line, capturing the output
- See:
-
spawnGitfor a detailed description
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
commandthe git command executedFires
resultthe 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.mdName Type Description optionsObject The options object. All its properties are
ResolvableName Type Description filesResolvable | Array.<String> The files to be added, relative to the cwd
cbcallback 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/12If 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 optionsObject The options object. All its properties are
ResolvableName Type Description branchResolvable | String The branch to checkout
tagResolvable | String optional The tag to checkout
createResolvable | Boolean optional Try to create the branch (-B flag)
oldCreateResolvable | Boolean optional Try to create the branch (-b flag). Do not use along with 'create'.
orphanResolvable | Boolean optional Create an orphan branch (--orphan flag)
forceResolvable | 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)
cbcallback 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 optionsObject The options object. All its properties are
ResolvableName Type Description repositoryResolvable | String The git repository endpoint
directoryResolvable | String optional The directory where the repo will be cloned By default, git will clone it a new one specifed by the repo name
branchResolvable | String optional The remote repo branch to checkout after clone.
tagResolvable | String optional The remote repo tag to checkout after clone.
originResolvable | String optional Instead of using the remote name origin to keep track of the upstream repository, use this parameter value
recursiveResolvable | Boolean optional After the clone is created, initialize all
bareResolvable | Boolean optional Make a bare Git repository.: neither remote-tracking branches nor the related configuration variables are created.
depthResolvable | Number optional Create a shallow clone with a history truncated to the specified number of revisions.
cbcallback 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 }); -
Creates a
commandin this module. Third party developers must use it to create their owns parametersName Type Description fncommand 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 optionsObject The options object. All its properties are
ResolvableName Type Description messageResolvable | String The commit message
forceResolvable | Boolean optional Replace the tip of the current branch by creating a new commit. The --amend flag
noVerifyResolvable | Boolean optional This option bypasses the pre-commit and commit-msg hooks
cbcallback 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 --tagsremote defaults to "origin", and don't follow configured refspecs for the upstream
Name Type Description optionsObject The options object. All its properties are
ResolvableName Type Default Description remoteResolvable | String "origin" optional The remote to fetch
tagsResolvable | Boolean optional Fetch the tags (--tags flag)
pruneResolvable | Boolean optional remove any remote-tracking references that no longer exist on the remote (--prune)
cbcallback 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 HEADName Type Description cbcallback 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 cbcallback 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 originName Type Description optionsObject The options object. All its properties are
ResolvableName Type Default Description remoteResolvable | String "origin" optional The remote ref to ask for branches
cbcallback 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 tagName Type Description cbcallback 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 cbcallback 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 optionsObject The options object. All its properties are
ResolvableName Type Description remoteResolvable | String optional The remote where the branch is located
branchResolvable | String The branch to merge
messageResolvable | String The merge message
noFFResolvable | Boolean optional Make a no fast forward merge, creating a new sha (--no-ff flag)
cbcallback 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 masterremote 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 optionsObject The options object. All its properties are
ResolvableName Type Default Description remoteResolvable | String "origin" optional The remote
branchResolvable | String currentBranch optional The remote branch to pull
tagResolvable | String optional The remote tag to pull
rebaseResolvable | Boolean optional Make a rebase (--rebase tag)
cbcallback 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 masterDefaults 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 optionsObject The options object. All its properties are
ResolvableName Type Default Description remoteResolvable | String "origin" optional The remote ref to push to
branchResolvable | String "HEAD" optional The branch to push. HEAD will push the current branch
tagResolvable | String optional The tag to push
forceResolvable | Boolean optional Force a remote update. Can cause the remote repository to lose commits; use it with care. --force flag
cbcallback 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 optionsObject The options object. All its properties are
ResolvableName Type Description branchResolvable | String The branch name
forceResolvable | Boolean optional force the delete (-D)
cbcallback 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.0It does not fail when the tag does not exists
Name Type Description optionsObject The options object. All its properties are
ResolvableName Type Description tagsResolvable | Array.<String> The tags to remove
cbcallback 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 optionsObject The options object. All its properties are
ResolvableName Type Default Description branchResolvable | String The branch name
remoteResolvable | String "origin" optional The remote ref where the branch will be removed
cbcallback 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.0Name Type Description optionsObject The options object. All its properties are
ResolvableName Type Default Description remoteResolvable | String "origin" optional The remote ref where the tag will be removed
tagsResolvable | Array.<String> The tags to remove
cbcallback 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 optionsObject The options object. All its properties are
ResolvableName Type Default Description remoteResolvable | String "origin" optional The remote ref where the tag will be removed
tagsResolvable | Array.<String> The tags to remove
cbcallback 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" -aName Type Description optionsObject The options object. All its properties are
ResolvableName Type Description tagResolvable | String The tag name
messageResolvable | String optional The tag message. Mandatory when creating an annotated tag
annotatedResolvable | Boolean optional Should this tag be annotated?
cbcallback 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 versionReturns:
Resolves with the git version
Example
var git = require('gitftw'); git.version().then(console.log) //outputs 1.8.2.3
Events
-
Name Type Description StringString the command issued
-
Name Type Description StringString the captured output