Skip to content

Commit a09590c

Browse files
authored
Merge pull request #31 from jrowlingson/master
Support packed annotated tags
2 parents fb7af27 + e8414af commit a09590c

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,19 @@ function getPackedRefsForType(gitPath, refPath, type) {
9090
}
9191

9292
function getLineForRefPath(packedRefsFile, type, refPath) {
93-
return packedRefsFile.split('\n').filter(function(line) {
94-
return doesLineMatchRefPath(type, line, refPath);
95-
})[0];
93+
return getLinesForRefPath(packedRefsFile, type, refPath)[0];
94+
}
95+
96+
function getLinesForRefPath(packedRefsFile, type, refPath) {
97+
return packedRefsFile.split('\n').reduce(function(acc, line, idx, arr) {
98+
var targetLine = line.indexOf('^') > -1 ? arr[idx-1] : line;
99+
return doesLineMatchRefPath(type, line, refPath) ? acc.concat(targetLine) : acc;
100+
}, []);
96101
}
97102

98103
function doesLineMatchRefPath(type, line, refPath) {
99104
var refPrefix = type === 'tag' ? 'refs/tags' : 'refs/heads';
100-
return line.indexOf(refPrefix) > -1 && line.indexOf(refPath) > -1;
105+
return (line.indexOf(refPrefix) > -1 || line.indexOf('^') > -1) && line.indexOf(refPath) > -1;
101106
}
102107

103108
function getShaBasedOnType(type, shaLine) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
5359aabd3872d9ffd160712e9615c5592dfe6745 refs/remotes/origin/master
2+
456d170a0177147cf2f242c91f776037150b3d4b refs/tags/example-annotated-tag
3+
^5359aabd3872d9ffd160712e9615c5592dfe6745
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5359aabd3872d9ffd160712e9615c5592dfe6745

tests/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ describe('git-repo-info', function() {
177177
assert.deepEqual(result, expected);
178178
});
179179

180+
it('returns an object with repo info, including the tag (packed annotated tag)', function() {
181+
var repoRoot = path.join(testFixturesPath, 'tagged-commit-packed-annotated');
182+
var result = repoInfo(path.join(repoRoot, gitDir));
183+
184+
var expected = {
185+
branch: 'master',
186+
sha: '5359aabd3872d9ffd160712e9615c5592dfe6745',
187+
abbreviatedSha: '5359aabd38',
188+
tag: 'example-annotated-tag',
189+
committer: null,
190+
committerDate: null,
191+
author: null,
192+
authorDate: null,
193+
commitMessage: null,
194+
root: repoRoot
195+
};
196+
197+
assert.deepEqual(result, expected);
198+
});
199+
180200
if (zlib.inflateSync) {
181201
it('returns an object with repo info, including the tag (unpacked tags)', function() {
182202
var repoRoot = path.join(testFixturesPath, 'tagged-commit-unpacked');

0 commit comments

Comments
 (0)