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.3.1 to 1.4.0

57

index.js

@@ -72,3 +72,3 @@ 'use strict';

function findPackedTag(gitPath, refPath) {
function findPackedTags(gitPath, refPath) {
return getPackedRefsForType(gitPath, refPath, 'tag');

@@ -78,26 +78,30 @@ }

function findPackedCommit(gitPath, refPath) {
return getPackedRefsForType(gitPath, refPath, 'commit');
return getPackedRefsForType(gitPath, refPath, 'commit')[0];
}
function getPackedRefsForType(gitPath, refPath, type) {
var packedRefsFilePath = path.join(gitPath, 'packed-refs');
if (fs.existsSync(packedRefsFilePath)) {
var packedRefsFile = fs.readFileSync(packedRefsFilePath, { encoding: 'utf8' });
var shaLine = getLineForRefPath(packedRefsFile, type, refPath);
if (shaLine) {
var packedRefsFile = getPackedRefsFile(gitPath);
if (packedRefsFile) {
return getLinesForRefPath(packedRefsFile, type, refPath).map(function(shaLine) {
return getShaBasedOnType(type, shaLine);
}
});
}
return [];
}
function getLineForRefPath(packedRefsFile, type, refPath) {
return packedRefsFile.split('\n').filter(function(line) {
return doesLineMatchRefPath(type, line, refPath);
})[0];
function getPackedRefsFile(gitPath) {
var packedRefsFilePath = path.join(gitPath, 'packed-refs');
return fs.existsSync(packedRefsFilePath) ? fs.readFileSync(packedRefsFilePath, { encoding: 'utf8' }) : false;
}
function getLinesForRefPath(packedRefsFile, type, refPath) {
return packedRefsFile.split('\n').reduce(function(acc, line, idx, arr) {
var targetLine = line.indexOf('^') > -1 ? arr[idx-1] : line;
return doesLineMatchRefPath(type, line, refPath) ? acc.concat(targetLine) : acc;
}, []);
}
function doesLineMatchRefPath(type, line, refPath) {
var refPrefix = type === 'tag' ? 'refs/tags' : 'refs/heads';
return line.indexOf(refPrefix) > -1 && line.indexOf(refPath) > -1;
return (line.indexOf(refPrefix) > -1 || line.indexOf('^') > -1) && line.indexOf(refPath) > -1;
}

@@ -143,20 +147,25 @@

function findTag(gitPath, sha) {
var tag = findPackedTag(gitPath, sha);
if (tag) { return tag; }
var tags = findPackedTags(gitPath, sha)
.concat(findUnpackedTags(gitPath, sha));
tags.sort();
return tags.length ? tags[0] : false;
}
var tagsPath = path.join(gitPath, 'refs', 'tags');
if (!fs.existsSync(tagsPath)) { return false; }
var tags = fs.readdirSync(tagsPath);
function findUnpackedTags(gitPath, sha) {
var unpackedTags = [];
var tags = findLooseRefsForType(gitPath, 'tags');
for (var i = 0, l = tags.length; i < l; i++) {
tag = tags[i];
var commitAtTag = commitForTag(gitPath, tags[i]);
if (commitAtTag === sha) {
return tag;
unpackedTags.push(tags[i]);
}
}
return unpackedTags;
}
function findLooseRefsForType(gitPath, type) {
var refsPath = path.join(gitPath, 'refs', type);
return fs.existsSync(refsPath) ? fs.readdirSync(refsPath) : [];
}
module.exports = function(gitPath) {

@@ -163,0 +172,0 @@ var gitPathInfo = findRepo(gitPath);

{
"name": "git-repo-info",
"version": "1.3.1",
"version": "1.4.0",
"description": "Retrieve current sha and branch name from a git repo.",

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

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