diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-01-26 09:12:00 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-01-26 09:12:00 +0100 |
commit | 75b217fc246be108368ed0e3c3adda3dc85fd615 (patch) | |
tree | b0482e14970e6bdb95c9bbffb3fedab326c713a1 | |
parent | d6b44cc149fd6889f77107bb365a68079811576f (diff) | |
download | gitbook-75b217fc246be108368ed0e3c3adda3dc85fd615.zip gitbook-75b217fc246be108368ed0e3c3adda3dc85fd615.tar.gz gitbook-75b217fc246be108368ed0e3c3adda3dc85fd615.tar.bz2 |
Support ssh urls in git parsing
-rw-r--r-- | lib/utils/git.js | 11 | ||||
-rw-r--r-- | test/git.js | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/utils/git.js b/lib/utils/git.js index c37f326..f7f63e7 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); + if (!url.parse(giturl).protocol) { + giturl = "ssh://"+giturl; + } + var normalized = ngu(giturl); - console.log(normalized); - var ref = parts.hash; + 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 2ac1eb9..b23c83e 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"); }); |