diff --git a/README.md b/README.md index fe04fc7..846cca9 100755 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ return the result of `git rev-parse HEAD`; optional `filePath` parameter can be return the current branch; optional `filePath` parameter can be used to run the command against a repo outside the current working directory -#### `git.count()` → <Number> +#### `git.count([branch])` → <Number> -return the count of commits across all branches; this method will fail if the `git` command is not found in `PATH` +returns the count of commits across all branches; optional `branch` parameter can be used to limit the count to a specific branch; this method will fail if the `git` command is not found in `PATH` #### `git.date()` → <Date> diff --git a/index.js b/index.js index e0d0eea..e91b52e 100755 --- a/index.js +++ b/index.js @@ -168,8 +168,8 @@ function date() { return new Date(_command('git', ['log', '--no-color', '-n', '1', '--pretty=format:"%ad"'])); } -function count() { - return parseInt(_command('git', ['rev-list', '--all', '--count']), 10); +function count(branch) { + return parseInt(_command('git', ['rev-list', '--count', branch || '--all']), 10); } function log() { diff --git a/tests/index.js b/tests/index.js index 21a2dcf..2bea362 100644 --- a/tests/index.js +++ b/tests/index.js @@ -19,6 +19,10 @@ result = git.count(); assert.notEqual(result, 0, 'count() returns a non-zero number'); assert.equal(Math.abs(result), result, 'count() returns a positive number'); +result = git.count('HEAD'); +assert.notEqual(result, 0, 'count() returns a non-zero number'); +assert.equal(Math.abs(result), result, 'count() returns a positive number'); + result = git.date(); assert.equal(result instanceof Date, true, 'date() returns a date');