Skip to content

Commit fc7c7af

Browse files
committed
Add method to get all refs on the repo
1 parent 0d0ee08 commit fc7c7af

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

lib/utils/repo/getAllRefs.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var Q = require('q');
2+
var Immutable = require('immutable');
3+
4+
var listAllRefs = require('./listAllRefs');
5+
var Ref = require('../../models/ref');
6+
7+
/*
8+
Get all refs in a repository
9+
10+
@param {Repository} repo
11+
@return {OrderedMap<String:Ref>}
12+
*/
13+
function getAllRefs(repo) {
14+
return listAllRefs(repo)
15+
.then(function(refs) {
16+
var base = new Immutable.OrderedMap();
17+
18+
return refs.reduce(function(prev, refName) {
19+
return prev.then(function(out) {
20+
return Ref.readFromRepoByName(repo, refName)
21+
.then(function(ref) {
22+
return out.set(refName, ref);
23+
});
24+
});
25+
26+
}, Q(base));
27+
});
28+
}
29+
30+
module.exports = getAllRefs;

lib/utils/repo/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
module.exports = {
33
init: require('./init'),
44
isBare: require('./isBare'),
5-
prepare: require('./prepare')
5+
prepare: require('./prepare'),
6+
listAllRefs:require('./listAllRefs'),
7+
getAllRefs: require('./getAllRefs')
68
};

lib/utils/repo/listAllRefs.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var FileUtils = require('../file');
2+
3+
/*
4+
List all refs in a repository
5+
6+
@param {Repository} repo
7+
@return {List<String>}
8+
*/
9+
function listAllRefs(repo) {
10+
var fs = repo.getFS();
11+
var baseFolder = repo.getGitPath('refs');
12+
13+
return FileUtils.list(fs, baseFolder)
14+
.then(function(files) {
15+
return files.keySeq();
16+
});
17+
}
18+
19+
module.exports = listAllRefs;

lib/utils/transfer/clone.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
var Q = require('q');
2+
3+
var RepoUtils = require('../repo');
14
var fetchDiscovery = require('./fetchDiscovery');
25

36
/*
@@ -8,10 +11,16 @@ var fetchDiscovery = require('./fetchDiscovery');
811
@return {Promise}
912
*/
1013
function clone(repo, transport) {
11-
return fetchDiscovery(transport)
12-
.then(function(refs) {
13-
console.log(refs);
14-
});
14+
return Q.all([
15+
// Fetch the list of refs and capabilities of the server
16+
fetchDiscovery(transport),
17+
18+
// List refs we have
19+
RepoUtils.getAllRefs(repo)
20+
])
21+
.spread(function(discovery, refs) {
22+
console.log(refs);
23+
});
1524
}
1625

1726
module.exports = clone;

0 commit comments

Comments
 (0)