Support GitHub FI

This commit is contained in:
Tim Pope 2012-03-14 16:27:46 -04:00
parent 4f7af188fe
commit 41ea90cddf
2 changed files with 12 additions and 3 deletions

View File

@ -186,6 +186,11 @@ that are part of Git repositories).
"git instaweb" from a terminal). If a range is given, "git instaweb" from a terminal). If a range is given,
it is appropriately appended to the URL as an anchor. it is appropriately appended to the URL as an anchor.
To use with GitHub FI, point g:fugitive_github_domains
at a list of domains:
>
let g:fugitive_github_domains = ['git.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

@ -1758,11 +1758,15 @@ 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 repo_path = matchstr(a:url,'^\%(https\=://\|git://\|git@\)github\.com[/:]\zs.\{-\}\ze\%(\.git\)\=$') let domain_pattern = 'github\.com'
if repo_path ==# '' for domain in exists('g:fugitive_github_domains') ? g:fugitive_github_domains : []
let domain_pattern .= '\|' . escape(domain, '.')
endfor
let repo = matchstr(a:url,'^\%(https\=://\|git://\|git@\)\zs\('.domain_pattern.'\)[/:].\{-\}\ze\%(\.git\)\=$')
if repo ==# ''
return '' return ''
endif endif
let root = 'https://github.com/' . repo_path let root = 'https://' . s:sub(repo,':','/')
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 ==# ''