Provide Git version comparison API
This commit is contained in:
parent
8bf74ceef3
commit
58a4a2e102
@ -183,7 +183,21 @@ function! fugitive#GitVersion(...) abort
|
|||||||
if !has_key(s:git_versions, g:fugitive_git_executable)
|
if !has_key(s:git_versions, g:fugitive_git_executable)
|
||||||
let s:git_versions[g:fugitive_git_executable] = matchstr(system(g:fugitive_git_executable.' --version'), "\\S\\+\\ze\n")
|
let s:git_versions[g:fugitive_git_executable] = matchstr(system(g:fugitive_git_executable.' --version'), "\\S\\+\\ze\n")
|
||||||
endif
|
endif
|
||||||
return s:git_versions[g:fugitive_git_executable]
|
if !a:0
|
||||||
|
return s:git_versions[g:fugitive_git_executable]
|
||||||
|
endif
|
||||||
|
let components = split(s:git_versions[g:fugitive_git_executable], '\D\+')
|
||||||
|
if empty(components)
|
||||||
|
return -1
|
||||||
|
endif
|
||||||
|
for i in range(len(a:000))
|
||||||
|
if a:000[i] > +get(components, i)
|
||||||
|
return 0
|
||||||
|
elseif a:000[i] < +get(components, i)
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return a:000[i] ==# get(components, i)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:commondirs = {}
|
let s:commondirs = {}
|
||||||
@ -213,7 +227,7 @@ function! s:Tree(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:PreparePathArgs(cmd, dir, literal) abort
|
function! s:PreparePathArgs(cmd, dir, literal) abort
|
||||||
let literal_supported = fugitive#GitVersion() !~# '^0\|^1\.[1-8]\.'
|
let literal_supported = fugitive#GitVersion(1, 9)
|
||||||
if a:literal && literal_supported
|
if a:literal && literal_supported
|
||||||
call insert(a:cmd, '--literal-pathspecs')
|
call insert(a:cmd, '--literal-pathspecs')
|
||||||
endif
|
endif
|
||||||
@ -265,17 +279,17 @@ function! fugitive#Prepare(...) abort
|
|||||||
let pre = (len(pre) ? pre : 'env ') . var . '=' . s:shellesc(val) . ' '
|
let pre = (len(pre) ? pre : 'env ') . var . '=' . s:shellesc(val) . ' '
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
if fugitive#GitVersion() =~# '^0\|^1\.[1-7]\.' || cmd[i+1] !~# '\.'
|
if fugitive#GitVersion(1, 8) && cmd[i+1] =~# '\.'
|
||||||
call remove(cmd, i, i + 1)
|
|
||||||
else
|
|
||||||
let i += 2
|
let i += 2
|
||||||
|
else
|
||||||
|
call remove(cmd, i, i + 1)
|
||||||
endif
|
endif
|
||||||
elseif cmd[i] =~# '^--.*pathspecs$'
|
elseif cmd[i] =~# '^--.*pathspecs$'
|
||||||
let explicit_pathspec_option = 1
|
let explicit_pathspec_option = 1
|
||||||
if fugitive#GitVersion() =~# '^0\|^1\.[1-8]\.'
|
if fugitive#GitVersion(1, 9)
|
||||||
call remove(cmd, i)
|
|
||||||
else
|
|
||||||
let i += 1
|
let i += 1
|
||||||
|
else
|
||||||
|
call remove(cmd, i)
|
||||||
endif
|
endif
|
||||||
elseif cmd[i] !~# '^-'
|
elseif cmd[i] !~# '^-'
|
||||||
break
|
break
|
||||||
@ -291,10 +305,10 @@ function! fugitive#Prepare(...) abort
|
|||||||
let args = join(map(copy(cmd), 's:shellesc(v:val)'))
|
let args = join(map(copy(cmd), 's:shellesc(v:val)'))
|
||||||
if empty(tree) || index(cmd, '--') == len(cmd) - 1
|
if empty(tree) || index(cmd, '--') == len(cmd) - 1
|
||||||
let args = s:shellesc('--git-dir=' . dir) . ' ' . args
|
let args = s:shellesc('--git-dir=' . dir) . ' ' . args
|
||||||
elseif fugitive#GitVersion() =~# '^0\|^1\.[1-8]\.'
|
elseif fugitive#GitVersion(1, 9)
|
||||||
let pre = 'cd ' . s:shellesc(tree) . (s:winshell() ? ' & ' : '; ') . pre
|
|
||||||
else
|
|
||||||
let args = '-C ' . s:shellesc(tree) . ' ' . args
|
let args = '-C ' . s:shellesc(tree) . ' ' . args
|
||||||
|
else
|
||||||
|
let pre = 'cd ' . s:shellesc(tree) . (s:winshell() ? ' & ' : '; ') . pre
|
||||||
endif
|
endif
|
||||||
return pre . g:fugitive_git_executable . ' ' . args
|
return pre . g:fugitive_git_executable . ' ' . args
|
||||||
endfunction
|
endfunction
|
||||||
@ -392,7 +406,7 @@ endfunction
|
|||||||
function! fugitive#RemoteUrl(...) abort
|
function! fugitive#RemoteUrl(...) abort
|
||||||
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
||||||
let remote = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
let remote = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
||||||
if fugitive#GitVersion() =~# '^[01]\.\|^2\.[0-6]\.'
|
if !fugitive#GitVersion(2, 7)
|
||||||
return fugitive#Config('remote.' . remote . '.url')
|
return fugitive#Config('remote.' . remote . '.url')
|
||||||
endif
|
endif
|
||||||
let cmd = s:Prepare(dir, 'remote', 'get-url', remote, '--')
|
let cmd = s:Prepare(dir, 'remote', 'get-url', remote, '--')
|
||||||
|
Loading…
Reference in New Issue
Block a user