git-repo-info
Advanced tools
Comparing version 2.0.0 to 2.1.0
23
index.js
@@ -15,2 +15,3 @@ 'use strict'; | ||
var stat = fs.statSync(gitPath); | ||
var root = path.dirname(path.resolve(gitPath)); | ||
if (stat.isDirectory()) { | ||
@@ -22,2 +23,3 @@ return { | ||
commonGitDir: gitPath, | ||
root: root, | ||
}; | ||
@@ -35,4 +37,3 @@ } else { | ||
if (fs.existsSync(commonDirPath)) { | ||
// this directory contains a `commondir` file; we're within a linked | ||
// worktree | ||
// this directory contains a `commondir` file; we're in a linked worktree | ||
@@ -45,2 +46,3 @@ var commonDirRelative = fs.readFileSync(commonDirPath).toString().replace(/\r?\n$/, ''); | ||
commonGitDir: commonDir, | ||
root: path.dirname(commonDir), | ||
}; | ||
@@ -52,2 +54,3 @@ } else { | ||
commonGitDir: worktreeGitDir, | ||
root: root, | ||
}; | ||
@@ -102,3 +105,3 @@ } | ||
function getLinesForRefPath(packedRefsFile, type, refPath) { | ||
return packedRefsFile.split('\n').reduce(function(acc, line, idx, arr) { | ||
return packedRefsFile.split(/\r?\n/).reduce(function(acc, line, idx, arr) { | ||
var targetLine = line.indexOf('^') > -1 ? arr[idx-1] : line; | ||
@@ -141,3 +144,3 @@ return doesLineMatchRefPath(type, line, refPath) ? acc.concat(targetLine) : acc; | ||
if (objectContents.slice(0,3) === 'tag') { | ||
var sections = objectContents.split(/\0|\n/); | ||
var sections = objectContents.split(/\0|\r?\n/); | ||
var sha = sections[1].slice(7); | ||
@@ -224,2 +227,4 @@ | ||
root: null, | ||
commonGitDir: null, | ||
worktreeGitDir: null, | ||
lastTag: null, | ||
@@ -232,5 +237,7 @@ commitsSinceLastTag: 0, | ||
try { | ||
result.root = path.resolve(gitPathInfo.commonGitDir, '..'); | ||
result.root = gitPathInfo.root; | ||
result.commonGitDir = gitPathInfo.commonGitDir; | ||
result.worktreeGitDir = gitPathInfo.worktreeGitDir; | ||
var headFilePath = path.join(gitPathInfo.worktreeGitDir, 'HEAD'); | ||
var headFilePath = path.join(gitPathInfo.worktreeGitDir, 'HEAD'); | ||
@@ -302,3 +309,3 @@ if (fs.existsSync(headFilePath)) { | ||
return objectContents.split(/\0|\n/) | ||
return objectContents.split(/\0|\r?\n/) | ||
.filter(function(item) { | ||
@@ -328,3 +335,3 @@ return !!item; | ||
case 'parent': | ||
data.parents = section.split('\n').map(p => p.split(' ')[1]); | ||
data.parents = section.split(/\r?\n/).map(p => p.split(' ')[1]); | ||
break; | ||
@@ -331,0 +338,0 @@ default: |
{ | ||
"name": "git-repo-info", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Retrieve current sha and branch name from a git repo.", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"test": "mocha tests", | ||
"preversion": "npm test", | ||
"postversion": "git push && git push --tags && npm publish" | ||
"test": "mocha tests" | ||
}, | ||
@@ -21,3 +21,3 @@ "repository": { | ||
], | ||
"author": "Robert Jackson", | ||
"author": "Robert Jackson <me@rwjblue.com>", | ||
"license": "MIT", | ||
@@ -29,4 +29,4 @@ "bugs": { | ||
"devDependencies": { | ||
"mocha": "^1.21.4", | ||
"mocha-jshint": "^1.1.0" | ||
"mocha": "^4.1.0", | ||
"mocha-jshint": "^2.3.1" | ||
}, | ||
@@ -33,0 +33,0 @@ "engines": { |
@@ -25,2 +25,8 @@ ## git-repo-info | ||
info.commitMessage // commit message for the current sha | ||
info.root // root directory for the Git repo or submodule | ||
// (if in a worktree, this is the directory containing the original copy) | ||
info.commonGitDir // directory containing Git metadata for this repo or submodule | ||
// (if in a worktree, this is the primary Git directory for the repo) | ||
info.worktreeGitDir // if in a worktree, the directory containing Git metadata specific to | ||
// this worktree; otherwise, this is the same as `commonGitDir`. | ||
``` | ||
@@ -27,0 +33,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14187
4
326
38