npm install giftA simple Node.js wrapper for the Git CLI. The API is based on
Grit.
Tested in all stable versions of node.
  
- Installation
- API
- Repo
- Commit
- Head
- Tag
- Config
- Status
- Actor
- Tree
- Blob
- Submodule
- License
This fork is now in the npm package repository. Install it like you would any other package:
$ npm install gift
For existing repositories:
git = require 'gift'
repo = git "path/to/repo"
# => #
Initialize a new repository:
git = require 'gift'
git.init "path/to/repo", (err, _repo) ->
repo = _repo
# => #
Initialize a new bare repository:
git = require 'gift'
git.init "path/to/bare/repo", true, (err, _repo) ->
repo = _repo
# => #
Clone a repository:
git = require 'gift'
git.clone "git@host:path/to/remote/repo.git", "path/to/local/clone/repo", depth, branch, (err, _repo) ->
repo = _repo
# => #
String - The path to the repository. * treeish - String (optional).
* limit - Integer (optional).
* skip - Integer (optional).
* callback - Function which receives (err, commits), where commits is
an Array of Commits.
Get the 10 most recent commits to master.
repo.commits (err, commits) ->
Or to a different tag or branch.
repo.commits "v0.0.3", (err, commits) ->
Limit the maximum number of commits returned (by default limit is 10).
repo.commits "master", 30, (err, commits) ->
Skip some (for pagination):
repo.commits "master", 30, 30, (err, commits) ->
Or get an unlimited number of commits (there could be a lot):
repo.commits "master", -1, (err, commits) ->
The callback receives (err, commit).
Tree object for the treeish (which defaults to "master"). repo.tree().contents (err, children) ->
for child in children
console.log child.name
The callback receives (err, diffs).
The callback receives (err, actor), where actor is an Actor.
The callback receives (err).
Receives (err, remotes), where each remote is a Ref.
Get the string names of each of the remotes.
git remote add .git remote set-url --add .git remote set-url .git remote set-url --delete .git fetch git push with branch parameter specified:git push
--porcelain to parse repository status in a way that is agnostic of system language.options is a string of any other options you'd like to pass to the status command. For example, the -u option will list each file in an untracked directory rather than simply listing the directory itself.(err, status). See below for a definition of what status is.files (paths or filenames).git config parsed as a simple, one-level object. The callback receives (err, config).callback receives (err, heads). * branch - The name of the branch to get. Defaults to the
currently checked out branch.
* callback - Receives (err, head).
name, and call the callback when completename, and call the callback with an error, if one occurred.git merge Tags. * message - String
* options -
- all - Boolean
- amend - Boolean
- author - String that must match "Au thor Author
* callback - Receives (err).
git add git rm git checkout Checkout a branch/commit/...
* treeish - Branch or treeish to checkout.
* options -
- b - Boolean to create a new branch
* callback - Receives (err).
* files - File(s) to checkout. Pass '.' or nothing to checkout all files.
* options -
- force - Boolean
* callback - Receives (err).
* remote - String (defaults to origin).
* branch - String (defaults to master).
* callback - Receives (err).
The following steps are carried out: stash, pull, push, stash pop. If there were no changes to stash, the last stash pop is not executed.
* remote - String (defaults to origin).
* branch - String (defaults to master).
* callback - Receives (err).
* treeish - The git object to reset to. Defaults to HEAD.
* options -
- soft - Boolean
- mixed - Boolean __default__
- hard - Boolean
- merge - Boolean
- keep - Boolean
* callback - Receives (err).
String - The commit's SHA.Commit[]Tree - The commit's content tree.ActorDateActorDateString * refs - String (all, tags, or null for default of unannotated tags).
* first_parent - Boolean (follow lineage or include all ancestry).
* callback - (err, description) (description is String).
StringCommitStringCommit(err, message) (message is a String).(err, actor).(err, date).Object - The keys are dotted precisely as the console output from git config. E.g., {'user.name': 'John Doe'}BooleanObject - The keys are files, the values objects indicating whether or notEach file has the following properties:
* type which translates to:
| _type_ | index | working tree |
| :--- | :-------: | :-----------:|
| A | added | - |
| M | modified | - |
| D | deleted | - |
| AM | added | modified |
| MM | modified | modified |
| AD | staged | deleted |
| MD | modified | deleted |
* staged - Boolean
* tracked - Boolean
StringStringString - The MD5 hash of the actor's email. Useful for displayingString - SHA1 * callback - Receives (err, children).
* children - An array of Blobs, Trees, and Submodules.
* callback - Receives (err, child_blobs).
* children - [Blob]
* callback - Receives (err, child_trees).
* children - [Tree]
* directory - String
* callback - Receives (err, thing).
String - SHA1String * callback - (err, data)
Warning: this method only returns the complete file up to 200k, which is the default
buffer size for running child_process.exec(). If the file you're reading is bigger than
that, or if you're not sure, you need to use dataStream()
* returns - [dataStream, errorStream]
Returns streams for you to use to get the data.
Usage:
data = ""
[dataStream, _] = blob.dataStream()
dataStream.on 'data', (buf) ->
data += buf.toString()
.on 'end', ->
callback(data)
StringStringString