@@ -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 ( / ( \. g i t | \. b u n d l e ) ? / , '' ) ;
130+ }
131+
120132function 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 ( / \. g i t $ / , '' ) ;
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 ( / \. g i t $ / , '' ) ;
@@ -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