summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRuslan Gainutdinov <ruslan.gainutdinov@futurice.com>2018-09-12 10:41:47 +0300
committerRuslan Gainutdinov <ruslan.gainutdinov@futurice.com>2018-09-12 10:41:47 +0300
commit20669d087ff66fd5dac012571afe353ab1f0c986 (patch)
treef88b93f78c8e69d0737fefabae4e45601f55f44d
parent305f88b4299f39492aad4a81bc396831589cd935 (diff)
parent1d4117af7a61329c09eb1e04edef99ed0bec49ec (diff)
downloadgit-hours-20669d087ff66fd5dac012571afe353ab1f0c986.zip
git-hours-20669d087ff66fd5dac012571afe353ab1f0c986.tar.gz
git-hours-20669d087ff66fd5dac012571afe353ab1f0c986.tar.bz2
Merge GuyPaddock:feature/per-branch-filter
-rw-r--r--README.md5
-rwxr-xr-xsrc/index.js38
2 files changed, 34 insertions, 9 deletions
diff --git a/README.md b/README.md
index b0218c1..63296fd 100644
--- a/README.md
+++ b/README.md
@@ -104,6 +104,7 @@ Help
-u, --until [until-certain-date] Analyze data until certain date. [always|yesterday|today|lastweek|thisweek|yyyy-mm-dd] Default: always
-m, --merge-request [false|true] Include merge requests into calculation. Default: true
-p, --path [git-repo] Git repository to analyze. Default: .
+ -b, --branch [branch-name] Analyze only data on the specified branch. Default: all branches
Examples:
@@ -126,6 +127,10 @@ Help
- Estimate hours work in repository since 2015-01-31
$ git hours --since 2015-01-31
+
+ - Estimate hours work in repository on the "master" branch
+
+ $ git hours --branch master
For more details, visit https://github.com/kimmobrunfeldt/git-hours
diff --git a/src/index.js b/src/index.js
index 4bb39f0..2f6478e 100755
--- a/src/index.js
+++ b/src/index.js
@@ -30,7 +30,9 @@ var config = {
// Aliases of emails for grouping the same activity as one person
emailAliases: {
"linus@torvalds.com": "linus@linux.com"
- }
+ },
+
+ branch: null
};
function main() {
@@ -55,7 +57,7 @@ function main() {
}
}
- getCommits(config.gitPath).then(function(commits) {
+ getCommits(config.gitPath, config.branch).then(function(commits) {
var commitsByEmail = _.groupBy(commits, function(commit) {
var email = commit.author.email || 'unknown'
if (config.emailAliases !== undefined && config.emailAliases[email] !== undefined) {
@@ -155,6 +157,11 @@ function parseArgs() {
'Git repository to analyze.' +
' Default: ' + config.gitPath,
String
+ )
+ .option(
+ '-b, --branch [branch-name]',
+ 'Analyze only data on the specified branch. Default: ' + config.branch,
+ String
);
program.on('--help', function() {
@@ -182,6 +189,10 @@ function parseArgs() {
console.log('');
console.log(' $ git hours --since 2015-01-31');
console.log('');
+ console.log(' - Estimate hours work in repository on the "master" branch');
+ console.log('');
+ console.log(' $ git hours --branch master');
+ console.log('');
console.log(' For more details, visit https://github.com/kimmobrunfeldt/git-hours');
console.log('');
});
@@ -237,7 +248,8 @@ function mergeDefaultsWithArgs(conf) {
since: program.since || conf.since,
until: program.until || conf.until,
gitPath: program.path || conf.gitPath,
- mergeRequest: program.mergeRequest !== undefined ? (program.mergeRequest == "true") : conf.mergeRequest
+ mergeRequest: program.mergeRequest !== undefined ? (program.mergeRequest == "true") : conf.mergeRequest,
+ branch: program.branch || conf.branch
};
}
@@ -273,15 +285,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) {