Commit 935fc68e authored by Steven Humphrey's avatar Steven Humphrey
Browse files

Tweak port stripping and add additional tests

- Ports can be 5 characters
- Changed test titles to be explicit about ssh long form vs short form
- Added tests for short form ssh non-standard user/port

Fixes #24
parent 25c826d8
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ function! gitlab#homepage_for_remote(remote) abort
    let base = matchstr(a:remote, '^\%(https\=://\|git://\|' . g:fugitive_gitlab_ssh_user . '@\|ssh://' . g:fugitive_gitlab_ssh_user . '@\)\%(.\{-\}@\)\=\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$')

    " Remove port
    let base = substitute(base, ':\d\{1,4}\/', '/', '')
    let base = substitute(base, ':\d\{1,5}\/', '/', '')

    let base = tr(base, ':', '/')
    let domain = substitute(base, '\v/.*', '', '')
+31 −4
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ Execute (Gbrowse - commit type):
    let url = g:fugitive_browse_handlers[0](opts)
    AssertEqual 'https://gitlab.com/shumphrey/fugitive-gitlab.vim/commit/a935a734765575b33da6c50fe8d0175e70e0e542', url

Execute (Gbrowse - private remote):
Execute (Gbrowse - private ssh remote):
    let opts = {
      \'remote': 'git@my.gitlab.com:shumphrey/fugitive-gitlab.vim.git',
      \'commit': 'master',
@@ -99,7 +99,7 @@ Execute (Gbrowse - https remote with @):

    AssertEqual 'https://gitlab.com/shumphrey/fugitive-gitlab.vim/blob/master/myfile.vim', url

Execute (Gbrowse - ssh remote):
Execute (Gbrowse - Long form ssh remote):
    let opts = {
      \'remote': 'ssh://git@gitlab.com:shumphrey/fugitive-gitlab.vim.git',
      \'commit': 'master',
@@ -110,7 +110,7 @@ Execute (Gbrowse - ssh remote):

    AssertEqual 'https://gitlab.com/shumphrey/fugitive-gitlab.vim/blob/master/myfile.vim', url

Execute (Gbrowse - ssh remote with non-standard ssh user):
Execute (Gbrowse - Long form ssh remote with non-standard ssh user):
    let opts = {
      \'remote': 'ssh://gitlab@gitlab.com:shumphrey/fugitive-gitlab.vim.git',
      \'commit': 'master',
@@ -126,7 +126,7 @@ Execute (Gbrowse - ssh remote with non-standard ssh user):

    AssertEqual 'https://gitlab.com/shumphrey/fugitive-gitlab.vim/blob/master/myfile.vim', url

Execute (Gbrowse - ssh remote with non-standard port):
Execute (Gbrowse - Long form ssh remote with non-standard port):
    let opts = {
      \'remote': 'ssh://git@gitlab.com:222/shumphrey/fugitive-gitlab.vim.git',
      \'commit': 'master',
@@ -137,4 +137,31 @@ Execute (Gbrowse - ssh remote with non-standard port):

    AssertEqual 'https://gitlab.com/shumphrey/fugitive-gitlab.vim/blob/master/myfile.vim', url

Execute (Gbrowse - Short form ssh remote with non-standard ssh user):
    let opts = {
      \'remote': 'gitlab@gitlab.com:shumphrey/fugitive-gitlab.vim.git',
      \'commit': 'master',
      \'type': 'blob',
      \'path': 'myfile.vim'
    \}

    let url = g:fugitive_browse_handlers[0](opts)
    AssertEqual '', url

    let g:fugitive_gitlab_ssh_user = 'gitlab'
    let url = g:fugitive_browse_handlers[0](opts)

    AssertEqual 'https://gitlab.com/shumphrey/fugitive-gitlab.vim/blob/master/myfile.vim', url

Execute (Gbrowse - Short form ssh remote with non-standard port):
    let opts = {
      \'remote': 'git@gitlab.com:12345/shumphrey/fugitive-gitlab.vim.git',
      \'commit': 'master',
      \'type': 'blob',
      \'path': 'myfile.vim'
    \}
    let url = g:fugitive_browse_handlers[0](opts)

    AssertEqual 'https://gitlab.com/shumphrey/fugitive-gitlab.vim/blob/master/myfile.vim', url

" vim: set ts=4 sw=4 et :