Skip to content

Commit 677a547

Browse files
committed
Merge pull request #9 from slindberg/missing-tag-object
Fixed issue with misreported tag when git object does not exist
2 parents bfda44f + 17c1325 commit 677a547

File tree

7 files changed

+18
-1
lines changed

7 files changed

+18
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function commitForTag(gitPath, tag) {
4949
var taggedObject = fs.readFileSync(tagPath, { encoding: 'utf8' }).trim();
5050
var objectPath = path.join(gitPath, 'objects', taggedObject.slice(0, 2), taggedObject.slice(2));
5151

52-
if (!zlib.inflateSync) {
52+
if (!zlib.inflateSync || !fs.existsSync(objectPath)) {
5353
// we cannot support annotated tags on node v0.10 because
5454
// zlib does not allow sync access
5555
return taggedObject;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c1ee41c325d54f410b133e0018c7a6b1316f6cda
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
c1ee41c325d54f410b133e0018c7a6b1316f6cda

tests/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ describe('git-repo-info', function() {
112112
assert.deepEqual(result, expected);
113113
});
114114

115+
it('returns an object with repo info, including the tag (unpacked tags) when a tag object does not exist', function() {
116+
var repoRoot = path.join(testFixturesPath, 'tagged-commit-unpacked-no-object');
117+
var result = repoInfo(path.join(repoRoot, gitDir));
118+
119+
var expected = {
120+
branch: 'master',
121+
sha: 'c1ee41c325d54f410b133e0018c7a6b1316f6cda',
122+
abbreviatedSha: 'c1ee41c325',
123+
tag: 'awesome-tag'
124+
};
125+
126+
assert.deepEqual(result, expected);
127+
});
128+
115129
if (zlib.inflateSync) {
116130
it('returns an object with repo info, including the tag (annotated tags)', function() {
117131
var repoRoot = path.join(testFixturesPath, 'tagged-annotated');

0 commit comments

Comments
 (0)