gitjs
A Node.js module for interacting with git repositories.
Install
$ npm install gitjs
Usage
var git = ;
git.open ( repoPath[, autoCreate = false], callback )
Opens a git repository so git commands can be run. If the autoCreate
parameter is given and is truthy, then the open function will init a new repository if one is not already in the given directory.
git;
git.init ( repoPath, callback )
Intializes a new git repo in the given directory.
git;
Repo::run ( cmd[, args], callback )
Runs a git command in the repository. If an args
array is given, it will be used to populate ?
placeholders in the command. As an example, on the command line you would create a new branch like so:
$ git branch foo
The same could be done with gitjs like this:
repo;
Also, you could make the branch name variable using the args
parameter like this:
{ repo;}
Repo::add ( <String|Array> files, callback )
Stages files to be committed.
// All of the following are acceptable formats for files repo; repo; repo; repo;
Repo::commit ( message, callback )
Commits the repository changes.
repo;
Repo::commitAll ( message, callback )
Commits the repository changes with a git commit -a
.
Repo::cloneTo ( target, callback )
Does a local clone of the repository to the given target path.
repo;
Repo::clean ( dirs, callback )
Runs a git clean
. If the dirs
parameter is truthy, a -d
flag will be used.
Repo::listBranches ([ giveObjs = false,] callback )
Gets an array of branch names for the repository. If the giveObjs
parameter is given and is truthy, objects about the branches will be given instead of just names.
repo; repo;
Repo::currentBranch ( callback )
Gets the name of the current branch.
repo;
Repo::listRemotes ( callback )
Gets the names of all remotes for the repository.
repo;
Repo::remoteExists ( remote, callback)
Determines if a given remote exists.
repo;
Repo::createBranch ( name, callback )
Creates a new branch.
repo;
Repo::deleteBranch ( name[, force = false], callback )
Deletes a branch from the repository. If the force
parameter is given and is truthy, the -f
flag will be given, forcing the branch to be deleted, even if it has unmerged changes.
Repo::checkout ( name, callback )
Checks out the given branch.
repo;
Repo::status ( callback )
Runs a git status --porcelain -z
command and parses the results into an array of files and the changes. Each value in the array is an object with the file name and the x
and y
change flags as defined in the git man pages.
x: 'M' y: ' ' file: 'foo.txt'
Repo::push ( callback )
Pushing commits to git
repo;