Skip to content

Commit 4f4a70d

Browse files
committed
Handle zlib.inflateSync being missing on node 0.10.
1 parent 211047a commit 4f4a70d

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ sudo: false
33
cache:
44
directories:
55
- node_modules
6+
7+
env:
8+
- NODE_VERSION=0.10
9+
- NODE_VERSION=0.12
10+
- NODE_VERSION=iojs

index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ function commitForTag(gitPath, tag) {
4848
var tagPath = path.join(gitPath, 'refs', 'tags', tag);
4949
var taggedObject = fs.readFileSync(tagPath, { encoding: 'utf8' }).trim();
5050
var objectPath = path.join(gitPath, 'objects', taggedObject.slice(0, 2), taggedObject.slice(2));
51+
52+
if (!zlib.inflateSync) {
53+
// we cannot support annotated tags on node v0.10 because
54+
// zlib does not allow sync access
55+
return taggedObject;
56+
}
57+
5158
var objectContents = zlib.inflateSync(fs.readFileSync(objectPath)).toString();
5259

5360
// 'tag 172\u0000object c1ee41c325d54f410b133e0018c7a6b1316f6cda\ntype commit\ntag awesome-tag\ntagger Robert Jackson <[email protected]> 1429100021 -0400\n\nI am making an annotated tag.\n'

tests/index.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var assert = require('assert');
44
var path = require('path');
55
var repoInfo = require('../index');
6+
var zlib = require('zlib');
67

78
require('mocha-jshint')();
89

@@ -111,18 +112,20 @@ describe('git-repo-info', function() {
111112
assert.deepEqual(result, expected);
112113
});
113114

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

0 commit comments

Comments
 (0)