" Location: autoload/fugitive.vim
" Maintainer: Tim Pope
if exists('g:autoloaded_fugitive')
finish
endif
let g:autoloaded_fugitive = 1
if !exists('g:fugitive_git_executable')
let g:fugitive_git_executable = 'git'
elseif g:fugitive_git_executable =~# '^\w\+='
let g:fugitive_git_executable = 'env ' . g:fugitive_git_executable
endif
" Section: Utility
function! s:function(name) abort
return function(substitute(a:name,'^s:',matchstr(expand(''), '.*\zs\d\+_'),''))
endfunction
function! s:sub(str,pat,rep) abort
return substitute(a:str,'\v\C'.a:pat,a:rep,'')
endfunction
function! s:gsub(str,pat,rep) abort
return substitute(a:str,'\v\C'.a:pat,a:rep,'g')
endfunction
function! s:Uniq(list) abort
let i = 0
let seen = {}
while i < len(a:list)
let str = string(a:list[i])
if has_key(seen, str)
call remove(a:list, i)
else
let seen[str] = 1
let i += 1
endif
endwhile
return a:list
endfunction
function! s:winshell() abort
return has('win32') && &shellcmdflag !~# '^-'
endfunction
function! s:shellesc(arg) abort
if type(a:arg) == type([])
return join(map(copy(a:arg), 's:shellesc(v:val)'))
elseif a:arg =~ '^[A-Za-z0-9_/:.-]\+$'
return a:arg
elseif s:winshell()
return '"'.s:gsub(s:gsub(a:arg, '"', '""'), '\%', '"%"').'"'
else
return shellescape(a:arg)
endif
endfunction
let s:fnameescape = " \t\n*?[{`$\\%#'\"|!<"
function! s:fnameescape(file) abort
if type(a:file) == type([])
return join(map(copy(a:file), 's:fnameescape(v:val)'))
elseif exists('*fnameescape')
return fnameescape(a:file)
else
return escape(a:file, s:fnameescape)
endif
endfunction
function! s:throw(string) abort
throw 'fugitive: '.a:string
endfunction
function! s:DirCheck(...) abort
if !empty(a:0 ? s:Dir(a:1) : s:Dir())
return ''
elseif empty(bufname(''))
return 'return ' . string('echoerr "fugitive: working directory does not belong to a Git repository"')
else
return 'return ' . string('echoerr "fugitive: file does not belong to a Git repository"')
endif
endfunction
function! s:Mods(mods, ...) abort
let mods = substitute(a:mods, '\C', '', '')
let mods = mods =~# '\S$' ? mods . ' ' : mods
if a:0 && mods !~# '\<\%(aboveleft\|belowright\|leftabove\|rightbelow\|topleft\|botright\|tab\)\>'
let mods = a:1 . ' ' . mods
endif
return substitute(mods, '\s\+', ' ', 'g')
endfunction
function! s:Slash(path) abort
if exists('+shellslash')
return tr(a:path, '\', '/')
else
return a:path
endif
endfunction
function! s:Resolve(path) abort
let path = resolve(a:path)
if has('win32')
let path = FugitiveVimPath(fnamemodify(fnamemodify(path, ':h'), ':p') . fnamemodify(path, ':t'))
endif
return path
endfunction
function! s:cpath(path, ...) abort
if exists('+fileignorecase') && &fileignorecase
let path = FugitiveVimPath(tolower(a:path))
else
let path = FugitiveVimPath(a:path)
endif
return a:0 ? path ==# s:cpath(a:1) : path
endfunction
function! s:Cd(...) abort
let cd = exists('*haslocaldir') && haslocaldir() ? 'lcd' : exists(':tcd') && haslocaldir(-1) ? 'tcd' : 'cd'
if !a:0
return cd
endif
let cwd = getcwd()
if s:cpath(cwd, a:1)
return ''
endif
exe cd s:fnameescape(a:1)
return cd . ' ' . s:fnameescape(cwd)
endfunction
let s:executables = {}
function! s:executable(binary) abort
if !has_key(s:executables, a:binary)
let s:executables[a:binary] = executable(a:binary)
endif
return s:executables[a:binary]
endfunction
if !exists('s:temp_scripts')
let s:temp_scripts = {}
endif
function! s:TempScript(...) abort
let body = join(a:000, "\n")
if !has_key(s:temp_scripts, body)
let temp = tempname() . '.sh'
call writefile(['#!/bin/sh'] + a:000, temp)
let s:temp_scripts[body] = temp
endif
return FugitiveGitPath(s:temp_scripts[body])
endfunction
function! s:DoAutocmd(cmd) abort
if v:version >= 704 || (v:version == 703 && has('patch442'))
return 'doautocmd ' . a:cmd
elseif &modelines > 0
return 'try|set modelines=0|doautocmd ' . a:cmd . '|finally|set modelines=' . &modelines . '|endtry'
else
return 'doautocmd ' . a:cmd
endif
endfunction
let s:nowait = v:version >= 704 ? '' : ''
function! s:Map(mode, lhs, rhs, ...) abort
for mode in split(a:mode, '\zs')
let flags = (a:0 ? a:1 : '') . (a:rhs =~# '' ? '' : '