Skip to content

Commit

Permalink
Adjust gitlab_domains doc and support more cases
Browse files Browse the repository at this point in the history
Issue #49 showed a mismatch between the docs the full SSH url.

We can both update the docs and catch more cases.

The issue with #49 was that we weren't allowing the user@ part of the
domain.
Whilst at the same time, the docs suggested having ssh:// in the
options when really we just need the domain with no schema, port or
user.

This adjusts both that use case and the README
  • Loading branch information
shumphrey committed Mar 18, 2024
1 parent 55fed48 commit e8dd4c9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ To use private GitLab instances, add the following to your .vimrc
If the private GitLab instance uses different URLs, for example, one for SSH
and another for HTTPS, instead add the following to your .vimrc

let g:fugitive_gitlab_domains = {'ssh://my-ssh.gitlab.com': 'https://my.gitlab.com'}
let g:fugitive_gitlab_domains = {'my-ssh.gitlab.com': 'https://my.gitlab.com'}

Fugitive command `:GBrowse` will now work with GitLab URLs.

Expand Down
2 changes: 2 additions & 0 deletions autoload/gitlab/fugitive.vim
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ function! gitlab#fugitive#homepage_for_remote(url) abort

if empty(match)
return ''
elseif has_key(domains, match[1] . 'git@' . match[2])
let key = match[1] . 'git@' . match[2]
elseif has_key(domains, match[1] . match[2])
let key = match[1] . match[2]
elseif has_key(domains, match[2])
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

docker build -f test/Dockerfile -t fugitive_gitlab .
docker build -f test/Dockerfile -t fugitive_gitlab --load .

docker run --rm -v `pwd`:/test/fugitive-gitlab.vim -w '/test' fugitive_gitlab vim -Es -Nu vimrc -c 'Vader! fugitive-gitlab.vim/test/*' > /dev/null
docker run --rm -v `pwd`:/test/fugitive-gitlab.vim -w '/test' fugitive_gitlab nvim -Es -Nu vimrc -c 'Vader! fugitive-gitlab.vim/test/*' > /dev/null
8 changes: 8 additions & 0 deletions test/homepage_for_remote.vader
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,11 @@ Execute (gitlab#fugitive#homepage_for_remote - simple dict config with insecure
let expected = 'http://my.gitlab.com/shumphrey/fugitive-gitlab.vim'
let url = gitlab#fugitive#homepage_for_remote('[email protected]:shumphrey/fugitive-gitlab.vim.git')
AssertEqual url, expected

Execute (gitlab#fugitive#homepage_for_remote - verbose ssh:// with user and port):
let g:fugitive_gitlab_domains = {
\ 'ssh://[email protected]:12345': 'https://my.gitlab.com:3456',
\ }
let expected = 'https://my.gitlab.com:3456/shumphrey/fugitive-gitlab.vim'
let url = gitlab#fugitive#homepage_for_remote('ssh://[email protected]:12345/shumphrey/fugitive-gitlab.vim.git')
AssertEqual url, expected

0 comments on commit e8dd4c9

Please sign in to comment.