Allow :Gbrowse on HTTP GitHub FI

Closes #272.
This commit is contained in:
Tim Pope 2012-11-18 22:43:04 -05:00
parent 003f38c6a4
commit f64ba46509
2 changed files with 9 additions and 4 deletions

View File

@ -203,7 +203,7 @@ that are part of Git repositories).
To use with GitHub FI, point g:fugitive_github_domains To use with GitHub FI, point g:fugitive_github_domains
at a list of domains: at a list of domains:
> >
let g:fugitive_github_domains = ['git.example.com'] let g:fugitive_github_domains = ['https://example.com']
~ ~
:[range]Gbrowse! Like :Gbrowse, but put the URL on the clipboard rather :[range]Gbrowse! Like :Gbrowse, but put the URL on the clipboard rather
than opening it. than opening it.

View File

@ -1870,14 +1870,19 @@ endfunction
function! s:github_url(repo,url,rev,commit,path,type,line1,line2) abort function! s:github_url(repo,url,rev,commit,path,type,line1,line2) abort
let path = a:path let path = a:path
let domain_pattern = 'github\.com' let domain_pattern = 'github\.com'
for domain in exists('g:fugitive_github_domains') ? g:fugitive_github_domains : [] let domains = exists('g:fugitive_github_domains') ? g:fugitive_github_domains : []
let domain_pattern .= '\|' . escape(domain, '.') for domain in domains
let domain_pattern .= '\|' . escape(split(domain, '://')[-1], '.')
endfor endfor
let repo = matchstr(a:url,'^\%(https\=://\|git://\|git@\)\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$') let repo = matchstr(a:url,'^\%(https\=://\|git://\|git@\)\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$')
if repo ==# '' if repo ==# ''
return '' return ''
endif endif
if index(g:fugitive_github_domains, 'http://' . matchstr(repo, '^[^:/]*')) >= 0
let root = 'http://' . s:sub(repo,':','/')
else
let root = 'https://' . s:sub(repo,':','/') let root = 'https://' . s:sub(repo,':','/')
endif
if path =~# '^\.git/refs/heads/' if path =~# '^\.git/refs/heads/'
let branch = a:repo.git_chomp('config','branch.'.path[16:-1].'.merge')[11:-1] let branch = a:repo.git_chomp('config','branch.'.path[16:-1].'.merge')[11:-1]
if branch ==# '' if branch ==# ''