Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sentientwaffle committed Feb 15, 2012
0 parents commit 3ef68d9
Show file tree
Hide file tree
Showing 211 changed files with 5,425 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
node_modules
Empty file added .npmignore
Empty file.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2012 [DJG](https://github.com/sentientwaffle)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
248 changes: 248 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
# Gift
A basic Node.js wrapper for the Git CLI. The API is based on
[Grit](https://github.com/mojombo/grit)

# Installation

$ npm install gift

# API

git = require 'gift'

repo = git "path/to/repo"
# => #<Repo>

## Repo
### Repo#path
`String` - The path to the repository.

### Repo#commits([treeish, [limit, [skip, ]]]callback)
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) ->

### Repo#tree([treeish]) => Tree
The `Tree` object for the treeish (which defaults to "master").

repo.tree().contents (err, children) ->
for child in children
console.log child.name

### Repo#diff(commitA, commitB, [paths, ]callback)
Get the difference between the trees.

The callback receives `(err, diffs)`.

### Repo#remotes(callback)
Get the repository's remotes.

Receives `(err, remotes)`, where each remote is a Ref.

### Repo#remote_list(callback)
Get a list of the repository's remote names.

Get the string names of each of the remotes.

### Repo#remote_add(name, url, callback)
Equivalent to `git remote add <name> <url>`.

### Repo#remote_fetch(name, callback)
`git fetch <name>`


### Repo#status(callback)
The callback receives `(err, status)`.

### Repo#create_branch(name, callback)
Create a new branch with `name`, and call the callback when complete
with an error, if one occurred.

### Repo#delete_branch(name, callback)
Delete the branch `name`, and call the callback with an error, if one occurred.

### Repo#tags(callback)
Get a list of `Tag`s.

### Repo#create_tag(name, callback)
Create a tab with the given name.

### Repo#delete_tag(name, callback)
Delete the tag with the given name.

### Repo#branches(callback)
`callback` receives `(err, heads)`.

### Repo#create_branch(name, callback)
Create a branch with the given name.

### Repo#delete_branch(delete, callback)
Delete the branch with the given name.

### Repo#branch([branch, ]callback)
Get a branch.

* `branch` - The name of the branch to get. Defaults to the
currently checked out branch.
* `callback` - Receives `(err, head)`.


### Repo#commit(message, [options, ]callback)
Commit some changes.

* `message` - `String`
* `options` -
- `all` - `Boolean`
- `amend` - `Boolean`
* `callback` - Receives `(err)`.

### Repo#add(files, callback)
`git add <files>`

### Repo#remove(files, callback)
`git rm <files>`

### Repo#checkout(treeish, callback)
`git checkout <treeish>`

## Commit
### Commit#id
`String` - The commit's SHA.

### Commit#parents
`Commit[]`

### Commit#tree(callback)

* `callback` - Receives `(err, tree)`.

### Commit#author
`Actor`
### Commit#authored_date
`Date`
### Commit#committer
`Actor`
### Commit#committed_date
`Date`
### Commit#message
`String`


## Head
### Head#name
`String`

### Head#commit
`Commit`

## Tag
### Tag#name
`String`

### Tag#commit
`Commit`

### Tag#message(callback)
The callback receives `(err, message)` (`message` is a String).

### Tag#tagger(callback)
The callback receives `(err, actor)`.

### Tag#tag_date(callback)
The callback receives `(err, date)`.

## Status
### Status#clean
`Boolean`

### Status#files
`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
### Actor#name
`String`

### Actor#email
`String`


## Tree
### Tree#id
`String` - SHA1

### Tree#contents(callback)

* `callback` - Receives `(err, children)`.
* `children` - An array of `Blob`s, `Tree`s, and `Submodule`s.

### Tree#blobs(callback)

* `callback` - Receives `(err, child_blobs)`.
* `children` - `[Blob]`

### Tree#trees(callback)

* `callback` - Receives `(err, child_trees)`.
* `children` - `[Tree]`

### Tree#find(directory, callback)

* `directory` - `String`
* `callback` - Receives `(err, thing)`.

## Blob
### Blob#id
`String` - SHA1

### Blob#mode
`String`

### Blob#data(callback)

* `callback` - `(err, data)`

## Submodule
### Submodule#id
`String`

### Submodule#name
`String`

### Submodule#mode
`String`

### Submodule#url(callback)
Get the url the submodule points to.


# License
See LICENSE.


31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ "name": "gift"
, "version": "0.0.1"
, "description": "a Git wrapper library"
, "keywords": ["git"]
, "homepage": "https://github.com/sentientwaffle/gift"
, "bugs": {"url": "https://github.com/sentientwaffle/gift/issues"}
, "author":
{ "name": "sentientwaffle"
, "url": "http://sentientwaffle.github.com/"
}

, "main": "./lib/index"

, "scripts":
{ "test": "mocha"
, "prepublish": "coffee -o lib -c src"
}

, "repository":
{ "type": "git"
, "url": "https://github.com/sentientwaffle/gift.git"
}

, "dependencies": {"underscore": "1.x.x"}
, "devDependencies":
{ "should": "0.4.x"
, "mocha": "0.5.x"
}

, "engines": {"node": "> 0.4.1"}
}
16 changes: 16 additions & 0 deletions src/actor.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = class Actor
constructor: (@name, @email) ->

# Public: Get a string representation of the Actor.
toString: ->
"#{@name} <#{@email}>"

# Public: Parse an Actor from a "bla <[email protected]>" string.
#
# Returns Actor.
@from_string: (str) ->
if /<.+>/.test str
[m, name, email] = /(.*) <(.+?)>/.exec str
return new Actor(name, email)
else
return new Actor(str, null)
17 changes: 17 additions & 0 deletions src/blob.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
path = require 'path'

module.exports = class Blob
constructor: (@repo, attrs) ->
{@id, @name, @mode} = attrs

# Public: Get the blob contents.
#
# callback - Receives `(err, data)`.
#
data: (callback) ->
@repo.git "cat-file", {p: true}, @id
, (err, stdout, stderr) ->
return callback err, stdout

toString: ->
"#<Blob '#{@id}'>"
Loading

0 comments on commit 3ef68d9

Please sign in to comment.