-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgitutil.js
30 lines (22 loc) · 831 Bytes
/
gitutil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var fs = require('fs'),
path = require('path');
var isGitDir = exports.isGitDir = function(fullPath) {
var gitDir = path.join(fullPath, '.git');
// check for a normal repository
if (fs.existsSync(gitDir))
return true;
// check for a bare repository
var bareRepoDirs = ['hooks', 'info', 'objects', 'refs'].map(function(f) {
return fs.existsSync(path.join(fullPath, f));
});
return bareRepoDirs.every(function(f) { return f; });
};
exports.listRepos = function(root, callback) {
fs.readdir(root, function(err, files) {
if (err) return callback(err);
var repos = files
.map(function(f) { return {name: f, path: path.join(root, f)}; })
.filter(function(info) { return isGitDir(info.path); });
callback(null, repos);
});
};