quick-gits v1.0.4
quick-gits
Provides quick access to most git commands using child_process. Works with Node.
Example
var gits = require('quick-gits');
var path = require('path');
var repoAPath = path.join(__dirname, 'repoA')
var repoBPath = path.join(__dirname, 'repoB')
var repoA = gits(repoAPath);
var repoB = gits(repoBPath);
repoA.init(function(err, stdout, stderr) {
console.log('Initialized new repository at ' + repoAPath)
repoB.clone(repoAPath, function(err, stdout, stderr) {
console.log('Cloned ' + repoAPath + ' to ' + repoBPath)
repoA('status', function(err, stdout, stderr) {
console.log('Ran `git status` in repoA:')
console.log(stdout);
});
repoB(['pull', 'origin'], function(err, stdout, stderr) {
console.log('repoB pulled repo A')
console.log(stdout);
});
});
});Initialized new repository at quick-gits/example/repoA
Cloned quick-gits/example/repoA to quick-gits/example/repoB
Ran `git status` in repoA:
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
repoB pulled repo AMethods
quick-gits is a convenience wrapper around the child_process module running git commands. It is useful when you need to automate git workflows in a program.
var git = require('quick-gits')(workpath)
- Return: QuickGits object
Returns a quick-gits Object that is bound bound to workpath. You can think of the returned function equivalent to running the git command inside of the path it is bound to, or running git from the command line with the -C option pointing to path.
Assign require('quick-gits') to a variable create a repository object factory. It follows the Functional Inheritance pattern and does not requires the new keyword.
var gits = require('quick-gits');
var path = require('path');
var repoA = gits(path.join(__dirname, 'repoA'));
var repoB = gits(path.join(__dirname, 'repoB'));git(command, [options], [callback])
There are two primary ways of using a returned quick-gits object.
commandString or Array of arguments to pass togit.- Accepts either a
child_process.execor achild_process.execFilestyle command to pass togit. commandArray- Passing an Array as the command uses
child_process.execFileto run the command. ['push','origin','master']results ingit -C $workpath push origin master
- Passing an Array as the command uses
commandString- Passing a String as the command uses the
child_process.execto run the command. 'push origin master'results ingit -C $workpath push origin master
- Passing a String as the command uses the
- Accepts either a
optionsObject- accepts the same options as
child_process.execandchild_process.execFile. cwdString Current working directory of the child processenvObject Environment key-value pairsencodingString (Default: 'utf8')timeoutNumber (Default: 0)maxBufferNumber(Default: 200*1024)killSignalString (Default: 'SIGTERM')
- accepts the same options as
callbackFunction called with the output when git terminateserrorErrorstdoutBufferstderrBuffer
Convenience Methods
These methods are special cases where you would not want the workpath specified when running a git command, such as cloning and initialization of new repositories.
git.init(callback)
Same as running git init $workpath to initialize an empty repository at workpath. Relative workpaths are resolved to the full path through path.resolve, and an new directories are created recursively using mkdirp.
callbackFunction called with the output when git terminateserrorErrorstdoutBufferstderrBuffer
git.clone(remote, cb)
Same as running git clone remote $workpath. Relative workpaths are resolved to the full path through path.resolve, and an new directories are created recursively using mkdirp.
remoteString passed as the<repository>to thegitcommand.callbackFunction called with the output when git terminateserrorErrorstdoutBufferstderrBuffer