Skip to content

resonance-cascade/quick-gits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

quick-gits

DEPRECIATED! Use https://github.com/feross/git-pull-or-clone instead

npm version Build Status Test Coverage Code Climate

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 A

Methods

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.

  • command String or Array of arguments to pass to git.
    • Accepts either a child_process.exec or a child_process.execFile style command to pass to git.
    • command Array
      • Passing an Array as the command uses child_process.execFile to run the command.
      • ['push','origin','master'] results in git -C $workpath push origin master
    • command String
      • Passing a String as the command uses the child_process.exec to run the command.
      • 'push origin master' results in git -C $workpath push origin master
  • options Object
    • accepts the same options as child_process.exec and child_process.execFile.
    • cwd String Current working directory of the child process
    • env Object Environment key-value pairs
    • encoding String (Default: 'utf8')
    • timeout Number (Default: 0)
    • maxBuffer Number (Default: 200*1024)
    • killSignal String (Default: 'SIGTERM')
  • callback Function called with the output when git terminates
    • error Error
    • stdout Buffer
    • stderr Buffer

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.

  • callback Function called with the output when git terminates
    • error Error
    • stdout Buffer
    • stderr Buffer

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.

  • remote String passed as the <repository> to the git command.
  • callback Function called with the output when git terminates
    • error Error
    • stdout Buffer
    • stderr Buffer

About

Provides quick access to git commands using child_process. Works with Node.

Resources

License

Stars

Watchers

Forks

Packages

No packages published