summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Paddock <guy.paddock@redbottledesign.com>2017-02-09 20:07:14 -0500
committerGuy Paddock <guy.paddock@redbottledesign.com>2017-02-09 20:07:14 -0500
commit77cca390bc4efc447215f425d53618f11d02f85a (patch)
treee9aba9a4693b1215c627acc6477828131e888ddf
parentfb76ed35e9893f713f5ab6001e0334f947c5f1ab (diff)
downloadgit-hours-77cca390bc4efc447215f425d53618f11d02f85a.zip
git-hours-77cca390bc4efc447215f425d53618f11d02f85a.tar.gz
git-hours-77cca390bc4efc447215f425d53618f11d02f85a.tar.bz2
Adds a filter for per-branch statistics
-rwxr-xr-xsrc/index.js35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/index.js b/src/index.js
index ab6b671..2c8fb2b 100755
--- a/src/index.js
+++ b/src/index.js
@@ -19,7 +19,8 @@ var config = {
// Include commits since time x
since: 'always',
- until: 'always'
+ until: 'always',
+ branch: null
};
function main() {
@@ -30,7 +31,7 @@ function main() {
config.since = parseSinceDate(config.since);
config.until = parseUntilDate(config.until);
- getCommits('.').then(function(commits) {
+ getCommits('.', config.branch).then(function(commits) {
var commitsByEmail = _.groupBy(commits, function(commit) {
return commit.author.email || 'unknown';
});
@@ -105,6 +106,11 @@ function parseArgs() {
'Analyze data until certain date.' +
' [always|yesterday|today|lastweek|thisweek|yyyy-mm-dd] Default: ' + config.until,
String
+ )
+ .option(
+ '-b, --branch [branch name]',
+ 'Analyze only data on the specified branch. Default: ' + config.branch,
+ String
);
program.on('--help', function() {
@@ -132,6 +138,10 @@ function parseArgs() {
console.log('');
console.log(' $ git hours --since 2015-01-31');
console.log('');
+ console.log(' - Estimate hours work in repository on the "develop" branch');
+ console.log('');
+ console.log(' $ git hours --branch develop');
+ console.log('');
console.log(' For more details, visit https://github.com/kimmobrunfeldt/git-hours');
console.log('');
});
@@ -170,7 +180,8 @@ function mergeDefaultsWithArgs(conf) {
maxCommitDiffInMinutes: program.maxCommitDiff || conf.maxCommitDiffInMinutes,
firstCommitAdditionInMinutes: program.firstCommitAdd || conf.firstCommitAdditionInMinutes,
since: program.since || conf.since,
- until: program.until || conf.until
+ until: program.until || conf.until,
+ branch: program.branch || conf.branch
};
}
@@ -206,15 +217,23 @@ function estimateHours(dates) {
}
// Promisify nodegit's API of getting all commits in repository
-function getCommits(gitPath) {
+function getCommits(gitPath, branch) {
return git.Repository.open(gitPath)
.then(function(repo) {
var allReferences = getAllReferences(repo);
- return Promise.filter(allReferences, function(reference) {
- return reference.match(/refs\/heads\/.*/);
- })
- .map(function(branchName) {
+ if (branch) {
+ filterPromise = Promise.filter(allReferences, function(reference) {
+ return (reference == ('refs/heads/' + branch));
+ });
+ }
+ else {
+ filterPromise = Promise.filter(allReferences, function(reference) {
+ return reference.match(/refs\/heads\/.*/);
+ });
+ }
+
+ return filterPromise.map(function(branchName) {
return getBranchLatestCommit(repo, branchName);
})
.map(function(branchLatestCommit) {