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.2 to 1.0.3

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

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;

2

package.json
{
"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);
});
});
});
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