summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/utils/git.js11
-rw-r--r--test/git.js2
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");
});