1
0
mirror of https://github.com/danog/gift.git synced 2024-12-02 09:17:55 +01:00
gift/README.md

309 lines
6.5 KiB
Markdown
Raw Normal View History

2012-02-15 15:51:45 +01:00
# Gift
2012-02-15 16:00:43 +01:00
2013-10-11 23:53:10 +02:00
### Not active, see [this fork](https://github.com/notatestuser/gift)
2012-02-15 16:00:43 +01:00
[![Build Status](https://secure.travis-ci.org/sentientwaffle/gift.png?branch=master)](http://travis-ci.org/sentientwaffle/gift)
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)
# Installation
$ npm install gift
# API
For existing repositories:
2012-02-15 15:51:45 +01:00
git = require 'gift'
2012-02-15 15:51:45 +01:00
repo = git "path/to/repo"
# => #<Repo>
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>
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) ->
Limit the maximum number of commits returned.
repo.commits "master", 30, (err, commits) ->
Skip some (for pagination):
repo.commits "master", 30, 30, (err, commits) ->
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)`.
### `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>`.
### `Repo#remote_remove(name, callback)`
Remove a remote.
2012-03-23 15:39:27 +01:00
### `Repo#remote_fetch(name, callback)`
2012-02-15 15:51:45 +01:00
`git fetch <name>`
### `Repo#remote_push(name, callback)`
`git push <name>`
2012-03-23 15:39:27 +01:00
### `Repo#status(callback)`
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
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`
* `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>`
### `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.
* `remote` - `String` (defaults to `origin`).
* `branch` - `String` (defaults to `master`).
* `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-03-23 15:39:27 +01:00
### `Commit#tree(callback)`
2012-02-15 15:51:45 +01:00
* `callback` - Receives `(err, tree)`.
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)`.
## 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:
* `type` - "A" for added, "M" for modified, "D" for deleted.
* `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)`
## 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.