diff options
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) { |