git-repo-info
Advanced tools
Comparing version 1.2.0 to 1.3.0
41
index.js
@@ -13,2 +13,25 @@ 'use strict'; | ||
function findRepoHandleLinkedWorktree(gitPath) { | ||
var stat = fs.statSync(gitPath); | ||
if (stat.isDirectory()) { | ||
return { | ||
// for the base (non-linked) dir, there is no distinction between where we | ||
// find the HEAD file and where we find the rest of .git | ||
worktreeGitDir: gitPath, | ||
commonGitDir: gitPath, | ||
}; | ||
} else { | ||
var linkedGitDir = fs.readFileSync(gitPath).toString(); | ||
var worktreeGitDir = /gitdir: (.*)/.exec(linkedGitDir)[1]; | ||
var commonDirPath = path.join(worktreeGitDir, 'commondir'); | ||
var commonDirRelative = fs.readFileSync(commonDirPath).toString().replace(/\r?\n$/, ''); | ||
var commonDir = path.resolve(path.join(worktreeGitDir, commonDirRelative)); | ||
return { | ||
worktreeGitDir: path.resolve(worktreeGitDir), | ||
commonGitDir: commonDir, | ||
}; | ||
} | ||
} | ||
function findRepo(startingPath) { | ||
@@ -24,3 +47,3 @@ var gitPath, lastPath; | ||
if (fs.existsSync(gitPath)) { | ||
return gitPath; | ||
return findRepoHandleLinkedWorktree(gitPath); | ||
} | ||
@@ -123,3 +146,3 @@ | ||
module.exports = function(gitPath) { | ||
gitPath = findRepo(gitPath); | ||
var gitPathInfo = findRepo(gitPath); | ||
@@ -139,8 +162,8 @@ var result = { | ||
if (!gitPath) { return result; } | ||
if (!gitPathInfo) { return result; } | ||
try { | ||
result.root = path.resolve(gitPath, '..'); | ||
result.root = path.resolve(gitPathInfo.commonGitDir, '..'); | ||
var headFilePath = path.join(gitPath, 'HEAD'); | ||
var headFilePath = path.join(gitPathInfo.worktreeGitDir, 'HEAD'); | ||
@@ -158,3 +181,3 @@ if (fs.existsSync(headFilePath)) { | ||
refPath = refPath.trim(); | ||
var branchPath = path.join(gitPath, refPath); | ||
var branchPath = path.join(gitPathInfo.commonGitDir, refPath); | ||
@@ -165,3 +188,3 @@ result.branch = branchName; | ||
} else { | ||
result.sha = findPackedCommit(gitPath, refPath); | ||
result.sha = findPackedCommit(gitPathInfo.commonGitDir, refPath); | ||
} | ||
@@ -175,3 +198,3 @@ } else { | ||
// Find commit data | ||
var commitData = getCommitData(gitPath, result.sha); | ||
var commitData = getCommitData(gitPathInfo.commonGitDir, result.sha); | ||
if (commitData) { | ||
@@ -185,3 +208,3 @@ result = Object.keys(commitData).reduce(function(r, key) { | ||
// Find tag | ||
var tag = findTag(gitPath, result.sha); | ||
var tag = findTag(gitPathInfo.commonGitDir, result.sha); | ||
if (tag) { | ||
@@ -188,0 +211,0 @@ result.tag = tag; |
{ | ||
"name": "git-repo-info", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Retrieve current sha and branch name from a git repo.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
9188
216