mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-20 17:43:24 +00:00
Support ssh urls in git parsing
This commit is contained in:
+9
-4
@@ -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
@@ -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");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user