Skip to content

Commit 82a3352

Browse files
authored
Merge pull request #163 from yuvipanda/git-ssh
Parse ssh git URLs properly
2 parents 92e2b7f + a9c119a commit 82a3352

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

docs/_static/link_gen/link.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ function changeTab(div) {
117117
}
118118
}
119119

120+
/**
121+
* Return name of directory git will clone given repo to.
122+
*
123+
* nbgitpuller needs to redirect users to *inside* the directory it
124+
* just cloned. We copy the logic git itself uses to determine that.
125+
* See https://github.com/git/git/blob/1c52ecf4ba0f4f7af72775695fee653f50737c71/builtin/clone.c#L276
126+
*/
127+
function generateCloneDirectoryName(gitCloneUrl) {
128+
var lastPart = gitCloneUrl.split('/').slice(-1)[0];
129+
return lastPart.split(':').slice(-1)[0].replace(/(\.git|\.bundle)?/, '');
130+
}
131+
120132
function displayLink() {
121133
var form = document.getElementById('linkgenerator');
122134

@@ -134,8 +146,7 @@ function displayLink() {
134146
if (appName === 'custom') {
135147
var urlPath = document.getElementById('urlpath').value;
136148
} else {
137-
var repoName = new URL(repoUrl).pathname.split('/').pop().replace(/\.git$/, '');
138-
var userName = new URL(repoUrl).pathname.split('/')[1];
149+
var repoName = generateCloneDirectoryName(repoUrl);
139150
var urlPath;
140151
if (activeTab === "tab-auth-binder") {
141152
var contentRepoName = new URL(contentRepoUrl).pathname.split('/').pop().replace(/\.git$/, '');
@@ -154,6 +165,10 @@ function displayLink() {
154165
hubUrl, urlPath, repoUrl, branch
155166
);
156167
} else if (activeTab === "tab-auth-binder"){
168+
// FIXME: userName parsing using new URL(...) assumes a
169+
// HTTP based repoUrl. Does it make sense to create a
170+
// BinderHub link for SSH URLs? Then let's fix this parsing.
171+
var userName = new URL(repoUrl).pathname.split('/')[1];
157172
document.getElementById('binder-link').value = generateBinderUrl(
158173
hubUrl, userName, repoName, branch, urlPath, contentRepoUrl, contentRepoBranch
159174
);

0 commit comments

Comments
 (0)