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 | |
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
-rw-r--r-- | .travis.yml | 8 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rwxr-xr-x | src/index.js | 36 |
3 files changed, 27 insertions, 19 deletions
diff --git a/.travis.yml b/.travis.yml index e80033d..1ccca88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: node_js node_js: - '0.12' sudo: false +git: + depth: 1000000 before_script: - npm install -g nodegit script: @@ -9,3 +11,9 @@ script: notifications: email: - kimmobrunfeldt+git-hours@gmail.com +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - libstdc++-4.9-dev diff --git a/package.json b/package.json index 857c81d..1f1c525 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "commander": "^2.2.0", "lodash": "^2.4.1", "moment": "^2.10.6", - "nodegit": "^0.4.1" + "nodegit": "^0.11.0" }, "devDependencies": { "eslint": "^1.5.1", 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) { |