Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

git-repo-info

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

git-repo-info - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

tests/fixtures/tagged-commit-packed/dot-git/HEAD

46

index.js

@@ -32,2 +32,33 @@ 'use strict';

function findPackedTag(gitPath, sha) {
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(sha) > -1;
})[0];
if (tagLine) {
return tagLine.split('tags/')[1];
}
}
}
function findTag(gitPath, sha) {
var tag = findPackedTag(gitPath, sha);
if (tag) { return tag; }
var tagsPath = path.join(gitPath, 'refs', 'tags');
if (!fs.existsSync(tagsPath)) { return; }
var tags = fs.readdirSync(tagsPath);
for (var i = 0, l = tags.length; i < l; i++) {
var tagPath = path.join(tagsPath, tags[i]);
if (fs.readFileSync(tagPath, { encoding: 'utf8' }).indexOf(sha) > -1) {
return tags[i];
}
}
}
module.exports = function(gitPath) {

@@ -65,12 +96,5 @@ if (!gitPath) { gitPath = findRepo(); }

// 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];
}
var tag = findTag(gitPath, result.sha);
if (tag) {
result.tag = tag;
}

@@ -86,2 +110,2 @@ }

module.exports._findRepo = findRepo;
module.exports._changeGitDir = changeGitDir;
module.exports._changeGitDir = changeGitDir;
{
"name": "git-repo-info",
"version": "1.0.3",
"version": "1.0.4",
"description": "Retrieve current sha and branch name from a git repo.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -82,4 +82,4 @@ 'use strict';

it('returns an object with repo info, including the tag', function() {
var repoRoot = path.join(testFixturesPath, 'tagged-commit');
it('returns an object with repo info, including the tag (packed tags)', function() {
var repoRoot = path.join(testFixturesPath, 'tagged-commit-packed');
var result = repoInfo(path.join(repoRoot, gitDir))

@@ -96,3 +96,17 @@

});
it('returns an object with repo info, including the tag (unpacked tags)', function() {
var repoRoot = path.join(testFixturesPath, 'tagged-commit-unpacked');
var result = repoInfo(path.join(repoRoot, gitDir))
var expected = {
branch: 'master',
sha: '5359aabd3872d9ffd160712e9615c5592dfe6745',
abbreviatedSha: '5359aabd38',
tag: 'my-tag'
}
assert.deepEqual(result, expected);
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc