git-repo-info
Advanced tools
Comparing version 1.0.2 to 1.0.3
19
index.js
@@ -38,3 +38,4 @@ 'use strict'; | ||
abbreviatedSha: null, | ||
branch: null | ||
branch: null, | ||
tag: null | ||
} | ||
@@ -51,2 +52,3 @@ | ||
// Find branch and SHA | ||
if (refPath) { | ||
@@ -62,2 +64,15 @@ var branchPath = path.join(gitPath, refPath.trim()); | ||
result.abbreviatedSha = result.sha.slice(0,10); | ||
// Find tag | ||
var packedRefsFilePath = path.join(gitPath, 'packed-refs'); | ||
if (fs.existsSync(packedRefsFilePath)) { | ||
var packedRefsFile = fs.readFileSync(packedRefsFilePath, {encoding: 'utf8'}); | ||
var tagLine = packedRefsFile.split('\n').filter(function(line) { | ||
return line.indexOf("refs/tags") > -1 && line.indexOf(result.sha) > -1; | ||
})[0]; | ||
if (tagLine) { | ||
result.tag = tagLine.split('tags/')[1]; | ||
} | ||
} | ||
} | ||
@@ -72,2 +87,2 @@ } catch (e) { | ||
module.exports._findRepo = findRepo; | ||
module.exports._changeGitDir = changeGitDir; | ||
module.exports._changeGitDir = changeGitDir; |
{ | ||
"name": "git-repo-info", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Retrieve current sha and branch name from a git repo.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,2 +15,3 @@ ## git-repo-info | ||
info.abbreviatedSha //=> will be the first 10 chars of the current sha | ||
info.tag //=> will be the tag for the current sha (or `null` if no tag exists) | ||
``` | ||
@@ -17,0 +18,0 @@ |
@@ -60,3 +60,4 @@ 'use strict'; | ||
sha: '5359aabd3872d9ffd160712e9615c5592dfe6745', | ||
abbreviatedSha: '5359aabd38' | ||
abbreviatedSha: '5359aabd38', | ||
tag: null | ||
} | ||
@@ -74,3 +75,4 @@ | ||
sha: '9dac893d5a83c02344d91e79dad8904889aeacb1', | ||
abbreviatedSha: '9dac893d5a' | ||
abbreviatedSha: '9dac893d5a', | ||
tag: null | ||
} | ||
@@ -80,3 +82,18 @@ | ||
}); | ||
it('returns an object with repo info, including the tag', function() { | ||
var repoRoot = path.join(testFixturesPath, 'tagged-commit'); | ||
var result = repoInfo(path.join(repoRoot, gitDir)) | ||
var expected = { | ||
branch: 'master', | ||
sha: '5359aabd3872d9ffd160712e9615c5592dfe6745', | ||
abbreviatedSha: '5359aabd38', | ||
tag: 'my-tag' | ||
} | ||
assert.deepEqual(result, expected); | ||
}); | ||
}); | ||
}); |
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
6324
13
136
23