Fix and simplify s:git_get_remote_origin_url

This commit is contained in:
Junegunn Choi 2020-09-08 17:00:55 +09:00
parent 28ede474b9
commit eb257c13c5
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

View File

@ -143,36 +143,11 @@ endfunction
function! s:git_get_remote_origin_url(dir) abort function! s:git_get_remote_origin_url(dir) abort
let gitdir = s:get_gitdir(a:dir) let gitdir = s:get_gitdir(a:dir)
if gitdir ==# '' let config = gitdir . '/config'
if empty(gitdir) || !filereadable(config)
return '' return ''
endif endif
try return matchstr(join(readfile(config)), '\[remote "origin"\].\{-}url\s*=\s*\zs\S*\ze')
let lines = readfile(gitdir . '/config')
let [n, ll, url] = [0, len(lines), '']
while n < ll
let line = s:trim(lines[n])
if stridx(line, '[remote "origin"]') != 0
let n += 1
continue
endif
let n += 1
while n < ll
let line = s:trim(lines[n])
if line ==# '['
break
endif
let url = matchstr(line, '^url\s*=\s*\zs[^ #]\+')
if !empty(url)
break
endif
let n += 1
endwhile
let n += 1
endwhile
return url
catch
return ''
endtry
endfunction endfunction
function! s:git_get_revision(dir) abort function! s:git_get_revision(dir) abort