Skip to content

Commit

Permalink
Merge pull request #2 from opengh/hotfix/custom-default-branch
Browse files Browse the repository at this point in the history
Fixes lookup if the default branch is not master
  • Loading branch information
martinheidegger committed Apr 2, 2016
2 parents 90fc88b + 3fe7231 commit 729b9c4
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions index.js
Expand Up @@ -23,24 +23,30 @@ function ls (path, callback) {
} else {
folder = ''
}
if (branch === 'master') {
branch = ''
prefix = 'trunk/' + folder
} else {
branch = branch + '/'
prefix = 'branches/' + branch + folder
}
ls.paths(GITHUB, slug, '', ls.errorCatch(callback, function (list) {
var rev
if (branch === '') {
rev = list[0].rev
} else {
rev = list[1].rev
var folderProcessor = ls.errorCatch(callback, function (list) {
callback(null, list.map(function (entry) {
return entry.path.substr(prefix.length)
}))
})
ls.paths(GITHUB, slug, 'branches', ls.errorCatch(callback, function (list) {
for (var i = 0; i < list.length; i++) {
var item = list[i]
prefix = 'branches/' + branch + '/' + folder
if (item.path === prefix) {
/*
This branch is actually a branch! lets use it!
*/
return ls.paths(GITHUB, slug, item.rev + folder, folderProcessor)
}
}
ls.paths(GITHUB, slug, rev + branch + folder, ls.errorCatch(callback, function (list) {
callback(null, list.map(function (entry) {
return entry.path.substr(prefix.length)
}))
/*
If the selected branch is not a dedicated branch it assumes that the branch is the trunk
and we need to fetch the version of the trunk to know which version of the tree we should
read
*/
ls.paths(GITHUB, slug, '', ls.errorCatch(callback, function (list) {
prefix = 'trunk/' + folder
ls.paths(GITHUB, slug, list[0].rev + folder, folderProcessor)
}))
}))
}
Expand Down

0 comments on commit 729b9c4

Please sign in to comment.