Support ssh urls in git parsing

This commit is contained in:
Samy Pessé
2015-01-26 09:12:00 +01:00
parent d6b44cc149
commit 75b217fc24
2 changed files with 10 additions and 5 deletions
+9 -4
View File
@@ -25,14 +25,19 @@ function validateSha(str) {
// Parse and extract infos
function parseGitUrl(giturl) {
var ref, parts;
if (!checkGitUrl(giturl)) return null;
giturl = giturl.slice(GIT_PREFIX.length);
var parts = url.parse(giturl);
var normalized = ngu(giturl);
console.log(normalized);
if (!url.parse(giturl).protocol) {
giturl = "ssh://"+giturl;
}
var ref = parts.hash;
var normalized = ngu(giturl);
parts = url.parse(normalized.url);
ref = normalized.branch;
// Extract file inside the repo (after the .git)
var fileParts = parts.pathname.split(".git");
+1 -1
View File
@@ -25,7 +25,7 @@ describe('GIT parser and getter', function () {
it('should correctly parse an ssh url', function() {
var parts = git.parseUrl("git+git@github.com:GitbookIO/gitbook.git/directory/README.md#e1594cde2c32e4ff48f6c4eff3d3d461743d74e1");
assert(parts);
assert.equal(parts.host, "git@github.com");
assert.equal(parts.host, "ssh://git@github.com/GitbookIO/gitbook.git");
assert.equal(parts.ref, "e1594cde2c32e4ff48f6c4eff3d3d461743d74e1");
assert.equal(parts.filepath, "directory/README.md");
});