diff options
author | Kimmo Brunfeldt <kimmobrunfeldt@gmail.com> | 2016-02-08 10:00:48 +0200 |
---|---|---|
committer | Kimmo Brunfeldt <kimmobrunfeldt@gmail.com> | 2016-02-08 10:00:48 +0200 |
commit | 568bd4288dc9f385e4f0fbdc10cda407d821f63f (patch) | |
tree | 42c5967fd42c40603029772c08b7e0955963fa51 /src/index.js | |
parent | a28d5d9118f5e2b048b7224272ef5d2137f9a42c (diff) | |
parent | 6e049ca1cb9b9c6539c7517874ccf21cd235f46e (diff) | |
download | git-hours-568bd4288dc9f385e4f0fbdc10cda407d821f63f.zip git-hours-568bd4288dc9f385e4f0fbdc10cda407d821f63f.tar.gz git-hours-568bd4288dc9f385e4f0fbdc10cda407d821f63f.tar.bz2 |
Merge pull request #17 from mrPjer/master
Update nodegit dependency and fix Travis build
Diffstat (limited to 'src/index.js')
-rwxr-xr-x | src/index.js | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/index.js b/src/index.js index 54e26a5..dd1ad8f 100755 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,7 @@ var git = require('nodegit'); var program = require('commander'); var _ = require('lodash'); var moment = require('moment'); -var exec = Promise.promisify(require('child_process').exec); +var fs = require('fs'); var DATE_FORMAT = 'YYYY-MM-DD'; @@ -22,6 +22,8 @@ var config = { }; function main() { + exitIfShallow(); + parseArgs(); config = mergeDefaultsWithArgs(config); config.since = parseSinceDate(config.since); @@ -62,6 +64,14 @@ function main() { }); } +function exitIfShallow() { + if (fs.existsSync(".git/shallow")) { + console.log("Cannot analyze shallow copies!"); + console.log("Please run git fetch --unshallow before continuing!"); + process.exit(1); + } +} + function parseArgs() { function int(val) { return parseInt(val, 10); @@ -183,9 +193,12 @@ function estimateHours(dates) { function getCommits(gitPath) { return git.Repository.open(gitPath) .then(function(repo) { - var branchNames = getBranchNames(gitPath); + var allReferences = getAllReferences(repo); - return Promise.map(branchNames, function(branchName) { + return Promise.filter(allReferences, function(reference) { + return reference.match(/refs\/heads\/.*/); + }) + .map(function(branchName) { return getBranchLatestCommit(repo, branchName); }) .map(function(branchLatestCommit) { @@ -209,21 +222,8 @@ function getCommits(gitPath) { }); } -function getBranchNames(gitPath) { - var cmd = "git branch --no-color | awk -F ' +' '! /\\(no branch\\)/ {print $2}'"; - return new Promise(function(resolve, reject) { - exec(cmd, {cwd: gitPath}, function(err, stdout, stderr) { - if (err) { - reject(err); - } - - resolve(stdout - .split('\n') - .filter(function(e) { return e; }) // Remove empty - .map(function(str) { return str.trim(); }) // Trim whitespace - ); - }); - }); +function getAllReferences(repo) { + return repo.getReferenceNames(git.Reference.TYPE.LISTALL); } function getBranchLatestCommit(repo, branchName) { |