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.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",

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