Skip to content

Commit

Permalink
added last commit id, fixes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Apr 6, 2015
1 parent b6d7eb5 commit 2ec48d9
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 10 deletions.
1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
registry=http://registry.npmjs.org/
16 changes: 15 additions & 1 deletion README.md
@@ -1,4 +1,4 @@
# ggit v0.10.2
# ggit v0.11.0

> Local promise-returning git command wrappers
Expand Down Expand Up @@ -217,6 +217,20 @@ require('ggit')
```


### lastCommitId

Returns last commit id

```js
require('ggit')
.lastCommitId()
.then(function (str) {
// str is full SHA id string
})
.done();
```





Expand Down
12 changes: 12 additions & 0 deletions docs/last-commit-id.md
@@ -0,0 +1,12 @@
## lastCommitId

Returns last commit id

```js
require('ggit')
.lastCommitId()
.then(function (str) {
// str is full SHA id string
})
.done();
```
1 change: 1 addition & 0 deletions docs/use.md
Expand Up @@ -11,3 +11,4 @@
{%= _.doc("./docs/tracked-files.md") %}
{%= _.doc("./docs/commit-per-line.md") %}
{%= _.doc("./docs/numstat.md") %}
{%= _.doc("./docs/last-commit-id.md") %}
21 changes: 13 additions & 8 deletions index.js
@@ -1,6 +1,6 @@
var getOneLineLog = require('./src/get-one-line-log');

module.exports = {
var actions = {
getOneLineLog: getOneLineLog,
cloneRepo: require('./src/clone-repo'),
exec: require('./src/exec'),
Expand All @@ -12,18 +12,23 @@ module.exports = {
commits: require('./src/commits'),
trackedFiles: require('./src/tracked-source-files'),
commitPerLine: require('./src/commit-per-line'),
numstat: require('./src/commit-numstat')
numstat: require('./src/commit-numstat'),
lastCommitId: require('./src/last-commit-id')
};

module.exports = actions;

if (!module.parent) {
/*
getOneLineLog({
n: 4,
remote: 'origin',
branch: 'master'
})
.done(function (stdout) {
console.log(stdout);
}, function (err) {
console.error(err);
});
})*/
actions.lastCommitId()
.done(function (stdout) {
console.log(stdout);
}, function (err) {
console.error(err);
});
}
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "ggit",
"description": "Local promise-returning git command wrappers",
"version": "0.10.2",
"version": "0.11.0",
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",
"bin": {
"ggit": "./index.js"
Expand Down
17 changes: 17 additions & 0 deletions src/last-commit-id.js
@@ -0,0 +1,17 @@
require('lazy-ass');
var check = require('check-more-types');
var exec = require('./exec');

/*
Returns the last commit id
*/
function lastCommitId() {
var cmd = 'git log --format="%H" -n 1';
return exec(cmd)
.then(function (str) {
la(check.unemptyString(str), 'expected commit id string', str);
return str.trim();
});
}

module.exports = lastCommitId;

0 comments on commit 2ec48d9

Please sign in to comment.