1
0
mirror of https://github.com/danog/gift.git synced 2024-11-30 04:19:37 +01:00

Merge pull request #6 from IgorMuzyka/master

Added current_commit function to repo.coffee
This commit is contained in:
Luke Plaster 2014-02-20 21:28:29 +01:00
commit fc500219aa
2 changed files with 39 additions and 2 deletions

View File

@ -63,7 +63,7 @@ Or to a different tag or branch.
repo.commits "v0.0.3", (err, commits) ->
Limit the maximum number of commits returned.
Limit the maximum number of commits returned (by default limit is 10).
repo.commits "master", 30, (err, commits) ->
@ -71,6 +71,15 @@ Skip some (for pagination):
repo.commits "master", 30, 30, (err, commits) ->
To get unlimited amount of commits:
repo.commits "master", -1, (err, commits) ->
### `Repo#current_commit(callback)`
Get current commit
The callback receives `(err, commit)`.
### `Repo#tree([treeish]) => Tree`
The `Tree` object for the treeish (which defaults to "master").

View File

@ -73,6 +73,9 @@ module.exports = class Repo
#
# # Skip some (for pagination):
# repo.commits "master", 30, 30, (err, commits) ->
#
# # Do not limit commits amount
# repo.commits "master", -1, (err, commits) ->
#
commits: (start, limit, skip, callback) ->
[skip, callback] = [callback, skip] if !callback
@ -82,8 +85,33 @@ module.exports = class Repo
start ?= "master"
limit ?= 10
skip ?= 0
options = {skip}
Commit.find_all this, start, {"max-count": limit, skip}, callback
if limit != -1
options["max-count"] = limit
Commit.find_all this, start, options, callback
# Internal: Returns current commit id
#
# callback - Receives `(err, id)`.
#
current_commit_id: (callback) ->
@git "rev-parse HEAD", {}, []
, (err, stdout, stderr) =>
return callback err if err
return callback null, _.first stdout.split "\n"
# Public:
#
# callback - Receives `(err, commit)`
#
current_commit: (callback) ->
@current_commit_id (err, commit_id) =>
return callback err if err
Commit.find this, commit_id, callback
# Public: The tree object for the treeish or master.