2013-10-20 02:34:20 +02:00
# Gift [![Build Status](https://secure.travis-ci.org/notatestuser/gift.png?branch=master)](http://travis-ci.org/notatestuser/gift) [![Dependency Status](https://david-dm.org/notatestuser/gift.png)](https://david-dm.org/notatestuser/gift)
2012-02-15 16:00:43 +01:00
2012-02-15 15:52:40 +01:00
A simple Node.js wrapper for the Git CLI. The API is based on
2012-02-15 15:51:45 +01:00
[Grit ](https://github.com/mojombo/grit )
2014-02-10 00:53:30 +01:00
# Installation
2012-02-15 15:51:45 +01:00
2014-02-10 00:53:30 +01:00
This fork is now in the `npm` package repository. Install it like you would any other package:
$ npm install gift
2012-02-15 15:51:45 +01:00
# API
2013-09-23 18:20:31 +02:00
For existing repositories:
2012-02-15 15:51:45 +01:00
git = require 'gift'
2013-03-17 16:35:37 +01:00
2012-02-15 15:51:45 +01:00
repo = git "path/to/repo"
# => #< Repo >
2013-09-23 18:20:31 +02:00
Initialize a new repository:
git = require 'gift'
git.init "path/to/repo", (err, _repo) ->
repo = _repo
# => #< Repo >
Initialize a new bare repository:
git = require 'gift'
git.init "path/to/bare/repo", true, (err, _repo) ->
repo = _repo
# => #< Repo >
2013-09-23 18:19:19 +02:00
Clone a repository:
git = require 'gift'
git.clone "git@host:path/to/remote/repo.git", "path/to/local/clone/repo", (err, _repo) ->
repo = _repo
# => #< Repo >
2012-02-15 15:51:45 +01:00
## Repo
2012-03-23 15:39:27 +01:00
### `Repo#path`
2012-02-15 15:51:45 +01:00
`String` - The path to the repository.
2012-03-23 15:39:27 +01:00
### `Repo#commits([treeish, [limit, [skip, ]]]callback)`
2012-02-15 15:51:45 +01:00
Get a list of commits.
* `treeish` - `String` (optional).
* `limit` - `Integer` (optional).
* `skip` - `Integer` (optional).
* `callback` - `Function` which receives `(err, commits)` , where `commits` is
an `Array` of `Commit` s.
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) ->
2014-02-20 10:14:28 +01:00
Limit the maximum number of commits returned (by default limit is 10).
2012-02-15 15:51:45 +01:00
repo.commits "master", 30, (err, commits) ->
Skip some (for pagination):
repo.commits "master", 30, 30, (err, commits) ->
2014-02-20 21:33:20 +01:00
Or get an unlimited number of commits (there could be a lot):
2014-02-20 10:14:28 +01:00
repo.commits "master", -1, (err, commits) ->
### `Repo#current_commit(callback)`
2014-02-20 21:33:20 +01:00
Get the current commit.
2014-02-20 10:14:28 +01:00
The callback receives `(err, commit)` .
2012-03-23 15:39:27 +01:00
### `Repo#tree([treeish]) => Tree`
2012-02-15 15:51:45 +01:00
The `Tree` object for the treeish (which defaults to "master").
repo.tree().contents (err, children) ->
for child in children
console.log child.name
2012-03-23 15:39:27 +01:00
### `Repo#diff(commitA, commitB, [paths, ]callback)`
2012-02-15 15:51:45 +01:00
Get the difference between the trees.
The callback receives `(err, diffs)` .
2013-03-17 16:35:37 +01:00
### `Repo#identity(callback)`
Get the commit identity for this repository.
The callback receives `(err, actor)` , where `actor` is an Actor.
### `Repo#identify(actor, callback)`
Set your account's default identity for commits to this repository.
The callback receives `(err)` .
2012-03-23 15:39:27 +01:00
### `Repo#remotes(callback)`
2012-02-15 15:51:45 +01:00
Get the repository's remotes.
Receives `(err, remotes)` , where each remote is a Ref.
2012-03-23 15:39:27 +01:00
### `Repo#remote_list(callback)`
2012-02-15 15:51:45 +01:00
Get a list of the repository's remote names.
Get the string names of each of the remotes.
2012-03-23 15:39:27 +01:00
### `Repo#remote_add(name, url, callback)`
2012-02-15 15:51:45 +01:00
Equivalent to `git remote add <name> <url>` .
2013-03-17 16:38:44 +01:00
### `Repo#remote_remove(name, callback)`
Remove a remote.
2014-07-30 17:44:28 +02:00
### `Repo#remote_fetch(name, [options, ]callback)`
2012-02-15 15:51:45 +01:00
`git fetch <name>`
2014-07-30 17:44:28 +02:00
### `Repo#remote_push(name, [branch, options, ]callback)`
2013-03-17 16:38:44 +01:00
`git push <name>`
2012-02-15 15:51:45 +01:00
2014-05-18 05:05:24 +02:00
with branch parameter specified:
`git push <name> <branch>`
2014-07-30 17:44:28 +02:00
### `Repo#merge(name, [options, ]callback)`
`git merge <name>`
2012-03-23 15:39:27 +01:00
### `Repo#status(callback)`
2013-03-17 16:35:37 +01:00
Uses `--porcelain` to parse repository status in a way that is agnostic of system language. The callback receives `(err, status)` . See below for a definition of what `status` is.
2012-02-15 15:51:45 +01:00
2013-10-06 00:40:33 +02:00
### `Repo#config(callback)`
`git config` parsed as a simple, one-level object. The callback receives `(err, config)` .
2012-03-23 15:39:27 +01:00
### `Repo#create_branch(name, callback)`
2012-02-15 15:51:45 +01:00
Create a new branch with `name` , and call the callback when complete
with an error, if one occurred.
2012-03-23 15:39:27 +01:00
### `Repo#delete_branch(name, callback)`
2012-02-15 15:51:45 +01:00
Delete the branch `name` , and call the callback with an error, if one occurred.
2012-03-23 15:39:27 +01:00
### `Repo#tags(callback)`
2012-02-15 15:51:45 +01:00
Get a list of `Tag` s.
2012-03-23 15:39:27 +01:00
### `Repo#create_tag(name, [options, ]callback)`
2012-02-15 15:51:45 +01:00
Create a tab with the given name.
2012-03-23 15:39:27 +01:00
### `Repo#delete_tag(name, callback)`
2012-02-15 15:51:45 +01:00
Delete the tag with the given name.
2012-03-23 15:39:27 +01:00
### `Repo#branches(callback)`
2012-02-15 15:51:45 +01:00
`callback` receives `(err, heads)` .
2012-03-23 15:39:27 +01:00
### `Repo#create_branch(name, callback)`
2012-02-15 15:51:45 +01:00
Create a branch with the given name.
2012-03-23 15:39:27 +01:00
### `Repo#delete_branch(delete, callback)`
2012-02-15 15:51:45 +01:00
Delete the branch with the given name.
2012-03-23 15:39:27 +01:00
### `Repo#branch([branch, ]callback)`
2012-02-15 15:51:45 +01:00
Get a branch.
* `branch` - The name of the branch to get. Defaults to the
currently checked out branch.
* `callback` - Receives `(err, head)` .
2012-03-23 15:39:27 +01:00
### `Repo#commit(message, [options, ]callback)`
2012-02-15 15:51:45 +01:00
Commit some changes.
* `message` - `String`
* `options` -
- `all` - `Boolean`
- `amend` - `Boolean`
2012-09-15 10:49:39 +02:00
- `author` - `String` that must match "Au thor Author < author @ nowhere . org > "
2012-02-15 15:51:45 +01:00
* `callback` - Receives `(err)` .
2012-03-23 15:39:27 +01:00
### `Repo#add(files, callback)`
2012-02-15 15:51:45 +01:00
`git add <files>`
2012-03-23 15:39:27 +01:00
### `Repo#remove(files, callback)`
2012-02-15 15:51:45 +01:00
`git rm <files>`
2012-03-23 15:39:27 +01:00
### `Repo#checkout(treeish, callback)`
2012-02-15 15:51:45 +01:00
`git checkout <treeish>`
2014-06-19 21:34:10 +02:00
### `Repo#checkoutFile([files, options, ]callback)`
Checkout some files.
* `files` - File(s) to checkout. Pass `'.'` or nothing to checkout all files.
* `options` -
- `force` - `Boolean`
* `callback` - Receives `(err)` .
2013-03-17 18:00:22 +01:00
### `Repo#sync([[remote, ]branch, ]callback)`
2013-03-17 16:44:20 +01:00
Sync the current branch with the remote, keeping all local changes intact.
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.
2013-03-17 18:00:22 +01:00
* `remote` - `String` (defaults to `origin` ).
* `branch` - `String` (defaults to `master` ).
* `callback` - Receives `(err)` .
2013-03-17 16:44:20 +01:00
2014-06-19 21:34:10 +02:00
### `Repo#reset([treeish, options, ]callback)`
Checkout files.
* `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)` .
2013-03-17 16:44:20 +01:00
2012-02-15 15:51:45 +01:00
## Commit
2012-03-23 15:39:27 +01:00
### `Commit#id`
2012-02-15 15:51:45 +01:00
`String` - The commit's SHA.
2012-03-23 15:39:27 +01:00
### `Commit#parents`
2012-02-15 15:51:45 +01:00
`Commit[]`
2012-09-15 10:49:39 +02:00
### `Commit#tree()`
`Tree` - The commit's content tree.
2012-02-15 15:51:45 +01:00
2012-03-23 15:39:27 +01:00
### `Commit#author`
2012-02-15 15:51:45 +01:00
`Actor`
2012-03-23 15:39:27 +01:00
### `Commit#authored_date`
2012-02-15 15:51:45 +01:00
`Date`
2012-03-23 15:39:27 +01:00
### `Commit#committer`
2012-02-15 15:51:45 +01:00
`Actor`
2012-03-23 15:39:27 +01:00
### `Commit#committed_date`
2012-02-15 15:51:45 +01:00
`Date`
2012-03-23 15:39:27 +01:00
### `Commit#message`
2012-02-15 15:51:45 +01:00
`String`
## Head
2012-03-23 15:39:27 +01:00
### `Head#name`
2012-02-15 15:51:45 +01:00
`String`
2012-03-23 15:39:27 +01:00
### `Head#commit`
2012-02-15 15:51:45 +01:00
`Commit`
## Tag
2012-03-23 15:39:27 +01:00
### `Tag#name`
2012-02-15 15:51:45 +01:00
`String`
2012-03-23 15:39:27 +01:00
### `Tag#commit`
2012-02-15 15:51:45 +01:00
`Commit`
2012-03-23 15:39:27 +01:00
### `Tag#message(callback)`
2012-02-15 15:51:45 +01:00
The callback receives `(err, message)` (`message` is a String).
2012-03-23 15:39:27 +01:00
### `Tag#tagger(callback)`
2012-02-15 15:51:45 +01:00
The callback receives `(err, actor)` .
2012-03-23 15:39:27 +01:00
### `Tag#tag_date(callback)`
2012-02-15 15:51:45 +01:00
The callback receives `(err, date)` .
2013-10-06 00:40:33 +02:00
## Config
2013-10-06 19:05:57 +02:00
### `Config#items`
2013-10-06 18:58:16 +02:00
`Object` - The keys are dotted precisely as the console output from `git config` . E.g., `{'user.name': 'John Doe'}`
2013-10-06 00:40:33 +02:00
2012-02-15 15:51:45 +01:00
## Status
2012-03-23 15:39:27 +01:00
### `Status#clean`
2012-02-15 15:51:45 +01:00
`Boolean`
2012-03-23 15:39:27 +01:00
### `Status#files`
2012-02-15 15:51:45 +01:00
`Object` - The keys are files, the values objects indicating whether or not
the file is staged, tracked, etc.
Each file has the following properties:
2014-06-19 15:08:21 +02:00
* `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 |
2012-02-15 15:51:45 +01:00
* `staged` - `Boolean`
* `tracked` - `Boolean`
## Actor
2012-03-23 15:39:27 +01:00
### `Actor#name`
2012-02-15 15:51:45 +01:00
`String`
2012-03-23 15:39:27 +01:00
### `Actor#email`
2012-02-15 15:51:45 +01:00
`String`
2012-03-23 15:39:27 +01:00
### `Actor#hash`
2012-02-22 19:44:46 +01:00
`String` - The MD5 hash of the actor's email. Useful for displaying
[Gravatar ](http://en.gravatar.com/ ) avatars.
2012-02-15 15:51:45 +01:00
## Tree
2012-03-23 15:39:27 +01:00
### `Tree#id`
2012-02-15 15:51:45 +01:00
`String` - SHA1
2012-03-23 15:39:27 +01:00
### `Tree#contents(callback)`
2012-02-15 15:51:45 +01:00
* `callback` - Receives `(err, children)` .
* `children` - An array of `Blob` s, `Tree` s, and `Submodule` s.
2012-03-23 15:39:27 +01:00
### `Tree#blobs(callback)`
2012-02-15 15:51:45 +01:00
* `callback` - Receives `(err, child_blobs)` .
* `children` - `[Blob]`
2012-03-23 15:39:27 +01:00
### `Tree#trees(callback)`
2012-02-15 15:51:45 +01:00
* `callback` - Receives `(err, child_trees)` .
* `children` - `[Tree]`
2012-03-23 15:39:27 +01:00
### `Tree#find(directory, callback)`
2012-02-15 15:51:45 +01:00
* `directory` - `String`
* `callback` - Receives `(err, thing)` .
## Blob
2012-03-23 15:39:27 +01:00
### `Blob#id`
2012-02-15 15:51:45 +01:00
`String` - SHA1
2012-03-23 15:39:27 +01:00
### `Blob#mode`
2012-02-15 15:51:45 +01:00
`String`
2012-03-23 15:39:27 +01:00
### `Blob#data(callback)`
2012-02-15 15:51:45 +01:00
* `callback` - `(err, data)`
2014-03-06 03:51:45 +01:00
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()
### `Blob#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)
2012-02-15 15:51:45 +01:00
## Submodule
2012-03-23 15:39:27 +01:00
### `Submodule#id`
2012-02-15 15:51:45 +01:00
`String`
2012-03-23 15:39:27 +01:00
### `Submodule#name`
2012-02-15 15:51:45 +01:00
`String`
2012-03-23 15:39:27 +01:00
### `Submodule#mode`
2012-02-15 15:51:45 +01:00
`String`
2012-03-23 15:39:27 +01:00
### `Submodule#url(callback)`
2012-02-15 15:51:45 +01:00
Get the url the submodule points to.
# License
See LICENSE.