Skip to content

Commit 89895a7

Browse files
committed
Support packed-refs
1 parent 963473a commit 89895a7

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/git/url_prefix.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,22 @@ function getGithubURLPrefix(root) {
1616
var head = fs.readFileSync(path.join(root, '.git', 'HEAD'), 'utf8');
1717
var branch = head.match(/ref\: (.*)/);
1818
if (branch) {
19-
var sha = fs.readFileSync(path.join(root, '.git', branch[1]), 'utf8');
19+
var branchFileName = path.join(root, '.git', branch[1]);
20+
var packedRefsName = path.join(root, '.git', 'packed-refs');
21+
var sha;
22+
if (fs.existsSync(branchFileName)) {
23+
sha = fs.readFileSync(branchFileName, 'utf8');
24+
} else if (fs.existsSync(packedRefsName)) {
25+
sha = fs.readFileSync(packedRefsName, 'utf8')
26+
.split(/\n/)
27+
.filter(function (line) {
28+
return line[0] !== '#' && line[0] !== '^';
29+
})
30+
.reduce(function (memo, line) {
31+
memo[line.split(' ')[1]] = line.split(' ')[0];
32+
return memo;
33+
}, {})[branch[1]];
34+
}
2035
} else {
2136
sha = head;
2237
}

0 commit comments

Comments
 (0)