From 75b217fc246be108368ed0e3c3adda3dc85fd615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Mon, 26 Jan 2015 09:12:00 +0100 Subject: [PATCH] Support ssh urls in git parsing --- lib/utils/git.js | 13 +++++++++---- test/git.js | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/utils/git.js b/lib/utils/git.js index c37f326e0..f7f63e7d6 100644 --- a/lib/utils/git.js +++ b/lib/utils/git.js @@ -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"); diff --git a/test/git.js b/test/git.js index 2ac1eb9dc..b23c83ea4 100644 --- a/test/git.js +++ b/test/git.js @@ -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"); });