aboutsummaryrefslogtreecommitdiff
path: root/lib/detectLocalGit.js
diff options
context:
space:
mode:
authorChas DeVeas <[email protected]>2017-03-30 12:17:18 -0400
committerNick Merwin <[email protected]>2017-03-30 09:17:18 -0700
commitef7e81120fde6ee5b197e2c8d53bc949cf09a390 (patch)
tree1648c839786c27f1eea4539fedbc95dac734eede /lib/detectLocalGit.js
parente47696495d7a6640763978d80601ec51cd41de6c (diff)
downloadnode-coveralls-ef7e81120fde6ee5b197e2c8d53bc949cf09a390.tar.xz
node-coveralls-ef7e81120fde6ee5b197e2c8d53bc949cf09a390.zip
Parse commit from packed refs if not available in refs dir. (#163)
* Add .idea to .gitignore * Added alternative method for parsing current commit with test. * Fixing test. * Remove dependency on fs-extra.
Diffstat (limited to 'lib/detectLocalGit.js')
-rw-r--r--lib/detectLocalGit.js21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/detectLocalGit.js b/lib/detectLocalGit.js
index ac8ed29..46a9e67 100644
--- a/lib/detectLocalGit.js
+++ b/lib/detectLocalGit.js
@@ -23,6 +23,25 @@ module.exports = function detectLocalGit() {
if (!branch)
return { git_commit: head };
- var commit = fs.readFileSync(path.join(dir, '.git', 'refs', 'heads', branch), 'utf-8').trim();
+ var commit = _parseCommitHashFromRef(dir, branch);
+
return { git_commit: commit, git_branch: branch };
};
+
+function _parseCommitHashFromRef(dir, branch) {
+ var ref = path.join(dir, '.git', 'refs', 'heads', branch);
+ if (fs.existsSync(ref)) {
+ return fs.readFileSync(ref, 'utf-8').trim();
+ } else {
+ // ref does not exist; get it from packed-refs
+ var commit = '';
+ var packedRefs = path.join(dir, '.git', 'packed-refs');
+ var packedRefsText = fs.readFileSync(packedRefs, 'utf-8');
+ packedRefsText.split('\n').forEach(function (line) {
+ if (line.match('refs/heads/'+branch)) {
+ commit = line.split(' ')[0];
+ }
+ });
+ return commit;
+ }
+}