2018-06-01 13:46:22 -04:00
|
|
|
" Location: autoload/fugitive.vim
|
|
|
|
" Maintainer: Tim Pope <http://tpo.pe/>
|
|
|
|
|
|
|
|
if exists('g:autoloaded_fugitive')
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:autoloaded_fugitive = 1
|
|
|
|
|
|
|
|
if !exists('g:fugitive_git_executable')
|
|
|
|
let g:fugitive_git_executable = 'git'
|
|
|
|
endif
|
|
|
|
|
|
|
|
" Section: Utility
|
|
|
|
|
|
|
|
function! s:function(name) abort
|
|
|
|
return function(substitute(a:name,'^s:',matchstr(expand('<sfile>'), '<SNR>\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
|
|
|
|
|
2018-07-28 21:08:56 -04:00
|
|
|
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
|
|
|
|
|
2018-06-01 13:46:22 -04:00
|
|
|
function! s:winshell() abort
|
2018-08-19 00:11:33 -04:00
|
|
|
return has('win32') && &shellcmdflag !~# '^-'
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:shellesc(arg) abort
|
|
|
|
if 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
|
|
|
|
|
2018-08-28 00:35:06 -04:00
|
|
|
let s:fnameescape = " \t\n*?[{`$\\%#'\"|!<"
|
2018-06-01 13:46:22 -04:00
|
|
|
function! s:fnameescape(file) abort
|
|
|
|
if exists('*fnameescape')
|
|
|
|
return fnameescape(a:file)
|
|
|
|
else
|
2018-08-28 00:35:06 -04:00
|
|
|
return escape(a:file, s:fnameescape)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:throw(string) abort
|
|
|
|
let v:errmsg = 'fugitive: '.a:string
|
|
|
|
throw v:errmsg
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:warn(str) abort
|
|
|
|
echohl WarningMsg
|
|
|
|
echomsg a:str
|
|
|
|
echohl None
|
|
|
|
let v:warningmsg = a:str
|
|
|
|
endfunction
|
|
|
|
|
2018-07-30 01:35:11 -04:00
|
|
|
function! s:Slash(path) abort
|
2018-08-19 05:12:04 -04:00
|
|
|
if exists('+shellslash')
|
2018-06-01 13:46:22 -04:00
|
|
|
return tr(a:path, '\', '/')
|
|
|
|
else
|
|
|
|
return a:path
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-06-05 12:28:16 -04:00
|
|
|
function! s:PlatformSlash(path) abort
|
|
|
|
if exists('+shellslash') && !&shellslash
|
|
|
|
return tr(a:path, '/', '\')
|
|
|
|
else
|
|
|
|
return a:path
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-08-18 23:12:09 -04:00
|
|
|
function! s:Resolve(path) abort
|
|
|
|
let path = resolve(a:path)
|
|
|
|
if has('win32')
|
|
|
|
let path = s:PlatformSlash(fnamemodify(fnamemodify(path, ':h'), ':p') . fnamemodify(path, ':t'))
|
|
|
|
endif
|
|
|
|
return path
|
|
|
|
endfunction
|
|
|
|
|
2018-07-28 21:08:56 -04:00
|
|
|
function! s:cpath(path, ...) abort
|
|
|
|
if exists('+fileignorecase') && &fileignorecase
|
|
|
|
let path = s:PlatformSlash(tolower(a:path))
|
|
|
|
else
|
|
|
|
let path = s:PlatformSlash(a:path)
|
|
|
|
endif
|
|
|
|
return a:0 ? path ==# s:cpath(a:1) : path
|
|
|
|
endfunction
|
|
|
|
|
2018-12-16 22:13:12 -05:00
|
|
|
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
|
|
|
|
|
2018-06-01 13:46:22 -04:00
|
|
|
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
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
function! s:map(mode, lhs, rhs, ...) abort
|
|
|
|
let flags = (a:0 ? a:1 : '') . (a:rhs =~# '<Plug>' ? '' : '<script>')
|
|
|
|
let head = a:lhs
|
|
|
|
let tail = ''
|
|
|
|
let keys = get(g:, a:mode.'remap', {})
|
|
|
|
if type(keys) == type([])
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
while !empty(head)
|
|
|
|
if has_key(keys, head)
|
|
|
|
let head = keys[head]
|
|
|
|
if empty(head)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
let tail = matchstr(head, '<[^<>]*>$\|.$') . tail
|
|
|
|
let head = substitute(head, '<[^<>]*>$\|.$', '', '')
|
|
|
|
endwhile
|
|
|
|
if flags !~# '<unique>' || empty(mapcheck(head.tail, a:mode))
|
|
|
|
exe a:mode.'map <buffer>' flags head.tail a:rhs
|
|
|
|
if a:0 > 1
|
|
|
|
let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') .
|
|
|
|
\ '|sil! exe "' . a:mode . 'unmap <buffer> ' . head.tail . '"'
|
|
|
|
endif
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-07-19 00:17:12 -04:00
|
|
|
function! s:System(cmd) abort
|
|
|
|
try
|
|
|
|
return system(a:cmd)
|
|
|
|
catch /^Vim\%((\a\+)\)\=:E484:/
|
|
|
|
let opts = ['shell', 'shellcmdflag', 'shellredir', 'shellquote', 'shellxquote', 'shellxescape', 'shellslash']
|
|
|
|
call filter(opts, 'exists("+".v:val) && !empty(eval("&".v:val))')
|
|
|
|
call map(opts, 'v:val."=".eval("&".v:val)')
|
|
|
|
call s:throw('failed to run `' . a:cmd . '` with ' . join(opts, ' '))
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: Git
|
|
|
|
|
|
|
|
function! s:UserCommand() abort
|
|
|
|
return get(g:, 'fugitive_git_command', g:fugitive_git_executable)
|
|
|
|
endfunction
|
|
|
|
|
2018-08-31 15:36:44 -04:00
|
|
|
function! s:Prepare(...) abort
|
|
|
|
return call('fugitive#Prepare', a:000)
|
2018-07-16 21:32:41 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
let s:git_versions = {}
|
2018-06-01 13:47:48 -04:00
|
|
|
function! fugitive#GitVersion(...) abort
|
2018-06-01 13:46:22 -04:00
|
|
|
if !has_key(s:git_versions, g:fugitive_git_executable)
|
2018-06-27 20:31:35 -04:00
|
|
|
let s:git_versions[g:fugitive_git_executable] = matchstr(system(g:fugitive_git_executable.' --version'), "\\S\\+\\ze\n")
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
return s:git_versions[g:fugitive_git_executable]
|
|
|
|
endfunction
|
|
|
|
|
2018-07-28 21:08:56 -04:00
|
|
|
let s:commondirs = {}
|
|
|
|
function! fugitive#CommonDir(dir) abort
|
|
|
|
if empty(a:dir)
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
if !has_key(s:commondirs, a:dir)
|
|
|
|
if getfsize(a:dir . '/HEAD') < 10
|
|
|
|
let s:commondirs[a:dir] = ''
|
|
|
|
elseif filereadable(a:dir . '/commondir')
|
|
|
|
let dir = get(readfile(a:dir . '/commondir', 1), 0, '')
|
|
|
|
if dir =~# '^/\|^\a:/'
|
|
|
|
let s:commondirs[a:dir] = dir
|
|
|
|
else
|
|
|
|
let s:commondirs[a:dir] = simplify(a:dir . '/' . dir)
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
let s:commondirs[a:dir] = a:dir
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
return s:commondirs[a:dir]
|
|
|
|
endfunction
|
|
|
|
|
2018-07-27 00:56:21 -04:00
|
|
|
function! s:Tree(...) abort
|
|
|
|
return FugitiveTreeForGitDir(a:0 ? a:1 : get(b:, 'git_dir', ''))
|
|
|
|
endfunction
|
|
|
|
|
2018-08-30 16:25:06 -04:00
|
|
|
function! s:PreparePathArgs(cmd, dir, literal) abort
|
|
|
|
let literal_supported = fugitive#GitVersion() !~# '^0\|^1\.[1-8]\.'
|
|
|
|
if a:literal && literal_supported
|
2018-08-13 00:08:59 -04:00
|
|
|
call insert(a:cmd, '--literal-pathspecs')
|
|
|
|
endif
|
|
|
|
let split = index(a:cmd, '--')
|
2018-08-30 16:25:06 -04:00
|
|
|
if split < 0
|
2018-08-13 00:08:59 -04:00
|
|
|
return a:cmd
|
|
|
|
endif
|
|
|
|
for i in range(split + 1, len(a:cmd) - 1)
|
2018-08-30 16:25:06 -04:00
|
|
|
if type(a:cmd[i]) == type(0)
|
|
|
|
let a:cmd[i] = fugitive#Path(bufname(a:cmd[i]), './', a:dir)
|
|
|
|
elseif a:literal
|
|
|
|
let a:cmd[i] = fugitive#Path(a:cmd[i], './', a:dir)
|
|
|
|
elseif !literal_supported
|
|
|
|
let a:cmd[i] = substitute(a:cmd[i], '^:\%(/\|([^)]*)\)\=:\=', './', '')
|
|
|
|
endif
|
2018-08-13 00:08:59 -04:00
|
|
|
endfor
|
|
|
|
return a:cmd
|
|
|
|
endfunction
|
|
|
|
|
2018-08-30 16:25:06 -04:00
|
|
|
let s:prepare_env = {
|
|
|
|
\ 'sequence.editor': 'GIT_SEQUENCE_EDITOR',
|
|
|
|
\ 'core.editor': 'GIT_EDITOR',
|
|
|
|
\ 'core.askpass': 'GIT_ASKPASS',
|
|
|
|
\ }
|
|
|
|
function! fugitive#Prepare(...) abort
|
|
|
|
if !a:0
|
|
|
|
return g:fugitive_git_executable
|
|
|
|
endif
|
|
|
|
if type(a:1) ==# type([])
|
|
|
|
let cmd = a:000[1:-1] + a:1
|
|
|
|
else
|
|
|
|
let cmd = copy(a:000)
|
|
|
|
endif
|
2018-07-28 20:05:06 -04:00
|
|
|
let pre = ''
|
2018-08-30 16:25:06 -04:00
|
|
|
let i = 0
|
|
|
|
while i < len(cmd)
|
|
|
|
if cmd[i] =~# '^$\|[\/.]' && cmd[i] !~# '^-'
|
|
|
|
let dir = remove(cmd, 0)
|
|
|
|
elseif type(cmd[i]) ==# type(0)
|
|
|
|
let dir = getbufvar(remove(cmd, i), 'git_dir')
|
|
|
|
elseif cmd[i] ==# '-c' && len(cmd) > i + 1
|
|
|
|
let key = matchstr(cmd[i+1], '^[^=]*')
|
|
|
|
if has_key(s:prepare_env, tolower(key)) || key !~# '\.'
|
|
|
|
let var = get(s:prepare_env, tolower(key), key)
|
|
|
|
let val = matchstr(cmd[i+1], '=\zs.*')
|
|
|
|
if s:winshell()
|
|
|
|
let pre .= 'set ' . var . '=' . s:shellesc(val) . ' & '
|
|
|
|
else
|
|
|
|
let pre = (len(pre) ? pre : 'env ') . var . '=' . s:shellesc(val) . ' '
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if fugitive#GitVersion() =~# '^0\|^1\.[1-7]\.' || cmd[i+1] !~# '\.'
|
|
|
|
call remove(cmd, i, i + 1)
|
|
|
|
else
|
|
|
|
let i += 2
|
|
|
|
endif
|
|
|
|
elseif cmd[i] =~# '^--.*pathspecs$'
|
|
|
|
let explicit_pathspec_option = 1
|
|
|
|
if fugitive#GitVersion() =~# '^0\|^1\.[1-8]\.'
|
|
|
|
call remove(cmd, i)
|
|
|
|
else
|
|
|
|
let i += 1
|
|
|
|
endif
|
|
|
|
elseif cmd[i] !~# '^-'
|
|
|
|
break
|
|
|
|
else
|
|
|
|
let i += 1
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
if !exists('dir')
|
|
|
|
let dir = get(b:, 'git_dir', '')
|
|
|
|
endif
|
|
|
|
let tree = s:Tree(dir)
|
|
|
|
call s:PreparePathArgs(cmd, dir, !exists('explicit_pathspec_option'))
|
|
|
|
let args = join(map(copy(cmd), 's:shellesc(v:val)'))
|
|
|
|
if empty(tree) || index(cmd, '--') == len(cmd) - 1
|
2018-07-28 20:05:06 -04:00
|
|
|
let args = s:shellesc('--git-dir=' . dir) . ' ' . args
|
2018-08-30 16:25:06 -04:00
|
|
|
elseif fugitive#GitVersion() =~# '^0\|^1\.[1-8]\.'
|
|
|
|
let pre = 'cd ' . s:shellesc(tree) . (s:winshell() ? ' & ' : '; ') . pre
|
2018-07-28 20:05:06 -04:00
|
|
|
else
|
|
|
|
let args = '-C ' . s:shellesc(tree) . ' ' . args
|
|
|
|
endif
|
|
|
|
return pre . g:fugitive_git_executable . ' ' . args
|
|
|
|
endfunction
|
|
|
|
|
2018-08-31 15:36:44 -04:00
|
|
|
function! s:TreeChomp(...) abort
|
|
|
|
return s:sub(s:System(call('fugitive#Prepare', a:000)), '\n$', '')
|
|
|
|
endfunction
|
|
|
|
|
2018-08-06 01:36:37 -04:00
|
|
|
function! fugitive#Head(...) abort
|
|
|
|
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
|
|
|
if empty(dir) || !filereadable(dir . '/HEAD')
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
let head = readfile(dir . '/HEAD')[0]
|
|
|
|
if head =~# '^ref: '
|
|
|
|
return substitute(head, '\C^ref: \%(refs/\%(heads/\|remotes/\|tags/\)\=\)\=', '', '')
|
|
|
|
elseif head =~# '^\x\{40\}$'
|
|
|
|
let len = a:0 ? a:1 : 0
|
|
|
|
return len < 0 ? head : len ? head[0:len-1] : ''
|
|
|
|
else
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-07-28 20:24:15 -04:00
|
|
|
function! fugitive#RevParse(rev, ...) abort
|
2018-08-19 20:52:29 -04:00
|
|
|
let hash = system(s:Prepare(a:0 ? a:1 : b:git_dir, 'rev-parse', '--verify', a:rev, '--'))[0:-2]
|
2018-07-28 20:24:15 -04:00
|
|
|
if !v:shell_error && hash =~# '^\x\{40\}$'
|
|
|
|
return hash
|
|
|
|
endif
|
|
|
|
call s:throw('rev-parse '.a:rev.': '.hash)
|
|
|
|
endfunction
|
|
|
|
|
2018-12-19 14:15:55 -05:00
|
|
|
function! s:ConfigTimestamps(dir, dict) abort
|
|
|
|
let files = ['/etc/gitconfig', '~/.gitconfig',
|
|
|
|
\ len($XDG_CONFIG_HOME) ? $XDG_CONFIG_HOME . '/git/config' : '~/.config/git/config']
|
|
|
|
if len(a:dir)
|
|
|
|
call add(files, fugitive#Find('.git/config', a:dir))
|
|
|
|
endif
|
|
|
|
call extend(files, get(a:dict, 'include.path', []))
|
|
|
|
return join(map(files, 'getftime(expand(v:val))'), ',')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let s:config = {}
|
|
|
|
function! fugitive#Config(...) abort
|
|
|
|
let dir = get(b:, 'git_dir', '')
|
|
|
|
let name = ''
|
2018-12-21 13:23:30 -05:00
|
|
|
if a:0 >= 2 && type(a:2) == type({})
|
2018-12-24 17:25:21 -05:00
|
|
|
let name = substitute(a:1, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
|
|
|
return len(a:1) ? get(get(a:2, name, []), 0, '') : a:2
|
2018-12-21 13:23:30 -05:00
|
|
|
elseif a:0 >= 2
|
|
|
|
let dir = a:2
|
|
|
|
let name = a:1
|
|
|
|
elseif a:0 == 1 && type(a:1) == type({})
|
|
|
|
return a:1
|
|
|
|
elseif a:0 == 1 && a:1 =~# '^[[:alnum:]-]\+\.'
|
|
|
|
let name = a:1
|
|
|
|
elseif a:0 == 1
|
|
|
|
let dir = a:1
|
2018-12-19 14:15:55 -05:00
|
|
|
endif
|
2018-12-22 14:34:37 -05:00
|
|
|
let name = substitute(name, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
2018-12-19 14:15:55 -05:00
|
|
|
let key = len(dir) ? dir : '_'
|
|
|
|
if has_key(s:config, key) && s:config[key][0] ==# s:ConfigTimestamps(dir, s:config[key][1])
|
|
|
|
let dict = s:config[key][1]
|
|
|
|
else
|
|
|
|
let dict = {}
|
|
|
|
let lines = split(system(FugitivePrepare(['config', '--list', '-z'], dir)), "\1")
|
|
|
|
if v:shell_error
|
|
|
|
return {}
|
|
|
|
endif
|
|
|
|
for line in lines
|
|
|
|
let key = matchstr(line, "^[^\n]*")
|
|
|
|
if !has_key(dict, key)
|
|
|
|
let dict[key] = []
|
|
|
|
endif
|
|
|
|
call add(dict[key], strpart(line, len(key) + 1))
|
|
|
|
endfor
|
|
|
|
let s:config[dir] = [s:ConfigTimestamps(dir, dict), dict]
|
|
|
|
lockvar! dict
|
|
|
|
endif
|
|
|
|
return len(name) ? get(get(dict, name, []), 0, '') : dict
|
2018-07-21 16:33:34 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-07-21 19:02:31 -04:00
|
|
|
function! s:Remote(dir) abort
|
|
|
|
let head = FugitiveHead(0, a:dir)
|
|
|
|
let remote = len(head) ? fugitive#Config('branch.' . head . '.remote') : ''
|
|
|
|
let i = 10
|
|
|
|
while remote ==# '.' && i > 0
|
|
|
|
let head = matchstr(fugitive#Config('branch.' . head . '.merge'), 'refs/heads/\zs.*')
|
|
|
|
let remote = len(head) ? fugitive#Config('branch.' . head . '.remote') : ''
|
|
|
|
let i -= 1
|
|
|
|
endwhile
|
2018-08-06 01:45:10 -04:00
|
|
|
return remote =~# '^\.\=$' ? 'origin' : remote
|
2018-07-21 19:02:31 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-07-21 16:33:34 -04:00
|
|
|
function! fugitive#RemoteUrl(...) abort
|
|
|
|
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
2018-07-21 19:02:31 -04:00
|
|
|
let remote = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
2018-07-21 16:33:34 -04:00
|
|
|
if fugitive#GitVersion() =~# '^[01]\.\|^2\.[0-6]\.'
|
|
|
|
return fugitive#Config('remote.' . remote . '.url')
|
|
|
|
endif
|
2018-08-19 20:52:29 -04:00
|
|
|
let cmd = s:Prepare(dir, 'remote', 'get-url', remote, '--')
|
2018-07-21 16:33:34 -04:00
|
|
|
let out = substitute(system(cmd), "\n$", '', '')
|
|
|
|
return v:shell_error ? '' : out
|
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: Repository Object
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
function! s:add_methods(namespace, method_names) abort
|
|
|
|
for name in a:method_names
|
|
|
|
let s:{a:namespace}_prototype[name] = s:function('s:'.a:namespace.'_'.name)
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let s:commands = []
|
|
|
|
function! s:command(definition) abort
|
|
|
|
let s:commands += [a:definition]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:define_commands() abort
|
|
|
|
for command in s:commands
|
|
|
|
exe 'command! -buffer '.command
|
|
|
|
endfor
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let s:repo_prototype = {}
|
|
|
|
let s:repos = {}
|
|
|
|
|
2018-07-28 20:26:31 -04:00
|
|
|
function! fugitive#repo(...) abort
|
2018-06-01 13:46:22 -04:00
|
|
|
let dir = a:0 ? a:1 : (exists('b:git_dir') && b:git_dir !=# '' ? b:git_dir : FugitiveExtractGitDir(expand('%:p')))
|
|
|
|
if dir !=# ''
|
|
|
|
if has_key(s:repos, dir)
|
|
|
|
let repo = get(s:repos, dir)
|
|
|
|
else
|
|
|
|
let repo = {'git_dir': dir}
|
|
|
|
let s:repos[dir] = repo
|
|
|
|
endif
|
2018-08-06 02:01:32 -04:00
|
|
|
return extend(repo, s:repo_prototype, 'keep')
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-10-27 18:22:04 -04:00
|
|
|
call s:throw('not a Git repository: ' . string(dir))
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:repo_dir(...) dict abort
|
|
|
|
return join([self.git_dir]+a:000,'/')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:repo_tree(...) dict abort
|
2018-07-27 00:56:21 -04:00
|
|
|
let dir = s:Tree(self.git_dir)
|
2018-06-01 13:46:22 -04:00
|
|
|
if dir ==# ''
|
|
|
|
call s:throw('no work tree')
|
|
|
|
else
|
|
|
|
return join([dir]+a:000,'/')
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:repo_bare() dict abort
|
|
|
|
if self.dir() =~# '/\.git$'
|
|
|
|
return 0
|
|
|
|
else
|
2018-07-27 00:56:21 -04:00
|
|
|
return s:Tree(self.git_dir) ==# ''
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-10-21 19:44:20 -04:00
|
|
|
function! s:repo_find(object) dict abort
|
|
|
|
return fugitive#Find(a:object, self.git_dir)
|
2018-07-22 01:29:49 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-02 20:53:15 -04:00
|
|
|
function! s:repo_translate(rev) dict abort
|
2018-10-21 19:44:20 -04:00
|
|
|
return s:Slash(fugitive#Find(substitute(a:rev, '^/', ':(top)', ''), self.git_dir))
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:repo_head(...) dict abort
|
2018-08-06 01:36:37 -04:00
|
|
|
return fugitive#Head(a:0 ? a:1 : 0, self.git_dir)
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-10-21 19:44:20 -04:00
|
|
|
call s:add_methods('repo',['dir','tree','bare','find','translate','head'])
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-08-30 16:25:06 -04:00
|
|
|
function! s:repo_prepare(...) dict abort
|
|
|
|
return call('fugitive#Prepare', [self.git_dir] + a:000)
|
|
|
|
endfunction
|
|
|
|
|
2018-06-01 13:46:22 -04:00
|
|
|
function! s:repo_git_command(...) dict abort
|
2018-07-27 00:19:44 -04:00
|
|
|
let git = s:UserCommand() . ' --git-dir='.s:shellesc(self.git_dir)
|
2018-06-01 13:46:22 -04:00
|
|
|
return git.join(map(copy(a:000),'" ".s:shellesc(v:val)'),'')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:repo_git_chomp(...) dict abort
|
2018-08-31 15:36:44 -04:00
|
|
|
let git = g:fugitive_git_executable . ' --git-dir='.s:shellesc(self.git_dir)
|
|
|
|
let output = git . join(map(copy(a:000),'" ".s:shellesc(v:val)'),'')
|
|
|
|
return s:sub(s:System(output),'\n$','')
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:repo_git_chomp_in_tree(...) dict abort
|
2018-12-16 22:13:12 -05:00
|
|
|
let cdback = s:Cd(self.tree())
|
2018-06-01 13:46:22 -04:00
|
|
|
try
|
2018-07-22 13:56:21 -04:00
|
|
|
return call(self.git_chomp, a:000, self)
|
2018-06-01 13:46:22 -04:00
|
|
|
finally
|
2018-12-16 22:13:12 -05:00
|
|
|
execute cdback
|
2018-06-01 13:46:22 -04:00
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:repo_rev_parse(rev) dict abort
|
2018-07-28 20:24:15 -04:00
|
|
|
return fugitive#RevParse(a:rev, self.git_dir)
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-30 16:25:06 -04:00
|
|
|
call s:add_methods('repo',['prepare','git_command','git_chomp','git_chomp_in_tree','rev_parse'])
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
function! s:repo_superglob(base) dict abort
|
2018-07-28 19:09:05 -04:00
|
|
|
return map(fugitive#Complete(a:base, self.git_dir), 'substitute(v:val, ''\\\(.\)'', ''\1'', "g")')
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-07-21 21:51:44 -04:00
|
|
|
call s:add_methods('repo',['superglob'])
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-07-21 16:33:34 -04:00
|
|
|
function! s:repo_config(name) dict abort
|
|
|
|
return fugitive#Config(a:name, self.git_dir)
|
|
|
|
endfunction
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
function! s:repo_user() dict abort
|
2018-07-21 16:33:34 -04:00
|
|
|
let username = self.config('user.name')
|
|
|
|
let useremail = self.config('user.email')
|
2018-06-01 13:46:22 -04:00
|
|
|
return username.' <'.useremail.'>'
|
2018-07-21 16:33:34 -04:00
|
|
|
endfunction
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-07-27 01:30:41 -04:00
|
|
|
call s:add_methods('repo',['config', 'user'])
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: File API
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-06-20 18:01:27 -04:00
|
|
|
function! s:DirCommitFile(path) abort
|
2018-07-30 01:35:11 -04:00
|
|
|
let vals = matchlist(s:Slash(a:path), '\c^fugitive:\%(//\)\=\(.\{-\}\)\%(//\|::\)\(\x\{40\}\|[0-3]\)\(/.*\)\=$')
|
2018-06-05 12:28:16 -04:00
|
|
|
if empty(vals)
|
|
|
|
return ['', '', '']
|
|
|
|
endif
|
2018-07-16 21:36:50 -04:00
|
|
|
return vals[1:3]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:DirRev(url) abort
|
|
|
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
|
|
|
return [dir, (commit =~# '^.$' ? ':' : '') . commit . substitute(file, '^/', ':', '')]
|
2018-06-05 12:28:16 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-07 15:33:19 -04:00
|
|
|
function! s:Owner(path, ...) abort
|
|
|
|
let dir = a:0 ? a:1 : get(b:, 'git_dir', '')
|
|
|
|
if empty(dir)
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
let [pdir, commit, file] = s:DirCommitFile(a:path)
|
2018-10-12 15:14:49 -04:00
|
|
|
if s:cpath(dir, pdir)
|
|
|
|
if commit =~# '^\x\{40\}$'
|
|
|
|
return commit
|
|
|
|
elseif commit ==# '2'
|
|
|
|
return 'HEAD^{}'
|
|
|
|
endif
|
|
|
|
if filereadable(dir . '/MERGE_HEAD')
|
|
|
|
let merge_head = 'MERGE_HEAD'
|
|
|
|
elseif filereadable(dir . '/REBASE_HEAD')
|
|
|
|
let merge_head = 'REBASE_HEAD'
|
|
|
|
else
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
if commit ==# '3'
|
|
|
|
return merge_head . '^{}'
|
|
|
|
elseif commit ==# '1'
|
|
|
|
return s:TreeChomp('merge-base', 'HEAD', merge_head, '--')
|
|
|
|
endif
|
2018-08-07 15:33:19 -04:00
|
|
|
endif
|
|
|
|
let path = fnamemodify(a:path, ':p')
|
|
|
|
if s:cpath(dir . '/', path[0 : len(dir)]) && a:path =~# 'HEAD$'
|
|
|
|
return strpart(path, len(dir) + 1)
|
|
|
|
endif
|
|
|
|
let refs = fugitive#CommonDir(dir) . '/refs'
|
|
|
|
if s:cpath(refs . '/', path[0 : len(refs)]) && path !~# '[\/]$'
|
|
|
|
return strpart(path, len(refs) - 4)
|
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
2018-07-22 13:57:28 -04:00
|
|
|
function! fugitive#Real(url) abort
|
2018-08-06 01:21:19 -04:00
|
|
|
if empty(a:url)
|
|
|
|
return ''
|
|
|
|
endif
|
2018-06-20 18:01:27 -04:00
|
|
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
2018-06-05 12:28:16 -04:00
|
|
|
if len(dir)
|
2018-07-27 00:56:21 -04:00
|
|
|
let tree = s:Tree(dir)
|
2018-06-28 15:43:13 -04:00
|
|
|
return s:PlatformSlash((len(tree) ? tree : dir) . file)
|
2018-07-22 13:57:28 -04:00
|
|
|
endif
|
2018-08-06 01:21:19 -04:00
|
|
|
let pre = substitute(matchstr(a:url, '^\a\a\+\ze:'), '^.', '\u&', '')
|
|
|
|
if len(pre) && pre !=? 'fugitive' && exists('*' . pre . 'Real')
|
|
|
|
let url = {pre}Real(a:url)
|
|
|
|
else
|
|
|
|
let url = fnamemodify(a:url, ':p' . (a:url =~# '[\/]$' ? '' : ':s?[\/]$??'))
|
2018-06-05 12:28:16 -04:00
|
|
|
endif
|
2018-08-06 01:21:19 -04:00
|
|
|
return s:PlatformSlash(empty(url) ? a:url : url)
|
2018-06-05 12:28:16 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-07-22 19:15:22 -04:00
|
|
|
function! fugitive#Path(url, ...) abort
|
2018-08-25 16:04:27 -04:00
|
|
|
if empty(a:url)
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
|
|
|
let tree = s:Tree(dir)
|
|
|
|
if !a:0
|
2018-07-22 19:15:22 -04:00
|
|
|
return fugitive#Real(a:url)
|
2018-08-25 16:04:27 -04:00
|
|
|
elseif a:1 =~# '\.$'
|
|
|
|
let path = s:Slash(fugitive#Real(a:url))
|
|
|
|
let cwd = getcwd()
|
|
|
|
let lead = ''
|
|
|
|
while s:cpath(tree . '/', (cwd . '/')[0 : len(tree)])
|
|
|
|
if s:cpath(cwd . '/', path[0 : len(cwd)])
|
|
|
|
if strpart(path, len(cwd) + 1) =~# '^\.git\%(/\|$\)'
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
return a:1[0:-2] . (empty(lead) ? './' : lead) . strpart(path, len(cwd) + 1)
|
|
|
|
endif
|
|
|
|
let cwd = fnamemodify(cwd, ':h')
|
|
|
|
let lead .= '../'
|
|
|
|
endwhile
|
|
|
|
return a:1[0:-2] . path
|
2018-07-22 19:15:22 -04:00
|
|
|
endif
|
2018-07-30 01:35:11 -04:00
|
|
|
let url = s:Slash(fnamemodify(a:url, ':p'))
|
|
|
|
if url =~# '/$' && s:Slash(a:url) !~# '/$'
|
2018-07-29 13:06:32 -04:00
|
|
|
let url = url[0:-2]
|
|
|
|
endif
|
2018-07-22 19:15:22 -04:00
|
|
|
let [argdir, commit, file] = s:DirCommitFile(a:url)
|
|
|
|
if len(argdir) && s:cpath(argdir) !=# s:cpath(dir)
|
|
|
|
let file = ''
|
|
|
|
elseif len(dir) && s:cpath(url[0 : len(dir)]) ==# s:cpath(dir . '/')
|
|
|
|
let file = '/.git'.url[strlen(dir) : -1]
|
|
|
|
elseif len(tree) && s:cpath(url[0 : len(tree)]) ==# s:cpath(tree . '/')
|
|
|
|
let file = url[len(tree) : -1]
|
2019-01-05 01:56:46 -05:00
|
|
|
elseif s:cpath(url) ==# s:cpath(tree)
|
2018-07-28 16:51:17 -04:00
|
|
|
let file = '/'
|
2018-07-22 19:15:22 -04:00
|
|
|
endif
|
2018-08-03 22:50:32 -04:00
|
|
|
if empty(file) && a:1 =~# '^$\|^[.:]/$'
|
2018-07-30 01:35:11 -04:00
|
|
|
return s:Slash(fugitive#Real(a:url))
|
2018-07-22 19:15:22 -04:00
|
|
|
endif
|
|
|
|
return substitute(file, '^/', a:1, '')
|
2018-06-29 18:10:38 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
function! s:Relative(...) abort
|
2018-08-19 18:03:41 -04:00
|
|
|
return fugitive#Path(@%, a:0 ? a:1 : ':(top)')
|
2018-08-06 02:01:32 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-10-21 19:44:20 -04:00
|
|
|
function! fugitive#Find(object, ...) abort
|
2018-08-20 19:12:17 -04:00
|
|
|
if type(a:object) == type(0)
|
|
|
|
let name = bufname(a:object)
|
|
|
|
return s:PlatformSlash(name =~# '^$\|^/\|^\a\+:' ? name : getcwd() . '/' . name)
|
|
|
|
elseif a:object =~# '^[~$]'
|
2018-08-02 20:53:15 -04:00
|
|
|
let prefix = matchstr(a:object, '^[~$]\i*')
|
|
|
|
let owner = expand(prefix)
|
|
|
|
return s:PlatformSlash((len(owner) ? owner : prefix) . strpart(a:object, len(prefix)))
|
2018-08-19 17:49:45 -04:00
|
|
|
elseif s:Slash(a:object) =~# '^$\|^/\|^\%(\a\a\+:\).*\%(//\|::\)' . (has('win32') ? '\|^\a:/' : '')
|
2018-08-02 20:53:15 -04:00
|
|
|
return s:PlatformSlash(a:object)
|
2018-08-15 19:24:35 -04:00
|
|
|
elseif s:Slash(a:object) =~# '^\.\.\=\%(/\|$\)'
|
|
|
|
return s:PlatformSlash(simplify(getcwd() . '/' . a:object))
|
2018-08-02 20:53:15 -04:00
|
|
|
endif
|
|
|
|
let dir = a:0 ? a:1 : get(b:, 'git_dir', '')
|
2018-08-15 19:24:35 -04:00
|
|
|
if empty(dir)
|
2018-08-11 00:52:48 -04:00
|
|
|
let file = matchstr(a:object, '^\%(:\d:\|[^:]*:\)\zs.*', '', '')
|
|
|
|
let dir = FugitiveExtractGitDir(file)
|
|
|
|
if empty(dir)
|
|
|
|
return fnamemodify(len(file) ? file : a:object, ':p')
|
|
|
|
endif
|
|
|
|
endif
|
2018-08-19 16:52:58 -04:00
|
|
|
let rev = s:Slash(a:object)
|
2018-08-02 20:53:15 -04:00
|
|
|
let tree = s:Tree(dir)
|
|
|
|
let base = len(tree) ? tree : 'fugitive://' . dir . '//0'
|
2018-08-19 16:52:58 -04:00
|
|
|
if rev ==# '.git'
|
|
|
|
let f = len(tree) ? tree . '/.git' : dir
|
|
|
|
elseif rev =~# '^\.git/'
|
|
|
|
let f = substitute(rev, '^\.git', '', '')
|
2018-08-02 20:53:15 -04:00
|
|
|
let cdir = fugitive#CommonDir(dir)
|
2018-08-19 16:52:58 -04:00
|
|
|
if f =~# '^/\.\./\.\.\%(/\|$\)'
|
|
|
|
let f = simplify(len(tree) ? tree . f[3:-1] : dir . f)
|
|
|
|
elseif f =~# '^/\.\.\%(/\|$\)'
|
|
|
|
let f = base . f[3:-1]
|
|
|
|
elseif cdir !=# dir && (
|
|
|
|
\ f =~# '^/\%(config\|hooks\|info\|logs/refs\|objects\|refs\|worktrees\)\%(/\|$\)' ||
|
|
|
|
\ f !~# '^/logs$\|/\w*HEAD$' && getftime(dir . f) < 0 && getftime(cdir . f) >= 0)
|
|
|
|
let f = simplify(cdir . f)
|
2018-08-02 20:53:15 -04:00
|
|
|
else
|
2018-08-19 16:52:58 -04:00
|
|
|
let f = simplify(dir . f)
|
2018-08-02 20:53:15 -04:00
|
|
|
endif
|
2018-08-19 17:49:45 -04:00
|
|
|
elseif rev ==# ':/'
|
2018-08-02 20:53:15 -04:00
|
|
|
let f = base
|
|
|
|
elseif rev =~# '^\.\%(/\|$\)'
|
|
|
|
let f = base . rev[1:-1]
|
2018-08-11 00:52:48 -04:00
|
|
|
elseif rev =~# '^::\%(/\|\a\+\:\)'
|
|
|
|
let f = rev[2:-1]
|
|
|
|
elseif rev =~# '^::\.\.\=\%(/\|$\)'
|
|
|
|
let f = simplify(getcwd() . '/' . rev[2:-1])
|
|
|
|
elseif rev =~# '^::'
|
|
|
|
let f = base . '/' . rev[2:-1]
|
|
|
|
elseif rev =~# '^:\%([0-3]:\)\=\.\.\=\%(/\|$\)\|^:[0-3]:\%(/\|\a\+:\)'
|
|
|
|
let f = rev =~# '^:\%([0-3]:\)\=\.' ? simplify(getcwd() . '/' . matchstr(rev, '\..*')) : rev[3:-1]
|
|
|
|
if s:cpath(base . '/', (f . '/')[0 : len(base)])
|
|
|
|
let f = 'fugitive://' . dir . '//' . +matchstr(rev, '^:\zs\d\ze:') . '/' . strpart(f, len(base) + 1)
|
|
|
|
else
|
|
|
|
let altdir = FugitiveExtractGitDir(f)
|
|
|
|
if len(altdir) && !s:cpath(dir, altdir)
|
2018-10-21 19:44:20 -04:00
|
|
|
return fugitive#Find(a:object, altdir)
|
2018-08-11 00:52:48 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
elseif rev =~# '^:[0-3]:'
|
2018-08-02 20:53:15 -04:00
|
|
|
let f = 'fugitive://' . dir . '//' . rev[1] . '/' . rev[3:-1]
|
|
|
|
elseif rev ==# ':'
|
|
|
|
if $GIT_INDEX_FILE =~# '/[^/]*index[^/]*\.lock$' && s:cpath(fnamemodify($GIT_INDEX_FILE,':p')[0:strlen(dir)]) ==# s:cpath(dir . '/') && filereadable($GIT_INDEX_FILE)
|
|
|
|
let f = fnamemodify($GIT_INDEX_FILE, ':p')
|
|
|
|
else
|
|
|
|
let f = dir . '/index'
|
|
|
|
endif
|
|
|
|
elseif rev =~# '^:(\%(top\|top,literal\|literal,top\|literal\))'
|
|
|
|
let f = base . '/' . matchstr(rev, ')\zs.*')
|
|
|
|
elseif rev =~# '^:/\@!'
|
|
|
|
let f = 'fugitive://' . dir . '//0/' . rev[1:-1]
|
|
|
|
else
|
2018-08-07 15:33:19 -04:00
|
|
|
if rev =~# 'HEAD$\|^refs/' && rev !~# ':'
|
2018-08-02 20:53:15 -04:00
|
|
|
let cdir = rev =~# '^refs/' ? fugitive#CommonDir(dir) : dir
|
|
|
|
if filereadable(cdir . '/' . rev)
|
|
|
|
let f = simplify(cdir . '/' . rev)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if !exists('f')
|
2018-09-12 12:32:43 -04:00
|
|
|
let commit = substitute(matchstr(rev, '^[^:]\+\|^:.*'), '^@\%($\|[~^]\|@{\)\@=', 'HEAD', '')
|
2018-08-02 20:53:15 -04:00
|
|
|
let file = substitute(matchstr(rev, '^[^:]\+\zs:.*'), '^:', '/', '')
|
2018-08-11 00:52:48 -04:00
|
|
|
if file =~# '^/\.\.\=\%(/\|$\)\|^//\|^/\a\+:'
|
|
|
|
let file = file =~# '^/\.' ? simplify(getcwd() . file) : file[1:-1]
|
|
|
|
if s:cpath(base . '/', (file . '/')[0 : len(base)])
|
|
|
|
let file = '/' . strpart(file, len(base) + 1)
|
|
|
|
else
|
|
|
|
let altdir = FugitiveExtractGitDir(file)
|
|
|
|
if len(altdir) && !s:cpath(dir, altdir)
|
2018-10-21 19:44:20 -04:00
|
|
|
return fugitive#Find(a:object, altdir)
|
2018-08-11 00:52:48 -04:00
|
|
|
endif
|
|
|
|
return file
|
|
|
|
endif
|
|
|
|
endif
|
2018-08-02 20:53:15 -04:00
|
|
|
if commit !~# '^[0-9a-f]\{40\}$'
|
2018-08-19 20:52:29 -04:00
|
|
|
let commit = system(s:Prepare(dir, 'rev-parse', '--verify', commit, '--'))[0:-2]
|
2018-08-02 20:53:15 -04:00
|
|
|
let commit = v:shell_error ? '' : commit
|
|
|
|
endif
|
|
|
|
if len(commit)
|
|
|
|
let f = 'fugitive://' . dir . '//' . commit . file
|
|
|
|
else
|
2018-08-11 00:52:48 -04:00
|
|
|
let f = base . '/' . substitute(rev, '^:/:\=\|^[^:]\+:', '', '')
|
2018-08-02 20:53:15 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
return s:PlatformSlash(f)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Generate(rev, ...) abort
|
|
|
|
let dir = a:0 ? a:1 : get(b:, 'git_dir', '')
|
|
|
|
let tree = s:Tree(dir)
|
|
|
|
let object = a:rev
|
2018-08-11 00:52:48 -04:00
|
|
|
if a:rev =~# '^/\.git\%(/\|$\)'
|
|
|
|
let object = a:rev[1:-1]
|
|
|
|
elseif a:rev =~# '^/' && len(tree) && getftime(tree . a:rev) >= 0 && getftime(a:rev) < 0
|
|
|
|
let object = ':(top)' . a:rev[1:-1]
|
2018-08-02 20:53:15 -04:00
|
|
|
endif
|
2018-10-21 19:44:20 -04:00
|
|
|
return fugitive#Find(object, dir)
|
2018-08-02 20:53:15 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-28 00:35:06 -04:00
|
|
|
function! s:DotRelative(path) abort
|
|
|
|
let cwd = getcwd()
|
|
|
|
let path = substitute(a:path, '^[~$]\i*', '\=expand(submatch(0))', '')
|
|
|
|
if s:cpath(cwd . '/', (path . '/')[0 : len(cwd)])
|
|
|
|
return '.' . strpart(path, len(cwd))
|
2018-07-31 19:44:03 -04:00
|
|
|
endif
|
2018-08-28 00:35:06 -04:00
|
|
|
return a:path
|
2018-07-31 19:44:03 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-10 19:20:31 -04:00
|
|
|
function! fugitive#Object(...) abort
|
|
|
|
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
|
|
|
let [fdir, rev] = s:DirRev(a:0 ? a:1 : @%)
|
|
|
|
if s:cpath(dir) !=# s:cpath(fdir)
|
|
|
|
let rev = ''
|
|
|
|
endif
|
|
|
|
let tree = s:Tree(dir)
|
|
|
|
if empty(rev) && empty(tree)
|
|
|
|
elseif empty(rev)
|
|
|
|
let rev = fugitive#Path(a:0 ? a:1 : @%, './', dir)
|
|
|
|
let cdir = fugitive#CommonDir(dir)
|
|
|
|
if rev =~# '^\./\.git/refs/\%(tags\|heads\|remotes\)/.\|^\./\.git/\w*HEAD$'
|
|
|
|
let rev = rev[7:-1]
|
|
|
|
elseif s:cpath(cdir . '/refs/', rev[0 : len(cdir)])
|
|
|
|
let rev = strpart(rev, len(cdir)+1)
|
|
|
|
elseif rev =~# '^\./.git\%(/\|$\)'
|
|
|
|
return fnamemodify(a:0 ? a:1 : @%, ':p')
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if rev !~# '^\.\%(/\|$\)' || s:cpath(getcwd(), tree)
|
|
|
|
return rev
|
|
|
|
else
|
|
|
|
return tree . rev[1:-1]
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-08-28 00:35:06 -04:00
|
|
|
let s:var = '\%(%\|#<\=\d\+\|##\=\)'
|
|
|
|
let s:flag = '\%(:[p8~.htre]\|:g\=s\(.\).\{-\}\1.\{-\}\1\)'
|
|
|
|
let s:expand = '\%(\(' . s:var . '\)\(' . s:flag . '*\)\(:S\)\=\)'
|
|
|
|
|
|
|
|
function! s:BufName(var) abort
|
|
|
|
if a:var ==# '%'
|
|
|
|
return bufname(get(b:, 'fugitive_blamed_bufnr', ''))
|
|
|
|
elseif a:var =~# '^#\d*$'
|
|
|
|
let nr = getbufvar(+a:var[1:-1], 'fugitive_blamed_bufnr', '')
|
|
|
|
return bufname(nr ? nr : +a:var[1:-1])
|
|
|
|
else
|
|
|
|
return expand(a:var)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:ExpandVar(other, var, flags, esc) abort
|
|
|
|
if a:other =~# '^\'
|
|
|
|
return a:other[1:-1]
|
|
|
|
elseif a:other =~# '^!'
|
|
|
|
let buffer = s:BufName(len(a:other) > 1 ? '#'. a:other[1:-1] : '%')
|
|
|
|
let owner = s:Owner(buffer)
|
|
|
|
return len(owner) ? owner : '@'
|
|
|
|
endif
|
|
|
|
let flags = a:flags
|
|
|
|
let file = s:DotRelative(fugitive#Real(s:BufName(a:var)))
|
|
|
|
while len(flags)
|
|
|
|
let flag = matchstr(flags, s:flag)
|
|
|
|
let flags = strpart(flags, len(flag))
|
|
|
|
if flag ==# ':.'
|
|
|
|
let file = s:DotRelative(file)
|
|
|
|
else
|
|
|
|
let file = fnamemodify(file, flag)
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
let file = s:Slash(file)
|
|
|
|
return (len(a:esc) ? shellescape(file) : file)
|
|
|
|
endfunction
|
|
|
|
|
2018-08-03 22:50:32 -04:00
|
|
|
function! s:Expand(rev) abort
|
2018-07-31 19:44:03 -04:00
|
|
|
if a:rev =~# '^:[0-3]$'
|
2018-08-03 22:50:32 -04:00
|
|
|
let file = a:rev . s:Relative(':')
|
2018-07-31 19:44:03 -04:00
|
|
|
elseif a:rev =~# '^-'
|
2018-08-03 22:50:32 -04:00
|
|
|
let file = 'HEAD^{}' . a:rev[1:-1] . s:Relative(':')
|
2018-07-31 19:44:03 -04:00
|
|
|
elseif a:rev =~# '^@{'
|
2018-08-11 01:26:09 -04:00
|
|
|
let file = 'HEAD' . a:rev. s:Relative(':')
|
2018-08-28 00:35:06 -04:00
|
|
|
elseif a:rev =~# '^\^[0-9~^{]\|^\~[0-9~^]'
|
2018-08-11 01:26:09 -04:00
|
|
|
let commit = substitute(s:DirCommitFile(@%)[1], '^\d\=$', 'HEAD', '')
|
2018-08-03 22:50:32 -04:00
|
|
|
let file = commit . a:rev . s:Relative(':')
|
2018-07-31 19:44:03 -04:00
|
|
|
else
|
|
|
|
let file = a:rev
|
|
|
|
endif
|
2018-08-28 00:35:06 -04:00
|
|
|
return substitute(file,
|
|
|
|
\ '\(\\[' . s:fnameescape . ']\|^\\[>+-]\|!\d*\)\|' . s:expand,
|
|
|
|
\ '\=s:ExpandVar(submatch(1),submatch(2),submatch(3),"")', 'g')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#Expand(object) abort
|
|
|
|
return substitute(a:object,
|
|
|
|
\ '\(\\[' . s:fnameescape . ']\|^\\[>+-]\|!\d*\)\|' . s:expand,
|
|
|
|
\ '\=s:ExpandVar(submatch(1),submatch(2),submatch(3),submatch(5))', 'g')
|
2018-07-31 19:44:03 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-03 22:50:32 -04:00
|
|
|
function! s:ShellExpand(cmd) abort
|
2018-08-28 00:35:06 -04:00
|
|
|
return substitute(a:cmd, '\(\\[!#%]\|!\d*\)\|' . s:expand,
|
|
|
|
\ '\=s:ExpandVar(submatch(1),submatch(2),submatch(3),submatch(5))', 'g')
|
2018-07-31 19:44:03 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-06-20 17:25:12 -04:00
|
|
|
let s:trees = {}
|
|
|
|
let s:indexes = {}
|
|
|
|
function! s:TreeInfo(dir, commit) abort
|
|
|
|
if a:commit =~# '^:\=[0-3]$'
|
|
|
|
let index = get(s:indexes, a:dir, [])
|
|
|
|
let newftime = getftime(a:dir . '/index')
|
|
|
|
if get(index, 0, -1) < newftime
|
2018-08-31 15:36:44 -04:00
|
|
|
let out = system(fugitive#Prepare(a:dir, 'ls-files', '--stage', '--'))
|
2018-06-20 17:25:12 -04:00
|
|
|
let s:indexes[a:dir] = [newftime, {'0': {}, '1': {}, '2': {}, '3': {}}]
|
|
|
|
if v:shell_error
|
|
|
|
return [{}, -1]
|
|
|
|
endif
|
|
|
|
for line in split(out, "\n")
|
|
|
|
let [info, filename] = split(line, "\t")
|
|
|
|
let [mode, sha, stage] = split(info, '\s\+')
|
|
|
|
let s:indexes[a:dir][1][stage][filename] = [newftime, mode, 'blob', sha, -2]
|
|
|
|
while filename =~# '/'
|
|
|
|
let filename = substitute(filename, '/[^/]*$', '', '')
|
|
|
|
let s:indexes[a:dir][1][stage][filename] = [newftime, '040000', 'tree', '', 0]
|
|
|
|
endwhile
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
return [get(s:indexes[a:dir][1], a:commit[-1:-1], {}), newftime]
|
|
|
|
elseif a:commit =~# '^\x\{40\}$'
|
|
|
|
if !has_key(s:trees, a:dir)
|
2018-08-06 16:38:30 -04:00
|
|
|
let s:trees[a:dir] = {}
|
|
|
|
endif
|
|
|
|
if !has_key(s:trees[a:dir], a:commit)
|
2018-08-31 15:36:44 -04:00
|
|
|
let ftime = +system(fugitive#Prepare(a:dir, 'log', '-1', '--pretty=format:%ct', a:commit, '--'))
|
2018-06-20 17:25:12 -04:00
|
|
|
if v:shell_error
|
2018-08-06 16:38:30 -04:00
|
|
|
let s:trees[a:dir][a:commit] = [{}, -1]
|
|
|
|
return s:trees[a:dir][a:commit]
|
2018-06-20 17:25:12 -04:00
|
|
|
endif
|
2018-08-06 16:38:30 -04:00
|
|
|
let s:trees[a:dir][a:commit] = [{}, +ftime]
|
2018-08-31 15:36:44 -04:00
|
|
|
let out = system(fugitive#Prepare(a:dir, 'ls-tree', '-rtl', '--full-name', a:commit, '--'))
|
2018-06-20 17:25:12 -04:00
|
|
|
if v:shell_error
|
2018-08-06 16:38:30 -04:00
|
|
|
return s:trees[a:dir][a:commit]
|
2018-06-20 17:25:12 -04:00
|
|
|
endif
|
|
|
|
for line in split(out, "\n")
|
|
|
|
let [info, filename] = split(line, "\t")
|
|
|
|
let [mode, type, sha, size] = split(info, '\s\+')
|
2018-08-06 16:38:30 -04:00
|
|
|
let s:trees[a:dir][a:commit][0][filename] = [ftime, mode, type, sha, +size, filename]
|
2018-06-20 17:25:12 -04:00
|
|
|
endfor
|
|
|
|
endif
|
2018-08-06 16:38:30 -04:00
|
|
|
return s:trees[a:dir][a:commit]
|
2018-06-20 17:25:12 -04:00
|
|
|
endif
|
|
|
|
return [{}, -1]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:PathInfo(url) abort
|
|
|
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
|
|
|
if empty(dir) || !get(g:, 'fugitive_file_api', 1)
|
|
|
|
return [-1, '000000', '', '', -1]
|
|
|
|
endif
|
|
|
|
let path = substitute(file[1:-1], '/*$', '', '')
|
|
|
|
let [tree, ftime] = s:TreeInfo(dir, commit)
|
|
|
|
let entry = empty(path) ? [ftime, '040000', 'tree', '', -1] : get(tree, path, [])
|
|
|
|
if empty(entry) || file =~# '/$' && entry[1] !=# 'tree'
|
|
|
|
return [-1, '000000', '', '', -1]
|
|
|
|
else
|
|
|
|
return entry
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#simplify(url) abort
|
|
|
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
|
|
|
if empty(dir)
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
if file =~# '/\.\.\%(/\|$\)'
|
2018-07-27 00:56:21 -04:00
|
|
|
let tree = s:Tree(dir)
|
2018-06-20 17:25:12 -04:00
|
|
|
if len(tree)
|
|
|
|
let path = simplify(tree . file)
|
|
|
|
if strpart(path . '/', 0, len(tree) + 1) !=# tree . '/'
|
|
|
|
return s:PlatformSlash(path)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
return s:PlatformSlash('fugitive://' . simplify(dir) . '//' . commit . simplify(file))
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#resolve(url) abort
|
|
|
|
let url = fugitive#simplify(a:url)
|
|
|
|
if url =~? '^fugitive:'
|
|
|
|
return url
|
|
|
|
else
|
|
|
|
return resolve(url)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#getftime(url) abort
|
|
|
|
return s:PathInfo(a:url)[0]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#getfsize(url) abort
|
|
|
|
let entry = s:PathInfo(a:url)
|
|
|
|
if entry[4] == -2 && entry[2] ==# 'blob' && len(entry[3])
|
|
|
|
let dir = s:DirCommitFile(a:url)[0]
|
2018-09-12 12:06:19 -04:00
|
|
|
let size = +system(s:Prepare(dir, 'cat-file', '-s', entry[3]))
|
2018-06-20 17:25:12 -04:00
|
|
|
let entry[4] = v:shell_error ? -1 : size
|
|
|
|
endif
|
|
|
|
return entry[4]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#getftype(url) abort
|
|
|
|
return get({'tree': 'dir', 'blob': 'file'}, s:PathInfo(a:url)[2], '')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#filereadable(url) abort
|
|
|
|
return s:PathInfo(a:url)[2] ==# 'blob'
|
|
|
|
endfunction
|
|
|
|
|
2018-07-26 18:09:47 -04:00
|
|
|
function! fugitive#filewritable(url) abort
|
|
|
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
|
|
|
if commit !~# '^\d$' || !filewritable(dir . '/index')
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
return s:PathInfo(a:url)[2] ==# 'blob' ? 1 : 2
|
|
|
|
endfunction
|
|
|
|
|
2018-06-20 17:25:12 -04:00
|
|
|
function! fugitive#isdirectory(url) abort
|
|
|
|
return s:PathInfo(a:url)[2] ==# 'tree'
|
|
|
|
endfunction
|
|
|
|
|
2018-07-26 20:55:47 -04:00
|
|
|
function! fugitive#getfperm(url) abort
|
|
|
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
|
|
|
let perm = getfperm(dir)
|
|
|
|
let fperm = s:PathInfo(a:url)[1]
|
|
|
|
if fperm ==# '040000'
|
|
|
|
let fperm = '000755'
|
|
|
|
endif
|
|
|
|
if fperm !~# '[15]'
|
|
|
|
let perm = tr(perm, 'x', '-')
|
|
|
|
endif
|
|
|
|
if fperm !~# '[45]$'
|
|
|
|
let perm = tr(perm, 'rw', '--')
|
|
|
|
endif
|
|
|
|
if commit !~# '^\d$'
|
|
|
|
let perm = tr(perm, 'w', '-')
|
|
|
|
endif
|
|
|
|
return perm ==# '---------' ? '' : perm
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#setfperm(url, perm) abort
|
|
|
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
|
|
|
let entry = s:PathInfo(a:url)
|
|
|
|
let perm = fugitive#getfperm(a:url)
|
|
|
|
if commit !~# '^\d$' || entry[2] !=# 'blob' ||
|
|
|
|
\ substitute(perm, 'x', '-', 'g') !=# substitute(a:perm, 'x', '-', 'g')
|
|
|
|
return -2
|
|
|
|
endif
|
2018-07-28 19:54:35 -04:00
|
|
|
call system(s:Prepare(dir, 'update-index', '--index-info'),
|
2018-07-26 20:55:47 -04:00
|
|
|
\ (a:perm =~# 'x' ? '000755 ' : '000644 ') . entry[3] . ' ' . commit . "\t" . file[1:-1])
|
|
|
|
return v:shell_error ? -1 : 0
|
|
|
|
endfunction
|
|
|
|
|
2018-07-22 22:37:28 -04:00
|
|
|
function! s:TempCmd(out, cmd) abort
|
|
|
|
let prefix = ''
|
|
|
|
try
|
2018-07-28 19:54:35 -04:00
|
|
|
let cmd = (type(a:cmd) == type([]) ? call('s:Prepare', a:cmd) : a:cmd)
|
2018-07-22 22:37:28 -04:00
|
|
|
let redir = ' > ' . a:out
|
|
|
|
if s:winshell()
|
|
|
|
let cmd_escape_char = &shellxquote == '(' ? '^' : '^^^'
|
|
|
|
return s:System('cmd /c "' . prefix . s:gsub(cmd, '[<>]', cmd_escape_char . '&') . redir . '"')
|
|
|
|
elseif &shell =~# 'fish'
|
|
|
|
return s:System(' begin;' . prefix . cmd . redir . ';end ')
|
|
|
|
else
|
|
|
|
return s:System(' (' . prefix . cmd . redir . ') ')
|
|
|
|
endif
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2018-07-16 23:34:02 -04:00
|
|
|
if !exists('s:blobdirs')
|
|
|
|
let s:blobdirs = {}
|
|
|
|
endif
|
|
|
|
function! s:BlobTemp(url) abort
|
|
|
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
|
|
|
if empty(file)
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
if !has_key(s:blobdirs, dir)
|
2018-08-18 23:12:09 -04:00
|
|
|
let s:blobdirs[dir] = tempname()
|
2018-07-16 23:34:02 -04:00
|
|
|
endif
|
2018-08-18 23:12:09 -04:00
|
|
|
let tempfile = s:blobdirs[dir] . '/' . commit . file
|
2018-07-16 23:34:02 -04:00
|
|
|
let tempparent = fnamemodify(tempfile, ':h')
|
|
|
|
if !isdirectory(tempparent)
|
|
|
|
call mkdir(tempparent, 'p')
|
|
|
|
endif
|
|
|
|
if commit =~# '^\d$' || !filereadable(tempfile)
|
|
|
|
let rev = s:DirRev(a:url)[1]
|
2018-09-12 12:06:19 -04:00
|
|
|
let command = s:Prepare(dir, 'cat-file', 'blob', rev)
|
2018-07-16 23:34:02 -04:00
|
|
|
call s:TempCmd(tempfile, command)
|
|
|
|
if v:shell_error
|
|
|
|
call delete(tempfile)
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
endif
|
2018-08-18 23:12:09 -04:00
|
|
|
return s:Resolve(tempfile)
|
2018-07-16 23:34:02 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-06-20 17:25:12 -04:00
|
|
|
function! fugitive#readfile(url, ...) abort
|
|
|
|
let entry = s:PathInfo(a:url)
|
|
|
|
if entry[2] !=# 'blob'
|
|
|
|
return []
|
|
|
|
endif
|
2018-07-16 23:34:02 -04:00
|
|
|
let temp = s:BlobTemp(a:url)
|
|
|
|
if empty(temp)
|
2018-06-20 17:25:12 -04:00
|
|
|
return []
|
|
|
|
endif
|
2018-07-16 23:34:02 -04:00
|
|
|
return call('readfile', [temp] + a:000)
|
2018-06-20 17:25:12 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-07-26 18:09:47 -04:00
|
|
|
function! fugitive#writefile(lines, url, ...) abort
|
|
|
|
let url = type(a:url) ==# type('') ? a:url : ''
|
|
|
|
let [dir, commit, file] = s:DirCommitFile(url)
|
|
|
|
let entry = s:PathInfo(url)
|
|
|
|
if commit =~# '^\d$' && entry[2] !=# 'tree'
|
2018-08-18 23:12:09 -04:00
|
|
|
let temp = tempname()
|
2018-07-26 18:09:47 -04:00
|
|
|
if a:0 && a:1 =~# 'a' && entry[2] ==# 'blob'
|
|
|
|
call writefile(fugitive#readfile(url, 'b'), temp, 'b')
|
|
|
|
endif
|
|
|
|
call call('writefile', [a:lines, temp] + a:000)
|
2018-07-28 19:54:35 -04:00
|
|
|
let hash = system(s:Prepare(dir, 'hash-object', '-w', temp))[0:-2]
|
2018-07-26 18:09:47 -04:00
|
|
|
let mode = len(entry[1]) ? entry[1] : '100644'
|
|
|
|
if !v:shell_error && hash =~# '^\x\{40\}$'
|
2018-07-28 19:54:35 -04:00
|
|
|
call system(s:Prepare(dir, 'update-index', '--index-info'),
|
2018-07-26 18:09:47 -04:00
|
|
|
\ mode . ' ' . hash . ' ' . commit . "\t" . file[1:-1])
|
|
|
|
if !v:shell_error
|
|
|
|
return 0
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
return call('writefile', [a:lines, a:url] + a:000)
|
|
|
|
endfunction
|
|
|
|
|
2018-08-10 03:14:47 -04:00
|
|
|
let s:globsubs = {
|
|
|
|
\ '/**/': '/\%([^./][^/]*/\)*',
|
|
|
|
\ '/**': '/\%([^./][^/]\+/\)*[^./][^/]*',
|
|
|
|
\ '**/': '[^/]*\%(/[^./][^/]*\)*',
|
|
|
|
\ '**': '.*',
|
|
|
|
\ '/*': '/[^/.][^/]*',
|
|
|
|
\ '*': '[^/]*',
|
|
|
|
\ '?': '[^/]'}
|
2018-06-20 17:25:12 -04:00
|
|
|
function! fugitive#glob(url, ...) abort
|
|
|
|
let [dirglob, commit, glob] = s:DirCommitFile(a:url)
|
|
|
|
let append = matchstr(glob, '/*$')
|
|
|
|
let glob = substitute(glob, '/*$', '', '')
|
2018-08-10 03:14:47 -04:00
|
|
|
let pattern = '^' . substitute(glob, '/\=\*\*/\=\|/\=\*\|[.?\^$]', '\=get(s:globsubs, submatch(0), "\\" . submatch(0))', 'g')[1:-1] . '$'
|
2018-06-20 17:25:12 -04:00
|
|
|
let results = []
|
|
|
|
for dir in dirglob =~# '[*?]' ? split(glob(dirglob), "\n") : [dirglob]
|
|
|
|
if empty(dir) || !get(g:, 'fugitive_file_api', 1) || !filereadable(dir . '/HEAD')
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
let files = items(s:TreeInfo(dir, commit)[0])
|
|
|
|
if len(append)
|
|
|
|
call filter(files, 'v:val[1][2] ==# "tree"')
|
|
|
|
endif
|
|
|
|
call map(files, 'v:val[0]')
|
|
|
|
call filter(files, 'v:val =~# pattern')
|
|
|
|
let prepend = 'fugitive://' . dir . '//' . substitute(commit, '^:', '', '') . '/'
|
|
|
|
call sort(files)
|
|
|
|
call map(files, 's:PlatformSlash(prepend . v:val . append)')
|
|
|
|
call extend(results, files)
|
|
|
|
endfor
|
|
|
|
if a:0 > 1 && a:2
|
|
|
|
return results
|
|
|
|
else
|
|
|
|
return join(results, "\n")
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-07-26 17:12:14 -04:00
|
|
|
function! fugitive#delete(url, ...) abort
|
|
|
|
let [dir, commit, file] = s:DirCommitFile(a:url)
|
|
|
|
if a:0 && len(a:1) || commit !~# '^\d$'
|
|
|
|
return -1
|
|
|
|
endif
|
|
|
|
let entry = s:PathInfo(a:url)
|
|
|
|
if entry[2] !=# 'blob'
|
|
|
|
return -1
|
|
|
|
endif
|
2018-07-28 19:54:35 -04:00
|
|
|
call system(s:Prepare(dir, 'update-index', '--index-info'),
|
2018-07-26 17:12:14 -04:00
|
|
|
\ '000000 0000000000000000000000000000000000000000 ' . commit . "\t" . file[1:-1])
|
|
|
|
return v:shell_error ? -1 : 0
|
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: Buffer Object
|
|
|
|
|
2018-06-01 13:46:22 -04:00
|
|
|
let s:buffer_prototype = {}
|
|
|
|
|
2018-07-28 20:26:31 -04:00
|
|
|
function! fugitive#buffer(...) abort
|
2018-06-01 13:46:22 -04:00
|
|
|
let buffer = {'#': bufnr(a:0 ? a:1 : '%')}
|
2018-08-06 02:01:32 -04:00
|
|
|
call extend(buffer, s:buffer_prototype, 'keep')
|
2018-12-28 17:10:45 -05:00
|
|
|
return buffer
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:buffer_getvar(var) dict abort
|
2018-12-28 17:10:45 -05:00
|
|
|
throw 'fugitive: Removed in favor of getbufvar()'
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:buffer_getline(lnum) dict abort
|
2018-12-28 17:10:45 -05:00
|
|
|
throw 'fugitive: Removed in favor of getbufline()'
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:buffer_repo() dict abort
|
2018-12-28 17:10:45 -05:00
|
|
|
throw 'fugitive: Removed in favor of fugitive#repo()'
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:buffer_type(...) dict abort
|
2018-12-28 17:10:45 -05:00
|
|
|
throw 'fugitive: Removed in favor of b:fugitive_type (or ideally avoid entirely)'
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-12-28 17:10:45 -05:00
|
|
|
function! s:buffer_spec() dict abort
|
|
|
|
throw "fugitive: Removed in favor of bufname(), expand('%:p'), etc."
|
|
|
|
endfunction
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
function! s:buffer_name() dict abort
|
2018-12-28 17:10:45 -05:00
|
|
|
throw "fugitive: Removed in favor of bufname(), expand('%:p'), etc."
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:buffer_commit() dict abort
|
2018-12-28 17:10:45 -05:00
|
|
|
throw 'fugitive: Removed in favor of FugitiveParse()'
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-06-25 16:43:00 -04:00
|
|
|
function! s:buffer_relative(...) dict abort
|
2018-12-28 17:10:45 -05:00
|
|
|
throw 'fugitive: Removed in favor of FugitivePath(bufname, ' . string(a:0 ? a:1 : '') . ')'
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-06-27 17:11:59 -04:00
|
|
|
function! s:buffer_path(...) dict abort
|
2018-12-28 17:10:45 -05:00
|
|
|
throw 'fugitive: Removed in favor of FugitivePath(bufname, ' . string(a:0 ? a:1 : '') . ')'
|
2018-06-27 17:11:59 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-10 19:20:31 -04:00
|
|
|
call s:add_methods('buffer',['getvar','getline','repo','type','spec','name','commit','path','relative'])
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-07-29 14:24:05 -04:00
|
|
|
" Section: Completion
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-07-28 21:08:56 -04:00
|
|
|
function! s:GlobComplete(lead, pattern) abort
|
|
|
|
if v:version >= 704
|
|
|
|
let results = glob(a:lead . a:pattern, 0, 1)
|
|
|
|
else
|
|
|
|
let results = split(glob(a:lead . a:pattern), "\n")
|
|
|
|
endif
|
|
|
|
call map(results, 'v:val !~# "/$" && isdirectory(v:val) ? v:val."/" : v:val')
|
|
|
|
call map(results, 'v:val[ strlen(a:lead) : -1 ]')
|
|
|
|
return results
|
|
|
|
endfunction
|
|
|
|
|
2018-07-29 14:24:05 -04:00
|
|
|
function! fugitive#PathComplete(base, ...) abort
|
2018-07-28 21:08:56 -04:00
|
|
|
let dir = a:0 == 1 ? a:1 : get(b:, 'git_dir', '')
|
2018-08-15 19:24:35 -04:00
|
|
|
let tree = s:Tree(dir) . '/'
|
|
|
|
let strip = '^\%(:/:\=\|:(top)\|:(top,literal)\|:(literal,top)\|:(literal)\)'
|
|
|
|
let base = substitute(a:base, strip, '', '')
|
2018-07-28 21:08:56 -04:00
|
|
|
if base =~# '^\.git/'
|
|
|
|
let pattern = s:gsub(base[5:-1], '/', '*&').'*'
|
|
|
|
let matches = s:GlobComplete(dir . '/', pattern)
|
|
|
|
let cdir = fugitive#CommonDir(dir)
|
|
|
|
if len(cdir) && s:cpath(dir) !=# s:cpath(cdir)
|
|
|
|
call extend(matches, s:GlobComplete(cdir . '/', pattern))
|
|
|
|
endif
|
|
|
|
call s:Uniq(matches)
|
|
|
|
call map(matches, "'.git/' . v:val")
|
2018-08-05 23:45:50 -04:00
|
|
|
elseif base =~# '^\~/'
|
|
|
|
let matches = map(s:GlobComplete(expand('~/'), base[2:-1] . '*'), '"~/" . v:val')
|
2018-08-15 19:24:35 -04:00
|
|
|
elseif a:base =~# '^/\|^\a\+:\|^\.\.\=/\|^:(literal)'
|
|
|
|
let matches = s:GlobComplete('', base . '*')
|
2018-08-02 18:17:54 -04:00
|
|
|
elseif len(tree) > 1
|
2018-07-28 21:08:56 -04:00
|
|
|
let matches = s:GlobComplete(tree, s:gsub(base, '/', '*&').'*')
|
2018-08-02 18:17:54 -04:00
|
|
|
else
|
|
|
|
let matches = []
|
2018-07-28 21:08:56 -04:00
|
|
|
endif
|
2018-07-30 01:35:11 -04:00
|
|
|
call map(matches, 's:fnameescape(s:Slash(matchstr(a:base, strip) . v:val))')
|
2018-07-29 14:24:05 -04:00
|
|
|
return matches
|
|
|
|
endfunction
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-07-29 14:24:05 -04:00
|
|
|
function! fugitive#Complete(base, ...) abort
|
|
|
|
let dir = a:0 == 1 ? a:1 : get(b:, 'git_dir', '')
|
2018-08-11 00:52:48 -04:00
|
|
|
let cwd = a:0 == 1 ? s:Tree(dir) : getcwd()
|
2018-07-28 21:08:56 -04:00
|
|
|
let tree = s:Tree(dir) . '/'
|
2018-08-12 21:28:21 -04:00
|
|
|
let subdir = ''
|
|
|
|
if len(tree) > 1 && s:cpath(tree, cwd[0 : len(tree) - 1])
|
|
|
|
let subdir = strpart(cwd, len(tree)) . '/'
|
|
|
|
endif
|
|
|
|
|
2018-08-02 18:51:12 -04:00
|
|
|
if a:base =~# '^\.\=/\|^:(' || a:base !~# ':'
|
2018-07-29 14:24:05 -04:00
|
|
|
let results = []
|
2018-07-28 21:08:56 -04:00
|
|
|
if a:base =~# '^refs/'
|
2018-07-30 01:35:11 -04:00
|
|
|
let results += map(s:GlobComplete(fugitive#CommonDir(dir) . '/', a:base . '*'), 's:Slash(v:val)')
|
2018-08-02 18:51:12 -04:00
|
|
|
elseif a:base !~# '^\.\=/\|^:('
|
2018-07-28 21:08:56 -04:00
|
|
|
let heads = ['HEAD', 'ORIG_HEAD', 'FETCH_HEAD', 'MERGE_HEAD', 'refs/']
|
2018-07-29 14:24:05 -04:00
|
|
|
let heads += sort(split(s:TreeChomp(["rev-parse","--symbolic","--branches","--tags","--remotes"], dir),"\n"))
|
2018-07-28 21:08:56 -04:00
|
|
|
if filereadable(fugitive#CommonDir(dir) . '/refs/stash')
|
2018-07-29 14:24:05 -04:00
|
|
|
let heads += ["stash"]
|
|
|
|
let heads += sort(split(s:TreeChomp(["stash","list","--pretty=format:%gd"], dir),"\n"))
|
|
|
|
endif
|
|
|
|
call filter(heads,'v:val[ 0 : strlen(a:base)-1 ] ==# a:base')
|
|
|
|
let results += heads
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
call map(results, 's:fnameescape(v:val)')
|
2018-07-28 21:08:56 -04:00
|
|
|
if !empty(tree)
|
2018-08-11 00:52:48 -04:00
|
|
|
let results += a:0 == 1 ? fugitive#PathComplete(a:base, dir) : fugitive#PathComplete(a:base)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
return results
|
2018-07-27 01:30:41 -04:00
|
|
|
|
2018-07-29 14:24:05 -04:00
|
|
|
elseif a:base =~# '^:'
|
|
|
|
let entries = split(s:TreeChomp(['ls-files','--stage'], dir),"\n")
|
2018-08-11 00:52:48 -04:00
|
|
|
if a:base =~# ':\./'
|
|
|
|
call map(entries, 'substitute(v:val, "\\M\t\\zs" . subdir, "./", "")')
|
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
call map(entries,'s:sub(v:val,".*(\\d)\\t(.*)",":\\1:\\2")')
|
|
|
|
if a:base !~# '^:[0-3]\%(:\|$\)'
|
|
|
|
call filter(entries,'v:val[1] == "0"')
|
|
|
|
call map(entries,'v:val[2:-1]')
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
else
|
2018-08-11 00:52:48 -04:00
|
|
|
let tree = matchstr(a:base, '.*[:/]')
|
2018-08-12 21:28:21 -04:00
|
|
|
let entries = split(s:TreeChomp(['ls-tree', substitute(tree, ':\zs\./', '\=subdir', '')], dir),"\n")
|
2018-07-29 14:24:05 -04:00
|
|
|
call map(entries,'s:sub(v:val,"^04.*\\zs$","/")')
|
|
|
|
call map(entries,'tree.s:sub(v:val,".*\t","")')
|
2018-08-11 00:52:48 -04:00
|
|
|
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-08-11 00:52:48 -04:00
|
|
|
call filter(entries, 'v:val[ 0 : strlen(a:base)-1 ] ==# a:base')
|
|
|
|
return map(entries, 's:fnameescape(v:val)')
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: Buffer auto-commands
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-09-09 09:34:52 -04:00
|
|
|
function! s:ReplaceCmd(cmd, ...) abort
|
2018-08-18 23:12:09 -04:00
|
|
|
let temp = tempname()
|
|
|
|
let err = s:TempCmd(temp, a:cmd)
|
2018-07-29 14:24:05 -04:00
|
|
|
if v:shell_error
|
2018-08-18 23:12:09 -04:00
|
|
|
call s:throw((len(err) ? err : filereadable(temp) ? join(readfile(temp), ' ') : 'unknown error running ' . a:cmd))
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-08-18 23:12:09 -04:00
|
|
|
let temp = s:Resolve(temp)
|
2018-07-29 14:24:05 -04:00
|
|
|
let fn = expand('%:p')
|
2018-08-18 23:12:09 -04:00
|
|
|
silent exe 'keepalt file '.temp
|
2018-12-23 14:30:34 -05:00
|
|
|
let modelines = &modelines
|
2018-06-01 13:46:22 -04:00
|
|
|
try
|
2018-12-23 14:30:34 -05:00
|
|
|
set modelines=0
|
2018-09-09 09:34:52 -04:00
|
|
|
if a:0
|
2019-01-03 16:06:29 -05:00
|
|
|
silent keepjumps noautocmd edit!
|
2018-09-09 09:34:52 -04:00
|
|
|
else
|
2019-01-03 16:06:29 -05:00
|
|
|
silent keepjumps edit!
|
2018-09-09 09:34:52 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
finally
|
2018-12-23 14:30:34 -05:00
|
|
|
let &modelines = modelines
|
2018-07-29 14:24:05 -04:00
|
|
|
try
|
|
|
|
silent exe 'keepalt file '.s:fnameescape(fn)
|
|
|
|
catch /^Vim\%((\a\+)\)\=:E302:/
|
|
|
|
endtry
|
2018-08-18 23:12:09 -04:00
|
|
|
call delete(temp)
|
|
|
|
if s:cpath(fnamemodify(bufname('$'), ':p'), temp)
|
2018-07-29 14:24:05 -04:00
|
|
|
silent execute 'bwipeout '.bufnr('$')
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2018-12-25 14:07:17 -05:00
|
|
|
function! s:QueryLog(refspec) abort
|
|
|
|
let lines = split(system(FugitivePrepare('log', '-n', '256', '--format=%h%x09%s', a:refspec, '--')), "\n")
|
|
|
|
call map(lines, 'split(v:val, "\t")')
|
|
|
|
call map(lines, '{"type": "Log", "commit": v:val[0], "subject": v:val[-1]}')
|
|
|
|
return lines
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:FormatLog(dict) abort
|
|
|
|
return a:dict.commit . ' ' . a:dict.subject
|
|
|
|
endfunction
|
|
|
|
|
2018-12-31 00:15:10 -05:00
|
|
|
function! s:FormatRebase(dict) abort
|
|
|
|
return a:dict.status . ' ' . a:dict.commit . ' ' . a:dict.subject
|
|
|
|
endfunction
|
|
|
|
|
2018-12-25 14:07:17 -05:00
|
|
|
function! s:FormatFile(dict) abort
|
|
|
|
return a:dict.status . ' ' . a:dict.filename
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Format(val) abort
|
|
|
|
if type(a:val) == type({})
|
|
|
|
return s:Format{a:val.type}(a:val)
|
|
|
|
elseif type(a:val) == type([])
|
|
|
|
return map(copy(a:val), 's:Format(v:val)')
|
|
|
|
else
|
|
|
|
return '' . a:val
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:AddHeader(key, value) abort
|
|
|
|
if empty(a:value)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
let before = 1
|
|
|
|
while !empty(getline(before))
|
|
|
|
let before += 1
|
|
|
|
endwhile
|
|
|
|
call append(before - 1, [a:key . ':' . (len(a:value) ? ' ' . a:value : '')])
|
|
|
|
if before == 1 && line('$') == 2
|
|
|
|
silent 2delete _
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:AddSection(label, lines, ...) abort
|
|
|
|
let note = a:0 ? a:1 : ''
|
|
|
|
if empty(a:lines) && empty(note)
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
call append(line('$'), ['', a:label . (len(note) ? ': ' . note : ' (' . len(a:lines) . ')')] + s:Format(a:lines))
|
|
|
|
endfunction
|
|
|
|
|
2018-07-29 14:24:05 -04:00
|
|
|
function! fugitive#BufReadStatus() abort
|
2018-07-30 01:35:11 -04:00
|
|
|
let amatch = s:Slash(expand('%:p'))
|
2018-07-29 14:24:05 -04:00
|
|
|
let b:fugitive_type = 'index'
|
|
|
|
try
|
2018-12-23 16:54:27 -05:00
|
|
|
silent doautocmd BufReadPre
|
2018-08-31 15:36:44 -04:00
|
|
|
let cmd = [fnamemodify(amatch, ':h')]
|
2018-12-25 14:07:17 -05:00
|
|
|
setlocal noro ma nomodeline buftype=nowrite
|
2018-07-29 14:24:05 -04:00
|
|
|
if s:cpath(fnamemodify($GIT_INDEX_FILE !=# '' ? $GIT_INDEX_FILE : b:git_dir . '/index', ':p')) !=# s:cpath(amatch)
|
2018-08-31 15:36:44 -04:00
|
|
|
let cmd += ['-c', 'GIT_INDEX_FILE=' . amatch]
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
2018-12-25 14:07:17 -05:00
|
|
|
let cmd += ['status', '--porcelain', '-bz']
|
|
|
|
let output = split(system(fugitive#Prepare(cmd)), "\1")
|
|
|
|
if v:shell_error
|
|
|
|
throw 'fugitive: ' . join(output, ' ')
|
|
|
|
endif
|
|
|
|
|
|
|
|
let head = matchstr(output[0], '^## \zs\S\+\ze\%($\| \[\)')
|
|
|
|
let pull = ''
|
|
|
|
if head =~# '\.\.\.'
|
|
|
|
let [head, pull] = split(head, '\.\.\.')
|
|
|
|
let branch = head
|
|
|
|
elseif head ==# 'HEAD' || empty(head)
|
|
|
|
let head = FugitiveHead(11)
|
|
|
|
let branch = ''
|
2018-07-29 14:24:05 -04:00
|
|
|
else
|
2018-12-25 14:07:17 -05:00
|
|
|
let branch = head
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
2018-12-25 14:07:17 -05:00
|
|
|
|
2018-12-27 18:05:29 -05:00
|
|
|
let [staged, unstaged] = [[], []]
|
2018-12-25 14:07:17 -05:00
|
|
|
let i = 0
|
|
|
|
while i < len(output)
|
|
|
|
let line = output[i]
|
|
|
|
let file = line[3:-1]
|
|
|
|
let files = file
|
|
|
|
let i += 1
|
|
|
|
if line[0:1] =~# '[RC]'
|
|
|
|
let files = output[i] . ' -> ' . file
|
|
|
|
let i += 1
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
2018-12-25 14:07:17 -05:00
|
|
|
if line[0] !~# '[ ?!#]'
|
|
|
|
call add(staged, {'type': 'File', 'status': line[0], 'filename': (line[0] =~# '[RC]' ? files : file)})
|
|
|
|
endif
|
2018-12-27 18:05:29 -05:00
|
|
|
if line[1] !~# '[ !#]'
|
2018-12-25 14:07:17 -05:00
|
|
|
call add(unstaged, {'type': 'File', 'status': line[1], 'filename': (line[1] =~# '[RC]' ? files : file)})
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
2018-12-25 14:07:17 -05:00
|
|
|
endwhile
|
|
|
|
|
|
|
|
let config = fugitive#Config()
|
|
|
|
|
2018-12-25 16:35:00 -05:00
|
|
|
let pull_type = 'Pull'
|
2018-12-25 14:07:17 -05:00
|
|
|
if len(pull)
|
|
|
|
let rebase = fugitive#Config('branch.' . branch . '.rebase', config)
|
|
|
|
if empty(rebase)
|
|
|
|
let rebase = fugitive#Config('pull.rebase', config)
|
|
|
|
endif
|
|
|
|
if rebase =~# '^\%(true\|yes\|on\|1\|interactive\)$'
|
|
|
|
let pull_type = 'Rebase'
|
|
|
|
elseif rebase =~# '^\%(false\|no|off\|0\|\)$'
|
|
|
|
let pull_type = 'Merge'
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
let push_remote = fugitive#Config('branch.' . branch . '.pushRemote', config)
|
|
|
|
if empty(push_remote)
|
|
|
|
let push_remote = fugitive#Config('remote.pushDefault', config)
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
2018-12-25 14:07:17 -05:00
|
|
|
let push = len(push_remote) && len(branch) ? push_remote . '/' . branch : ''
|
|
|
|
if empty(push)
|
|
|
|
let push = pull
|
|
|
|
endif
|
|
|
|
|
|
|
|
if len(pull)
|
|
|
|
let unpulled = s:QueryLog(head . '..' . pull)
|
|
|
|
else
|
|
|
|
let unpulled = []
|
|
|
|
endif
|
|
|
|
if len(push)
|
|
|
|
let unpushed = s:QueryLog(push . '..' . head)
|
|
|
|
else
|
|
|
|
let unpushed = []
|
|
|
|
endif
|
|
|
|
|
2018-12-31 00:15:10 -05:00
|
|
|
if isdirectory(fugitive#Find('.git/rebase-merge/'))
|
|
|
|
let rebasing_dir = fugitive#Find('.git/rebase-merge/')
|
|
|
|
elseif isdirectory(fugitive#Find('.git/rebase-apply/'))
|
|
|
|
let rebasing_dir = fugitive#Find('.git/rebase-apply/')
|
|
|
|
endif
|
|
|
|
|
|
|
|
let rebasing = []
|
|
|
|
let rebasing_head = 'detached HEAD'
|
|
|
|
if exists('rebasing_dir') && filereadable(rebasing_dir . 'git-rebase-todo')
|
|
|
|
let rebasing_head = substitute(readfile(rebasing_dir . 'head-name')[0], '\C^refs/heads/', '', '')
|
|
|
|
let len = 11
|
|
|
|
let lines = readfile(rebasing_dir . 'git-rebase-todo')
|
|
|
|
for line in lines
|
|
|
|
let hash = matchstr(line, '^[^a-z].*\s\zs[0-9a-f]\{4,\}\ze\.\.')
|
|
|
|
if len(hash)
|
|
|
|
let len = len(hash)
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
if getfsize(rebasing_dir . 'done') > 0
|
|
|
|
let done = readfile(rebasing_dir . 'done')
|
|
|
|
call map(done, 'substitute(v:val, ''^\l\+\>'', "done", "")')
|
|
|
|
let done[-1] = substitute(done[-1], '^\l\+\>', 'stop', '')
|
|
|
|
let lines = done + lines
|
|
|
|
endif
|
|
|
|
call reverse(lines)
|
|
|
|
for line in lines
|
|
|
|
let match = matchlist(line, '^\(\l\+\)\s\+\(\x\{4,\}\)\s\+\(.*\)')
|
|
|
|
if len(match) && match[1] !~# 'exec\|merge\|label'
|
|
|
|
call add(rebasing, {'type': 'Rebase', 'status': get(s:rebase_abbrevs, match[1], match[1]), 'commit': strpart(match[2], 0, len), 'subject': match[3]})
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
|
2019-01-03 00:19:21 -05:00
|
|
|
let b:fugitive_diff = {
|
2019-01-03 21:06:01 -05:00
|
|
|
\ 'Staged': split(system(fugitive#Prepare('diff', '--no-ext-diff', '--no-prefix', '--cached')), "\n"),
|
|
|
|
\ 'Unstaged': split(system(fugitive#Prepare('diff', '--no-ext-diff', '--no-prefix')), "\n")}
|
2019-01-03 00:19:21 -05:00
|
|
|
let expanded = get(b:, 'fugitive_expanded', {'Staged': {}, 'Unstaged': {}})
|
|
|
|
let b:fugitive_expanded = {'Staged': {}, 'Unstaged': {}}
|
|
|
|
|
2018-12-25 14:07:17 -05:00
|
|
|
silent keepjumps %delete_
|
|
|
|
|
|
|
|
call s:AddHeader('Head', head)
|
|
|
|
call s:AddHeader(pull_type, pull)
|
|
|
|
if push !=# pull
|
|
|
|
call s:AddHeader('Push', push)
|
|
|
|
endif
|
2018-12-31 00:15:10 -05:00
|
|
|
call s:AddSection('Rebasing ' . rebasing_head, rebasing)
|
2018-12-25 14:07:17 -05:00
|
|
|
call s:AddSection('Unstaged', unstaged)
|
2019-01-03 00:19:21 -05:00
|
|
|
let unstaged_end = len(unstaged) ? line('$') : 0
|
2018-12-25 14:07:17 -05:00
|
|
|
call s:AddSection('Staged', staged)
|
2019-01-03 00:19:21 -05:00
|
|
|
let staged_end = len(staged) ? line('$') : 0
|
2018-12-25 14:07:17 -05:00
|
|
|
call s:AddSection('Unpushed to ' . push, unpushed)
|
|
|
|
call s:AddSection('Unpulled from ' . pull, unpulled)
|
|
|
|
|
|
|
|
set nomodified readonly noswapfile
|
|
|
|
silent doautocmd BufReadPost
|
|
|
|
set foldtext=fugitive#Foldtext()
|
|
|
|
set filetype=fugitive
|
|
|
|
setlocal nomodifiable
|
2018-07-29 14:24:05 -04:00
|
|
|
if &bufhidden ==# ''
|
|
|
|
setlocal bufhidden=delete
|
|
|
|
endif
|
2018-12-25 19:43:35 -05:00
|
|
|
let b:dispatch = ':Gfetch --all'
|
2018-07-29 14:24:05 -04:00
|
|
|
call fugitive#MapJumps()
|
2018-08-11 02:36:53 -04:00
|
|
|
let nowait = v:version >= 704 ? '<nowait>' : ''
|
2018-07-29 14:24:05 -04:00
|
|
|
nunmap <buffer> P
|
|
|
|
nunmap <buffer> ~
|
|
|
|
nnoremap <buffer> <silent> <C-N> :<C-U>execute <SID>StageNext(v:count1)<CR>
|
|
|
|
nnoremap <buffer> <silent> <C-P> :<C-U>execute <SID>StagePrevious(v:count1)<CR>
|
2019-01-02 22:01:07 -05:00
|
|
|
exe "nnoremap <buffer> <silent>" nowait "- :<C-U>execute <SID>StageToggle(line('.'),v:count)<CR>"
|
|
|
|
exe "xnoremap <buffer> <silent>" nowait "- :<C-U>execute <SID>StageToggle(line(\"'<\"),line(\"'>\")-line(\"'<\")+1)<CR>"
|
2019-01-03 12:18:53 -05:00
|
|
|
exe "nnoremap <buffer> <silent>" nowait "s :<C-U>execute <SID>StageToggleOnly('Unstaged',line('.'),v:count)<CR>"
|
2019-01-02 22:01:07 -05:00
|
|
|
exe "xnoremap <buffer> <silent>" nowait "s :<C-U>execute <SID>StageToggle(line(\"'<\"),line(\"'>\")-line(\"'<\")+1)<CR>"
|
2019-01-03 12:18:53 -05:00
|
|
|
exe "nnoremap <buffer> <silent>" nowait "u :<C-U>execute <SID>StageToggleOnly('Staged',line('.'),v:count)<CR>"
|
2019-01-02 22:01:07 -05:00
|
|
|
exe "xnoremap <buffer> <silent>" nowait "u :<C-U>execute <SID>StageToggle(line(\"'<\"),line(\"'>\")-line(\"'<\")+1)<CR>"
|
2018-07-29 14:24:05 -04:00
|
|
|
nnoremap <buffer> <silent> C :<C-U>Gcommit<CR>:echohl WarningMsg<Bar>echo ':Gstatus C is deprecated in favor of cc'<Bar>echohl NONE<CR>
|
|
|
|
nnoremap <buffer> <silent> ca :<C-U>Gcommit --amend<CR>
|
|
|
|
nnoremap <buffer> <silent> cc :<C-U>Gcommit<CR>
|
|
|
|
nnoremap <buffer> <silent> ce :<C-U>Gcommit --amend --no-edit<CR>
|
|
|
|
nnoremap <buffer> <silent> cw :<C-U>Gcommit --amend --only<CR>
|
|
|
|
nnoremap <buffer> <silent> cva :<C-U>Gcommit -v --amend<CR>
|
|
|
|
nnoremap <buffer> <silent> cvc :<C-U>Gcommit -v<CR>
|
2019-01-03 00:19:21 -05:00
|
|
|
nnoremap <buffer> <silent> a :<C-U>execute <SID>StageInline('toggle',line('.'),v:count)<CR>
|
|
|
|
nnoremap <buffer> <silent> i :<C-U>execute <SID>StageInline('toggle',line('.'),v:count)<CR>
|
|
|
|
exe 'nnoremap <buffer> <silent>' nowait "= :<C-U>execute <SID>StageInline('toggle',line('.'),v:count)<CR>"
|
|
|
|
exe 'nnoremap <buffer> <silent>' nowait "< :<C-U>execute <SID>StageInline('show', line('.'),v:count)<CR>"
|
|
|
|
exe 'nnoremap <buffer> <silent>' nowait "> :<C-U>execute <SID>StageInline('hide', line('.'),v:count)<CR>"
|
|
|
|
exe 'xnoremap <buffer> <silent>' nowait "= :<C-U>execute <SID>StageInline('toggle',line(\"'<\"),line(\"'>\")-line(\"'<\")+1)<CR>"
|
|
|
|
exe 'xnoremap <buffer> <silent>' nowait "< :<C-U>execute <SID>StageInline('show', line(\"'<\"),line(\"'>\")-line(\"'<\")+1)<CR>"
|
|
|
|
exe 'xnoremap <buffer> <silent>' nowait "> :<C-U>execute <SID>StageInline('hide', line(\"'<\"),line(\"'>\")-line(\"'<\")+1)<CR>"
|
2018-07-29 14:24:05 -04:00
|
|
|
nnoremap <buffer> <silent> D :<C-U>execute <SID>StageDiff('Gdiff')<CR>
|
|
|
|
nnoremap <buffer> <silent> dd :<C-U>execute <SID>StageDiff('Gdiff')<CR>
|
|
|
|
nnoremap <buffer> <silent> dh :<C-U>execute <SID>StageDiff('Gsdiff')<CR>
|
|
|
|
nnoremap <buffer> <silent> ds :<C-U>execute <SID>StageDiff('Gsdiff')<CR>
|
|
|
|
nnoremap <buffer> <silent> dp :<C-U>execute <SID>StageDiffEdit()<CR>
|
|
|
|
nnoremap <buffer> <silent> dv :<C-U>execute <SID>StageDiff('Gvdiff')<CR>
|
|
|
|
nnoremap <buffer> <silent> P :<C-U>execute <SID>StagePatch(line('.'),line('.')+v:count1-1)<CR>
|
|
|
|
xnoremap <buffer> <silent> P :<C-U>execute <SID>StagePatch(line("'<"),line("'>"))<CR>
|
|
|
|
nnoremap <buffer> <silent> q :<C-U>if bufnr('$') == 1<Bar>quit<Bar>else<Bar>bdelete<Bar>endif<CR>
|
2019-01-02 00:42:22 -05:00
|
|
|
nnoremap <buffer> <silent> r :<C-U>exe <SID>ReloadStatus()<CR>
|
|
|
|
nnoremap <buffer> <silent> R :<C-U>exe <SID>ReloadStatus()<CR>
|
2019-01-02 23:49:12 -05:00
|
|
|
nnoremap <buffer> <silent> U :<C-U>echoerr 'Changed to X'<CR>
|
|
|
|
nnoremap <buffer> <silent> g<Bar> :<C-U>execute <SID>StageDelete(line('.'),v:count)<CR>
|
|
|
|
xnoremap <buffer> <silent> g<Bar> :<C-U>execute <SID>StageDelete(line("'<"),line("'>")-line("'<")+1)<CR>
|
|
|
|
nnoremap <buffer> <silent> X :<C-U>execute <SID>StageDelete(line('.'),v:count)<CR>
|
|
|
|
xnoremap <buffer> <silent> X :<C-U>execute <SID>StageDelete(line("'<"),line("'>")-line("'<")+1)<CR>
|
2019-01-03 00:19:21 -05:00
|
|
|
nnoremap <buffer> . : <C-R>=<SID>fnameescape(get(<SID>StatusCfile(),0,''))<CR><Home>
|
2019-01-03 00:23:02 -05:00
|
|
|
nnoremap <buffer> <silent> q :<C-U>bdelete<CR>
|
2018-07-29 14:24:05 -04:00
|
|
|
nnoremap <buffer> <silent> g? :help fugitive-:Gstatus<CR>
|
|
|
|
nnoremap <buffer> <silent> <F1> :help fugitive-:Gstatus<CR>
|
2019-01-03 00:19:21 -05:00
|
|
|
|
|
|
|
for [lnum, section] in [[staged_end, 'Staged'], [unstaged_end, 'Unstaged']]
|
|
|
|
while len(getline(lnum))
|
|
|
|
let filename = matchstr(getline(lnum), '^[A-Z?] \zs.*')
|
|
|
|
if has_key(expanded[section], filename)
|
|
|
|
call s:StageInline('show', lnum)
|
|
|
|
endif
|
|
|
|
let lnum -= 1
|
|
|
|
endwhile
|
|
|
|
endfor
|
|
|
|
|
2018-12-24 11:35:03 -05:00
|
|
|
return ''
|
2018-07-29 14:24:05 -04:00
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#FileReadCmd(...) abort
|
|
|
|
let amatch = a:0 ? a:1 : expand('<amatch>')
|
|
|
|
let [dir, rev] = s:DirRev(amatch)
|
|
|
|
let line = a:0 > 1 ? a:2 : line("'[")
|
|
|
|
if empty(dir)
|
|
|
|
return 'noautocmd ' . line . 'read ' . s:fnameescape(amatch)
|
|
|
|
endif
|
|
|
|
if rev !~# ':'
|
2018-08-19 20:52:29 -04:00
|
|
|
let cmd = s:Prepare(dir, 'log', '--pretty=format:%B', '-1', rev, '--')
|
2018-07-29 14:24:05 -04:00
|
|
|
else
|
2018-09-12 12:06:19 -04:00
|
|
|
let cmd = s:Prepare(dir, 'cat-file', '-p', rev)
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
|
|
|
return line . 'read !' . escape(cmd, '!#%')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#FileWriteCmd(...) abort
|
|
|
|
let tmp = tempname()
|
|
|
|
let amatch = a:0 ? a:1 : expand('<amatch>')
|
|
|
|
let autype = a:0 > 1 ? 'Buf' : 'File'
|
|
|
|
if exists('#' . autype . 'WritePre')
|
|
|
|
execute 'doautocmd ' . autype . 'WritePre ' . s:fnameescape(amatch)
|
|
|
|
endif
|
|
|
|
try
|
|
|
|
let [dir, commit, file] = s:DirCommitFile(amatch)
|
|
|
|
if commit !~# '^[0-3]$' || !v:cmdbang && (line("'[") != 1 || line("']") != line('$'))
|
|
|
|
return "noautocmd '[,']write" . (v:cmdbang ? '!' : '') . ' ' . s:fnameescape(amatch)
|
|
|
|
endif
|
2018-08-19 20:52:29 -04:00
|
|
|
silent execute "'[,']write !".s:Prepare(dir, 'hash-object', '-w', '--stdin', '--').' > '.tmp
|
2018-07-29 14:24:05 -04:00
|
|
|
let sha1 = readfile(tmp)[0]
|
2018-08-31 15:36:44 -04:00
|
|
|
let old_mode = matchstr(system(s:Prepare(dir, 'ls-files', '--stage', '.' . file)), '^\d\+')
|
2018-08-19 20:52:29 -04:00
|
|
|
if empty(old_mode)
|
2018-07-29 14:24:05 -04:00
|
|
|
let old_mode = executable(s:Tree(dir) . file) ? '100755' : '100644'
|
|
|
|
endif
|
|
|
|
let info = old_mode.' '.sha1.' '.commit."\t".file[1:-1]
|
2018-08-19 23:26:19 -04:00
|
|
|
let error = system(s:Prepare(dir, 'update-index', '--index-info'), info . "\n")
|
2018-07-29 14:24:05 -04:00
|
|
|
if v:shell_error == 0
|
|
|
|
setlocal nomodified
|
|
|
|
if exists('#' . autype . 'WritePost')
|
|
|
|
execute 'doautocmd ' . autype . 'WritePost ' . s:fnameescape(amatch)
|
|
|
|
endif
|
|
|
|
call fugitive#ReloadStatus()
|
|
|
|
return ''
|
|
|
|
else
|
|
|
|
return 'echoerr '.string('fugitive: '.error)
|
|
|
|
endif
|
|
|
|
finally
|
|
|
|
call delete(tmp)
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#BufReadCmd(...) abort
|
|
|
|
let amatch = a:0 ? a:1 : expand('<amatch>')
|
|
|
|
try
|
|
|
|
let [dir, rev] = s:DirRev(amatch)
|
|
|
|
if empty(dir)
|
|
|
|
return 'echo "Invalid Fugitive URL"'
|
|
|
|
endif
|
2018-07-29 14:22:33 -04:00
|
|
|
if rev =~# '^:\d$'
|
|
|
|
let b:fugitive_type = 'stage'
|
|
|
|
else
|
2018-09-12 12:06:19 -04:00
|
|
|
let b:fugitive_type = system(s:Prepare(dir, 'cat-file', '-t', rev))[0:-2]
|
2018-07-29 14:22:33 -04:00
|
|
|
if v:shell_error && rev =~# '^:0'
|
|
|
|
let sha = system(s:Prepare(dir, 'write-tree', '--prefix=' . rev[3:-1]))[0:-2]
|
|
|
|
let b:fugitive_type = 'tree'
|
|
|
|
endif
|
|
|
|
if v:shell_error
|
2018-09-15 16:47:20 -04:00
|
|
|
let error = b:fugitive_type
|
2018-07-29 14:22:33 -04:00
|
|
|
unlet b:fugitive_type
|
|
|
|
if rev =~# '^:\d:'
|
|
|
|
let &readonly = !filewritable(dir . '/index')
|
2018-12-23 16:54:27 -05:00
|
|
|
return 'silent doautocmd BufNewFile'
|
2018-07-29 14:22:33 -04:00
|
|
|
else
|
|
|
|
setlocal readonly nomodifiable
|
2018-09-15 16:47:20 -04:00
|
|
|
return 'echo ' . string(error)
|
2018-07-29 14:22:33 -04:00
|
|
|
endif
|
|
|
|
elseif b:fugitive_type !~# '^\%(tag\|commit\|tree\|blob\)$'
|
|
|
|
return "echoerr ".string("fugitive: unrecognized git type '".b:fugitive_type."'")
|
|
|
|
endif
|
|
|
|
if !exists('b:fugitive_display_format') && b:fugitive_type != 'blob'
|
|
|
|
let b:fugitive_display_format = +getbufvar('#','fugitive_display_format')
|
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if b:fugitive_type !=# 'blob'
|
|
|
|
setlocal nomodeline
|
|
|
|
endif
|
|
|
|
|
|
|
|
setlocal noreadonly modifiable
|
|
|
|
let pos = getpos('.')
|
|
|
|
silent keepjumps %delete_
|
|
|
|
setlocal endofline
|
|
|
|
|
|
|
|
try
|
2018-12-23 16:54:27 -05:00
|
|
|
silent doautocmd BufReadPre
|
2018-07-29 14:24:05 -04:00
|
|
|
if b:fugitive_type ==# 'tree'
|
|
|
|
let b:fugitive_display_format = b:fugitive_display_format % 2
|
|
|
|
if b:fugitive_display_format
|
2018-07-29 14:22:33 -04:00
|
|
|
call s:ReplaceCmd([dir, 'ls-tree', exists('sha') ? sha : rev])
|
2018-07-29 14:24:05 -04:00
|
|
|
else
|
2018-07-29 14:22:33 -04:00
|
|
|
if !exists('sha')
|
2018-08-31 15:36:44 -04:00
|
|
|
let sha = system(s:Prepare(dir, 'rev-parse', '--verify', rev, '--'))[0:-2]
|
2018-07-29 14:22:33 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
call s:ReplaceCmd([dir, 'show', '--no-color', sha])
|
|
|
|
endif
|
|
|
|
elseif b:fugitive_type ==# 'tag'
|
|
|
|
let b:fugitive_display_format = b:fugitive_display_format % 2
|
|
|
|
if b:fugitive_display_format
|
|
|
|
call s:ReplaceCmd([dir, 'cat-file', b:fugitive_type, rev])
|
|
|
|
else
|
|
|
|
call s:ReplaceCmd([dir, 'cat-file', '-p', rev])
|
|
|
|
endif
|
|
|
|
elseif b:fugitive_type ==# 'commit'
|
|
|
|
let b:fugitive_display_format = b:fugitive_display_format % 2
|
|
|
|
if b:fugitive_display_format
|
|
|
|
call s:ReplaceCmd([dir, 'cat-file', b:fugitive_type, rev])
|
|
|
|
else
|
|
|
|
call s:ReplaceCmd([dir, 'show', '--no-color', '--pretty=format:tree%x20%T%nparent%x20%P%nauthor%x20%an%x20<%ae>%x20%ad%ncommitter%x20%cn%x20<%ce>%x20%cd%nencoding%x20%e%n%n%s%n%n%b', rev])
|
|
|
|
keepjumps call search('^parent ')
|
|
|
|
if getline('.') ==# 'parent '
|
|
|
|
silent keepjumps delete_
|
|
|
|
else
|
2018-09-14 12:45:22 -04:00
|
|
|
silent exe (exists(':keeppatterns') ? 'keeppatterns' : '') 'keepjumps s/\m\C\%(^parent\)\@<! /\rparent /e' . (&gdefault ? '' : 'g')
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
|
|
|
keepjumps let lnum = search('^encoding \%(<unknown>\)\=$','W',line('.')+3)
|
|
|
|
if lnum
|
|
|
|
silent keepjumps delete_
|
|
|
|
end
|
2018-10-28 19:48:15 -04:00
|
|
|
silent exe (exists(':keeppatterns') ? 'keeppatterns' : '') 'keepjumps 1,/^diff --git\|\%$/s/\r$//e'
|
2018-07-29 14:24:05 -04:00
|
|
|
keepjumps 1
|
|
|
|
endif
|
2018-07-29 14:22:33 -04:00
|
|
|
elseif b:fugitive_type ==# 'stage'
|
|
|
|
call s:ReplaceCmd([dir, 'ls-files', '--stage'])
|
2018-07-29 14:24:05 -04:00
|
|
|
elseif b:fugitive_type ==# 'blob'
|
|
|
|
call s:ReplaceCmd([dir, 'cat-file', b:fugitive_type, rev])
|
|
|
|
endif
|
|
|
|
finally
|
|
|
|
keepjumps call setpos('.',pos)
|
|
|
|
setlocal nomodified noswapfile
|
2018-12-23 16:54:27 -05:00
|
|
|
let modifiable = rev =~# '^:.:' && b:fugitive_type !=# 'tree'
|
|
|
|
let &readonly = !modifiable || !filewritable(dir . '/index')
|
2018-07-29 14:24:05 -04:00
|
|
|
if &bufhidden ==# ''
|
|
|
|
setlocal bufhidden=delete
|
|
|
|
endif
|
2019-01-06 01:57:33 -05:00
|
|
|
let &l:modifiable = modifiable
|
2018-07-29 14:24:05 -04:00
|
|
|
if b:fugitive_type !=# 'blob'
|
|
|
|
setlocal filetype=git foldmethod=syntax
|
|
|
|
nnoremap <buffer> <silent> a :<C-U>let b:fugitive_display_format += v:count1<Bar>exe fugitive#BufReadCmd(@%)<CR>
|
|
|
|
nnoremap <buffer> <silent> i :<C-U>let b:fugitive_display_format -= v:count1<Bar>exe fugitive#BufReadCmd(@%)<CR>
|
|
|
|
else
|
|
|
|
call fugitive#MapJumps()
|
|
|
|
endif
|
|
|
|
endtry
|
|
|
|
|
2019-01-05 01:43:59 -05:00
|
|
|
setlocal modifiable
|
2018-12-23 16:54:27 -05:00
|
|
|
return 'silent doautocmd' . (v:version >= 704 ? ' <nomodeline>' : '') .
|
|
|
|
\ ' BufReadPost' . (modifiable ? '' : '|setl nomodifiable')
|
2018-07-29 14:24:05 -04:00
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#BufWriteCmd(...) abort
|
|
|
|
return fugitive#FileWriteCmd(a:0 ? a:1 : expand('<amatch>'), 1)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#SourceCmd(...) abort
|
|
|
|
let amatch = a:0 ? a:1 : expand('<amatch>')
|
|
|
|
let temp = s:BlobTemp(amatch)
|
|
|
|
if empty(temp)
|
|
|
|
return 'noautocmd source ' . s:fnameescape(amatch)
|
|
|
|
endif
|
|
|
|
if !exists('g:virtual_scriptnames')
|
|
|
|
let g:virtual_scriptnames = {}
|
|
|
|
endif
|
|
|
|
let g:virtual_scriptnames[temp] = amatch
|
|
|
|
return 'source ' . s:fnameescape(temp)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Section: Temp files
|
|
|
|
|
|
|
|
if !exists('s:temp_files')
|
|
|
|
let s:temp_files = {}
|
|
|
|
endif
|
|
|
|
|
2018-08-03 22:50:32 -04:00
|
|
|
function! s:SetupTemp(file) abort
|
|
|
|
if has_key(s:temp_files, s:cpath(a:file))
|
|
|
|
let dict = s:temp_files[s:cpath(a:file)]
|
|
|
|
let b:git_dir = dict.dir
|
|
|
|
call extend(b:, {'fugitive_type': 'temp'}, 'keep')
|
|
|
|
if has_key(dict, 'filetype') && dict.filetype !=# &l:filetype
|
|
|
|
let &l:filetype = dict.filetype
|
|
|
|
endif
|
|
|
|
setlocal foldmarker=<<<<<<<,>>>>>>>
|
|
|
|
setlocal bufhidden=delete nobuflisted
|
|
|
|
setlocal buftype=nowrite
|
|
|
|
nnoremap <buffer> <silent> q :<C-U>bdelete<CR>
|
|
|
|
if getline(1) !~# '^diff '
|
|
|
|
setlocal nomodifiable
|
|
|
|
endif
|
|
|
|
call FugitiveDetect(a:file)
|
2019-01-03 13:46:16 -05:00
|
|
|
if &filetype ==# 'git'
|
|
|
|
call fugitive#MapJumps()
|
|
|
|
endif
|
2018-08-03 22:50:32 -04:00
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
2018-07-29 14:24:05 -04:00
|
|
|
augroup fugitive_temp
|
|
|
|
autocmd!
|
2018-08-03 22:50:32 -04:00
|
|
|
autocmd BufNewFile,BufReadPost * exe s:SetupTemp(expand('<amatch>:p'))
|
2018-07-29 14:24:05 -04:00
|
|
|
augroup END
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Git
|
2018-07-29 14:24:05 -04:00
|
|
|
|
|
|
|
call s:command("-bang -nargs=? -complete=customlist,s:GitComplete Git :execute s:Git(<bang>0,'<mods>',<q-args>)")
|
|
|
|
|
|
|
|
function! s:Git(bang, mods, args) abort
|
|
|
|
if a:bang
|
|
|
|
return s:Edit('edit', 1, a:mods, a:args)
|
|
|
|
endif
|
|
|
|
let git = s:UserCommand()
|
|
|
|
if has('gui_running') && !has('win32')
|
|
|
|
let git .= ' --no-pager'
|
|
|
|
endif
|
|
|
|
let args = matchstr(a:args,'\v\C.{-}%($|\\@<!%(\\\\)*\|)@=')
|
|
|
|
let after = matchstr(a:args, '\v\C\\@<!%(\\\\)*\zs\|.*')
|
|
|
|
let tree = s:Tree()
|
|
|
|
if has('win32')
|
|
|
|
let after = '|call fugitive#ReloadStatus()' . after
|
|
|
|
endif
|
|
|
|
if exists(':terminal') && has('nvim') && !get(g:, 'fugitive_force_bang_command')
|
|
|
|
if len(@%)
|
|
|
|
-tabedit %
|
|
|
|
else
|
|
|
|
-tabnew
|
|
|
|
endif
|
|
|
|
execute 'lcd' fnameescape(tree)
|
2018-08-04 19:17:06 -04:00
|
|
|
let exec = escape(git . ' ' . s:ShellExpand(args), '#%')
|
2018-07-31 19:44:03 -04:00
|
|
|
return 'exe ' . string('terminal ' . exec) . after
|
2018-07-29 14:24:05 -04:00
|
|
|
else
|
2018-08-03 22:50:32 -04:00
|
|
|
let cmd = "exe '!'.escape(" . string(git) . " . ' ' . s:ShellExpand(" . string(args) . "),'!#%')"
|
2018-07-29 14:24:05 -04:00
|
|
|
if s:cpath(tree) !=# s:cpath(getcwd())
|
2018-12-16 22:13:12 -05:00
|
|
|
let cd = s:Cd()
|
2018-07-29 14:24:05 -04:00
|
|
|
let cmd = 'try|' . cd . ' ' . tree . '|' . cmd . '|finally|' . cd . ' ' . s:fnameescape(getcwd()) . '|endtry'
|
|
|
|
endif
|
|
|
|
return cmd . after
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let s:exec_paths = {}
|
|
|
|
function! s:Subcommands() abort
|
|
|
|
if !has_key(s:exec_paths, g:fugitive_git_executable)
|
|
|
|
let s:exec_paths[g:fugitive_git_executable] = s:sub(system(g:fugitive_git_executable.' --exec-path'),'\n$','')
|
|
|
|
endif
|
|
|
|
let exec_path = s:exec_paths[g:fugitive_git_executable]
|
|
|
|
return map(split(glob(exec_path.'/git-*'),"\n"),'s:sub(v:val[strlen(exec_path)+5 : -1],"\\.exe$","")')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let s:aliases = {}
|
|
|
|
function! s:Aliases() abort
|
|
|
|
if !has_key(s:aliases, b:git_dir)
|
|
|
|
let s:aliases[b:git_dir] = {}
|
|
|
|
let lines = split(s:TreeChomp('config','-z','--get-regexp','^alias[.]'),"\1")
|
|
|
|
for line in v:shell_error ? [] : lines
|
|
|
|
let s:aliases[b:git_dir][matchstr(line, '\.\zs.\{-}\ze\n')] = matchstr(line, '\n\zs.*')
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
return s:aliases[b:git_dir]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:GitComplete(A, L, P) abort
|
|
|
|
let pre = strpart(a:L, 0, a:P)
|
|
|
|
if pre !~# ' [[:alnum:]-]\+ '
|
|
|
|
let cmds = s:Subcommands()
|
|
|
|
return filter(sort(cmds+keys(s:Aliases())), 'strpart(v:val, 0, strlen(a:A)) ==# a:A')
|
|
|
|
elseif pre =~# ' -- '
|
2018-08-11 00:52:48 -04:00
|
|
|
return fugitive#PathComplete(a:A, b:git_dir)
|
2018-07-29 14:24:05 -04:00
|
|
|
else
|
2018-08-11 00:52:48 -04:00
|
|
|
return fugitive#Complete(a:A, b:git_dir)
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gcd, :Glcd
|
2018-07-29 14:24:05 -04:00
|
|
|
|
|
|
|
function! s:DirComplete(A, L, P) abort
|
2018-08-10 22:01:43 -04:00
|
|
|
return filter(fugitive#PathComplete(a:A), 'v:val =~# "/$"')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:DirArg(path) abort
|
|
|
|
let path = substitute(a:path, '^:/:\=\|^:(\%(top\|top,literal\|literal,top\|literal\))', '', '')
|
2018-08-15 19:24:35 -04:00
|
|
|
if path =~# '^/\|^\a\+:\|^\.\.\=\%(/\|$\)'
|
2018-08-10 22:01:43 -04:00
|
|
|
return path
|
|
|
|
else
|
|
|
|
return (empty(s:Tree()) ? b:git_dir : s:Tree()) . '/' . path
|
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-10 22:01:43 -04:00
|
|
|
call s:command("-bar -bang -nargs=? -complete=customlist,s:DirComplete Gcd :exe 'cd<bang>' s:fnameescape(s:DirArg(<q-args>))")
|
|
|
|
call s:command("-bar -bang -nargs=? -complete=customlist,s:DirComplete Glcd :exe 'lcd<bang>' s:fnameescape(s:DirArg(<q-args>))")
|
2018-07-29 14:24:05 -04:00
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gstatus
|
2018-07-29 14:24:05 -04:00
|
|
|
|
|
|
|
call s:command("-bar -bang -range=-1 Gstatus :execute s:Status(<bang>0, <count>, '<mods>')")
|
2019-01-01 13:51:41 -05:00
|
|
|
call s:command("-bar -bang -range=-1 G :execute s:Status(<bang>0, <count>, '<mods>')")
|
2018-07-29 14:24:05 -04:00
|
|
|
augroup fugitive_status
|
|
|
|
autocmd!
|
|
|
|
if !has('win32')
|
|
|
|
autocmd FocusGained,ShellCmdPost * call fugitive#ReloadStatus()
|
2018-12-26 15:47:53 -05:00
|
|
|
autocmd QuickFixCmdPost c*file call fugitive#ReloadStatus()
|
2018-07-29 14:24:05 -04:00
|
|
|
autocmd BufDelete term://* call fugitive#ReloadStatus()
|
|
|
|
endif
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
function! s:Status(bang, count, mods) abort
|
|
|
|
try
|
2019-01-03 00:23:02 -05:00
|
|
|
let dir = b:git_dir
|
|
|
|
let mods = a:mods ==# '<mods>' || empty(a:mods) ? 'leftabove' : a:mods
|
|
|
|
let file = fugitive#Find(':')
|
|
|
|
for winnr in range(1, winnr('$'))
|
|
|
|
if s:cpath(file, fnamemodify(bufname(winbufnr(winnr)), ':p'))
|
|
|
|
exe winnr . 'wincmd w'
|
|
|
|
let w:fugitive_status = dir
|
|
|
|
return s:ReloadStatus()
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
let wide = winwidth(0) >= 160
|
|
|
|
if a:count ==# 0
|
|
|
|
exe mods 'Gedit :'
|
|
|
|
elseif a:bang
|
|
|
|
exe mods (a:count ==# -1 && wide ? 'vert' : '') 'Gpedit :'
|
|
|
|
wincmd P
|
|
|
|
elseif a:count ==# -1 && wide
|
|
|
|
exe mods 'Gvsplit :'
|
|
|
|
else
|
|
|
|
exe mods a:count > 0 ? a:count : '' 'Gsplit :'
|
|
|
|
endif
|
|
|
|
let w:fugitive_status = dir
|
|
|
|
setlocal foldmethod=syntax foldlevel=1
|
2018-07-29 14:24:05 -04:00
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
2019-01-03 00:19:21 -05:00
|
|
|
function! s:StageSeek(info, fallback) abort
|
|
|
|
let info = a:info
|
|
|
|
if empty(info.section)
|
|
|
|
return a:fallback
|
|
|
|
endif
|
|
|
|
let line = search('^' . info.section, 'wn')
|
|
|
|
if !line
|
|
|
|
for section in get({'Staged': ['Unstaged'], 'Unstaged': ['Staged']}, info.section, [])
|
|
|
|
let line = search('^' . section, 'wn')
|
|
|
|
if line
|
|
|
|
return line + (info.index > 0 ? 1 : 0)
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
return 1
|
|
|
|
endif
|
|
|
|
let i = 0
|
|
|
|
while len(getline(line))
|
|
|
|
let filename = matchstr(getline(line), '^[A-Z?] \zs.*')
|
|
|
|
if len(filename) &&
|
|
|
|
\ ((info.filename[-1:-1] ==# '/' && filename[0 : len(info.filename) - 1] ==# info.filename) ||
|
|
|
|
\ (filename[-1:-1] ==# '/' && filename ==# info.filename[0 : len(filename) - 1]) ||
|
|
|
|
\ filename ==# info.filename)
|
|
|
|
if info.offset < 0
|
|
|
|
return line
|
|
|
|
else
|
|
|
|
if getline(line+1) !~# '^@'
|
|
|
|
exe s:StageInline('show', line)
|
|
|
|
endif
|
|
|
|
if getline(line+1) !~# '^@'
|
|
|
|
return line
|
|
|
|
endif
|
|
|
|
let type = info.sigil ==# '-' ? '-' : '+'
|
|
|
|
let offset = -1
|
|
|
|
while offset < info.offset
|
|
|
|
let line += 1
|
|
|
|
if getline(line) =~# '^@'
|
|
|
|
let offset = +matchstr(getline(line), type . '\zs\d\+') - 1
|
|
|
|
elseif getline(line) =~# '^[ ' . type . ']'
|
|
|
|
let offset += 1
|
2019-01-03 18:06:26 -05:00
|
|
|
elseif getline(line) !~# '^[ @\+-]'
|
2019-01-03 00:19:21 -05:00
|
|
|
return line - 1
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
return line
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
let commit = matchstr(getline(line), '^\%(\%(\x\x\x\)\@!\l\+\s\+\)\=\zs[0-9a-f]\+')
|
|
|
|
if len(commit) && commit ==# info.commit
|
|
|
|
return line
|
|
|
|
endif
|
|
|
|
if i ==# info.index
|
|
|
|
let backup = line
|
|
|
|
endif
|
2019-01-03 18:06:26 -05:00
|
|
|
let i += getline(line) !~# '^[ @\+-]'
|
2019-01-03 00:19:21 -05:00
|
|
|
let line += 1
|
|
|
|
endwhile
|
|
|
|
return exists('backup') ? backup : line - 1
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:ReloadStatus(...) abort
|
|
|
|
let original_lnum = a:0 ? a:1 : line('.')
|
|
|
|
let info = s:StageInfo(original_lnum)
|
2019-01-02 00:42:22 -05:00
|
|
|
call fugitive#BufReadStatus()
|
2019-01-03 00:19:21 -05:00
|
|
|
exe s:StageSeek(info, original_lnum)
|
|
|
|
normal! 0
|
2019-01-02 00:42:22 -05:00
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
2018-12-25 14:07:17 -05:00
|
|
|
function! fugitive#ReloadStatus(...) abort
|
2018-06-01 13:46:22 -04:00
|
|
|
if exists('s:reloading_status')
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
try
|
|
|
|
let s:reloading_status = 1
|
|
|
|
let mytab = tabpagenr()
|
|
|
|
for tab in [mytab] + range(1,tabpagenr('$'))
|
|
|
|
for winnr in range(1,tabpagewinnr(tab,'$'))
|
|
|
|
if getbufvar(tabpagebuflist(tab)[winnr-1],'fugitive_type') ==# 'index'
|
|
|
|
execute 'tabnext '.tab
|
|
|
|
if winnr != winnr()
|
|
|
|
execute winnr.'wincmd w'
|
|
|
|
let restorewinnr = 1
|
|
|
|
endif
|
|
|
|
try
|
|
|
|
if !&modified
|
2019-01-02 00:42:22 -05:00
|
|
|
exe s:ReloadStatus()
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
finally
|
|
|
|
if exists('restorewinnr')
|
2018-12-31 00:58:38 -05:00
|
|
|
unlet restorewinnr
|
2018-06-01 13:46:22 -04:00
|
|
|
wincmd p
|
|
|
|
endif
|
|
|
|
execute 'tabnext '.mytab
|
|
|
|
endtry
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
finally
|
|
|
|
unlet! s:reloading_status
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2018-12-25 14:07:17 -05:00
|
|
|
function! s:StageInfo(...) abort
|
|
|
|
let lnum = a:0 ? a:1 : line('.')
|
2019-01-03 18:06:26 -05:00
|
|
|
let sigil = matchstr(getline('.'), '^[ @\+-]')
|
2019-01-03 00:19:21 -05:00
|
|
|
let offset = -1
|
2019-01-03 18:06:26 -05:00
|
|
|
if getline(lnum) =~# '^[ @\+-]'
|
2019-01-03 00:19:21 -05:00
|
|
|
let type = sigil ==# '-' ? '-' : '+'
|
|
|
|
while lnum > 0 && getline(lnum) !~# '^@'
|
|
|
|
if getline(lnum) =~# '^[ '.type.']'
|
|
|
|
let offset += 1
|
|
|
|
endif
|
|
|
|
let lnum -= 1
|
|
|
|
endwhile
|
|
|
|
let offset += matchstr(getline(lnum), type.'\zs\d\+')
|
2019-01-03 18:06:26 -05:00
|
|
|
while getline(lnum) =~# '^[ @\+-]'
|
2019-01-03 00:19:21 -05:00
|
|
|
let lnum -= 1
|
|
|
|
endwhile
|
|
|
|
endif
|
2018-12-27 17:34:51 -05:00
|
|
|
let slnum = lnum + 1
|
2018-12-25 14:07:17 -05:00
|
|
|
let section = ''
|
2019-01-03 00:19:21 -05:00
|
|
|
let index = 0
|
2018-12-25 14:07:17 -05:00
|
|
|
while len(getline(slnum - 1)) && empty(section)
|
|
|
|
let slnum -= 1
|
|
|
|
let section = matchstr(getline(slnum), '^\u\l\+\ze.* (\d\+)$')
|
2019-01-03 18:06:26 -05:00
|
|
|
if empty(section) && getline(slnum) !~# '^[ @\+-]'
|
2019-01-03 00:19:21 -05:00
|
|
|
let index += 1
|
|
|
|
endif
|
2018-12-25 14:07:17 -05:00
|
|
|
endwhile
|
|
|
|
return {'section': section,
|
|
|
|
\ 'heading': getline(slnum),
|
2019-01-03 00:19:21 -05:00
|
|
|
\ 'sigil': sigil,
|
|
|
|
\ 'offset': offset,
|
2018-12-25 14:07:17 -05:00
|
|
|
\ 'filename': matchstr(getline(lnum), '^[A-Z?] \zs.*'),
|
2018-12-31 00:15:10 -05:00
|
|
|
\ 'commit': matchstr(getline(lnum), '^\%(\%(\x\x\x\)\@!\l\+\s\+\)\=\zs[0-9a-f]\{4,\}\ze '),
|
|
|
|
\ 'status': matchstr(getline(lnum), '^[A-Z?]\ze \|^\%(\x\x\x\)\@!\l\+\ze [0-9a-f]'),
|
2019-01-03 00:19:21 -05:00
|
|
|
\ 'index': index}
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-01-03 16:33:44 -05:00
|
|
|
function! s:StageReveal(...) abort
|
|
|
|
let begin = a:0 ? a:1 : line('.')
|
|
|
|
if getline(begin) =~# '^@'
|
|
|
|
let end = line(begin) + 1
|
|
|
|
while getline(end) =~# '^[ \+-]'
|
|
|
|
let end += 1
|
|
|
|
endwhile
|
|
|
|
while end > line('w$') && line('.') > line('w0') + &scrolloff
|
|
|
|
execute "normal! \<C-E>"
|
|
|
|
endwhile
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-06-01 13:46:22 -04:00
|
|
|
function! s:StageNext(count) abort
|
|
|
|
for i in range(a:count)
|
2019-01-03 00:19:21 -05:00
|
|
|
call search('^[A-Z?] .\|^[0-9a-f]\{4,\} \|^@','W')
|
2018-06-01 13:46:22 -04:00
|
|
|
endfor
|
2019-01-03 16:33:44 -05:00
|
|
|
call s:StageReveal()
|
2018-06-01 13:46:22 -04:00
|
|
|
return '.'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:StagePrevious(count) abort
|
|
|
|
if line('.') == 1 && exists(':CtrlP') && get(g:, 'ctrl_p_map') =~? '^<c-p>$'
|
2018-07-27 00:56:21 -04:00
|
|
|
return 'CtrlP '.fnameescape(s:Tree())
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
|
|
|
for i in range(a:count)
|
2019-01-03 00:19:21 -05:00
|
|
|
call search('^[A-Z?] .\|^[0-9a-f]\{4,\} \|^@','Wbe')
|
2018-06-01 13:46:22 -04:00
|
|
|
endfor
|
2019-01-03 16:33:44 -05:00
|
|
|
call s:StageReveal()
|
2018-06-01 13:46:22 -04:00
|
|
|
return '.'
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:StageReloadSeek(target,lnum1,lnum2) abort
|
2019-01-03 00:19:21 -05:00
|
|
|
exe s:ReloadStatus(a:lnum1)
|
|
|
|
return ''
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-01-03 00:19:21 -05:00
|
|
|
function! s:StageInline(mode, ...) abort
|
|
|
|
let lnum1 = a:0 ? a:1 : line('.')
|
|
|
|
let lnum = lnum1 + 1
|
|
|
|
if a:0 > 1 && a:2 == 0
|
|
|
|
let info = s:StageInfo(lnum - 1)
|
|
|
|
if empty(info.filename) && len(info.section)
|
|
|
|
while len(getline(lnum))
|
|
|
|
let lnum += 1
|
|
|
|
endwhile
|
|
|
|
endif
|
|
|
|
elseif a:0 > 1
|
|
|
|
let lnum += a:2 - 1
|
|
|
|
endif
|
|
|
|
while lnum > lnum1
|
|
|
|
let lnum -= 1
|
2019-01-03 18:06:26 -05:00
|
|
|
while lnum > 0 && getline(lnum) =~# '^[ @\+-]'
|
2019-01-03 00:19:21 -05:00
|
|
|
let lnum -= 1
|
|
|
|
endwhile
|
|
|
|
let info = s:StageInfo(lnum)
|
|
|
|
if !has_key(b:fugitive_diff, info.section)
|
|
|
|
continue
|
|
|
|
endif
|
2019-01-03 18:06:26 -05:00
|
|
|
if getline(lnum + 1) =~# '^[ @\+-]'
|
2019-01-03 00:19:21 -05:00
|
|
|
let lnum2 = lnum + 1
|
2019-01-03 18:06:26 -05:00
|
|
|
while getline(lnum2 + 1) =~# '^[ @\+-]'
|
2019-01-03 00:19:21 -05:00
|
|
|
let lnum2 += 1
|
|
|
|
endwhile
|
|
|
|
if a:mode !=# 'show'
|
|
|
|
setlocal modifiable noreadonly
|
|
|
|
exe 'silent keepjumps ' . (lnum + 1) . ',' . lnum2 . 'delete _'
|
|
|
|
call remove(b:fugitive_expanded[info.section], info.filename)
|
|
|
|
setlocal nomodifiable readonly nomodified
|
|
|
|
endif
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
if !has_key(b:fugitive_diff, info.section) || info.status !~# '^[ADM]$' || a:mode ==# 'hide'
|
|
|
|
continue
|
|
|
|
endif
|
|
|
|
let mode = ''
|
|
|
|
let diff = []
|
|
|
|
let index = 0
|
|
|
|
let start = -1
|
|
|
|
for line in b:fugitive_diff[info.section]
|
|
|
|
if mode ==# 'await' && line[0] ==# '@'
|
|
|
|
let mode = 'capture'
|
|
|
|
endif
|
2019-01-03 18:06:26 -05:00
|
|
|
if mode !=# 'head' && line !~# '^[ @\+-]'
|
2019-01-03 00:19:21 -05:00
|
|
|
if len(diff)
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
let start = index
|
|
|
|
let mode = 'head'
|
|
|
|
elseif mode ==# 'head' && line ==# '--- ' . info.filename
|
|
|
|
let mode = 'await'
|
|
|
|
elseif mode ==# 'head' && line ==# '+++ ' . info.filename
|
|
|
|
let mode = 'await'
|
|
|
|
elseif mode ==# 'capture'
|
|
|
|
call add(diff, line)
|
|
|
|
elseif line[0] ==# '@'
|
|
|
|
let mode = ''
|
|
|
|
endif
|
|
|
|
let index += 1
|
|
|
|
endfor
|
|
|
|
if len(diff)
|
|
|
|
setlocal modifiable noreadonly
|
|
|
|
silent call append(lnum, diff)
|
|
|
|
let b:fugitive_expanded[info.section][info.filename] = [start, len(diff)]
|
|
|
|
setlocal nomodifiable readonly nomodified
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
return lnum
|
|
|
|
endfunction
|
|
|
|
|
2018-06-01 13:46:22 -04:00
|
|
|
function! s:StageDiff(diff) abort
|
2019-01-03 00:19:21 -05:00
|
|
|
let lnum = line('.')
|
|
|
|
let info = s:StageInfo(lnum)
|
|
|
|
let prefix = info.offset > 0 ? '+' . info.offset : ''
|
|
|
|
if empty(info.filename) && info.section ==# 'Staged'
|
2018-06-01 13:46:22 -04:00
|
|
|
return 'Git! diff --no-ext-diff --cached'
|
2019-01-03 00:19:21 -05:00
|
|
|
elseif empty(info.filename)
|
2018-06-01 13:46:22 -04:00
|
|
|
return 'Git! diff --no-ext-diff'
|
2019-01-03 00:19:21 -05:00
|
|
|
elseif info.filename =~# ' -> '
|
|
|
|
let [old, new] = split(info.filename,' -> ')
|
|
|
|
execute 'Gedit' . prefix s:fnameescape(':0:'.new)
|
2018-06-01 13:46:22 -04:00
|
|
|
return a:diff.' HEAD:'.s:fnameescape(old)
|
2019-01-03 00:19:21 -05:00
|
|
|
elseif info.section ==# 'Staged' && info.sigil ==# '-'
|
|
|
|
execute 'Gedit' prefix s:fnameescape('@:'.info.filename)
|
|
|
|
return a:diff.'! :0'
|
|
|
|
elseif info.section ==# 'Staged'
|
|
|
|
execute 'Gedit' prefix s:fnameescape(':0:'.info.filename)
|
|
|
|
return a:diff . (info.sigil ==# '+' ? '!' : '') . ' -'
|
|
|
|
elseif info.sigil ==# '-'
|
|
|
|
execute 'Gedit' prefix s:fnameescape(':0:'.info.filename)
|
|
|
|
return a:diff . '!'
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2019-01-03 00:19:21 -05:00
|
|
|
execute 'Gedit' prefix s:fnameescape(':(top)'.info.filename)
|
|
|
|
return a:diff . (info.sigil ==# '+' ? '!' : '')
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:StageDiffEdit() abort
|
2018-12-27 18:05:29 -05:00
|
|
|
let info = s:StageInfo(line('.'))
|
|
|
|
let arg = (empty(info.filename) ? '.' : info.filename)
|
|
|
|
if info.section ==# 'Staged'
|
2018-06-01 13:46:22 -04:00
|
|
|
return 'Git! diff --no-ext-diff --cached '.s:shellesc(arg)
|
2018-12-27 18:05:29 -05:00
|
|
|
elseif info.status ==# '?'
|
2018-08-13 00:08:59 -04:00
|
|
|
call s:TreeChomp('add', '--intent-to-add', './' . arg)
|
2018-06-01 13:46:22 -04:00
|
|
|
if arg ==# '.'
|
|
|
|
silent! edit!
|
|
|
|
1
|
2018-12-25 14:07:17 -05:00
|
|
|
if !search('^Unstaged','W')
|
2018-12-27 18:05:29 -05:00
|
|
|
call search('^Staged','W')
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
else
|
2019-01-03 00:19:21 -05:00
|
|
|
call s:StageReloadSeek([info.filename, 'Staged'], line('.'), line('.'))
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
else
|
|
|
|
return 'Git! diff --no-ext-diff '.s:shellesc(arg)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2019-01-02 22:01:07 -05:00
|
|
|
function! s:StageApply(info, lnum1, count, reverse, extra) abort
|
|
|
|
let cmd = ['apply', '-p0'] + a:extra
|
|
|
|
let info = a:info
|
|
|
|
let start = a:lnum1
|
|
|
|
let end = start
|
|
|
|
if !a:count
|
|
|
|
while start > 0 && getline(start) !~# '^@@'
|
|
|
|
let start -= 1
|
|
|
|
endwhile
|
|
|
|
while getline(end + 1) =~# '^[-+ ]'
|
|
|
|
let end += 1
|
|
|
|
endwhile
|
|
|
|
else
|
|
|
|
let end = a:lnum1 + a:count - 1
|
|
|
|
call add(cmd, '--recount')
|
|
|
|
endif
|
|
|
|
let lines = getline(start, end)
|
|
|
|
if empty(filter(copy(lines), 'v:val =~# "^[+-]"'))
|
|
|
|
return ''
|
|
|
|
endif
|
2019-01-03 18:06:26 -05:00
|
|
|
if len(filter(copy(lines), 'v:val !~# "^[ @\+-]"'))
|
2019-01-02 22:01:07 -05:00
|
|
|
return 'fugitive: cannot apply hunks across multiple files'
|
|
|
|
endif
|
|
|
|
while getline(end) =~# '^[-+ ]'
|
|
|
|
let end += 1
|
|
|
|
if getline(end) =~# '^[' . (a:reverse ? '+' : '-') . ' ]'
|
|
|
|
call add(lines, ' ' . getline(end)[1:-1])
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
while start > 0 && getline(start) !~# '^@'
|
|
|
|
let start -= 1
|
|
|
|
if getline(start) =~# '^[' . (a:reverse ? '+' : '-') . ' ]'
|
|
|
|
call insert(lines, ' ' . getline(start)[1:-1])
|
|
|
|
elseif getline(start) =~# '^@'
|
|
|
|
call insert(lines, getline(start))
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
if start == 0 || getline(start) !~# '^@@ '
|
|
|
|
return "fugitive: could not find hunk"
|
|
|
|
endif
|
|
|
|
let i = b:fugitive_expanded[info.section][info.filename][0]
|
|
|
|
let head = []
|
|
|
|
while get(b:fugitive_diff[info.section], i, '@') !~# '^@'
|
|
|
|
call add(head, b:fugitive_diff[info.section][i])
|
|
|
|
let i += 1
|
|
|
|
endwhile
|
|
|
|
call extend(lines, head, 'keep')
|
|
|
|
let temp = tempname()
|
|
|
|
call writefile(lines, temp)
|
|
|
|
if a:reverse
|
|
|
|
call add(cmd, '--reverse')
|
|
|
|
endif
|
|
|
|
call extend(cmd, ['--', temp])
|
|
|
|
let output = call('s:TreeChomp', cmd)
|
|
|
|
return v:shell_error ? output : ''
|
|
|
|
endfunction
|
|
|
|
|
2019-01-02 23:49:12 -05:00
|
|
|
function! s:StageDelete(lnum, count) abort
|
|
|
|
let info = s:StageInfo(a:lnum)
|
|
|
|
if empty(info.filename)
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
let hash = s:TreeChomp('hash-object', '-w', './' . info.filename)
|
|
|
|
if empty(hash)
|
|
|
|
return ''
|
|
|
|
elseif info.offset >= 0
|
|
|
|
let output = s:StageApply(info, a:lnum, a:count, 1, info.section ==# 'Staged' ? ['--index'] : [])
|
|
|
|
if len(output)
|
|
|
|
return 'echoerr ' . string(output)
|
|
|
|
endif
|
|
|
|
elseif info.status ==# 'U'
|
|
|
|
call s:TreeChomp('rm', './' . info.filename)
|
|
|
|
elseif info.status ==# '?'
|
|
|
|
call s:TreeChomp('clean', '-f', './' . info.filename)
|
|
|
|
elseif info.section ==# 'Unstaged'
|
|
|
|
call s:TreeChomp('checkout', './' . info.filename)
|
|
|
|
else
|
|
|
|
call s:TreeChomp('checkout', 'HEAD^{}', './' . info.filename)
|
|
|
|
endif
|
|
|
|
exe s:ReloadStatus()
|
|
|
|
let @@ = hash
|
2019-01-03 19:21:35 -05:00
|
|
|
return 'checktime|redraw|echomsg ' .
|
2019-01-02 23:49:12 -05:00
|
|
|
\ string('To restore, :Git cat-file blob '.hash[0:6].' > '.info.filename)
|
|
|
|
endfunction
|
|
|
|
|
2019-01-02 22:01:07 -05:00
|
|
|
function! s:StageToggle(lnum1, count) abort
|
|
|
|
if a:lnum1 == 1 && a:count == 0
|
2018-08-29 20:17:54 -04:00
|
|
|
return 'Gedit .git/|call search("^index$", "wc")'
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
try
|
2019-01-02 22:01:07 -05:00
|
|
|
let info = s:StageInfo(a:lnum1)
|
|
|
|
if empty(info.filename)
|
|
|
|
if info.section ==# 'Staged'
|
|
|
|
call s:TreeChomp('reset','-q')
|
|
|
|
silent! edit!
|
|
|
|
1
|
|
|
|
call search('^Unstaged','W')
|
|
|
|
return ''
|
|
|
|
elseif info.section ==# 'Unstaged'
|
|
|
|
call s:TreeChomp('add','.')
|
|
|
|
silent! edit!
|
|
|
|
1
|
|
|
|
call search('^Staged','W')
|
|
|
|
return ''
|
|
|
|
elseif info.section ==# 'Unpushed' && len(info.commit)
|
|
|
|
let remote = matchstr(info.heading, 'to \zs[^/]\+\ze/')
|
|
|
|
if empty(remote)
|
|
|
|
let remote = '.'
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2019-01-02 22:01:07 -05:00
|
|
|
let branch = matchstr(info.heading, 'to \%([^/]\+/\)\=\zs\S\+')
|
|
|
|
call feedkeys(':Gpush ' . remote . ' ' . info.commit . ':' . branch)
|
|
|
|
return ''
|
|
|
|
elseif info.section ==# 'Unpulled'
|
|
|
|
call feedkeys(':Grebase ' . info.commit)
|
|
|
|
return ''
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2019-01-02 22:01:07 -05:00
|
|
|
elseif info.offset >= 0
|
|
|
|
let output = s:StageApply(info, a:lnum1, a:count, info.section ==# 'Staged', ['--cached'])
|
|
|
|
return len(output) ? 'redraw|echoerr ' . string(output) : s:ReloadStatus()
|
|
|
|
endif
|
|
|
|
let lnum2 = a:count ? a:lnum1 + a:count - 1 : a:lnum1
|
|
|
|
for lnum in range(a:lnum1, lnum2)
|
|
|
|
let info = s:StageInfo(lnum)
|
2018-12-25 14:07:17 -05:00
|
|
|
let filename = info.filename
|
2019-01-02 22:01:07 -05:00
|
|
|
if empty(filename) || info.offset >= 0
|
2018-06-01 13:46:22 -04:00
|
|
|
continue
|
|
|
|
endif
|
|
|
|
execute lnum
|
2018-12-25 14:07:17 -05:00
|
|
|
if info.section ==# 'Staged'
|
2018-08-29 20:21:00 -04:00
|
|
|
let files_to_unstage = split(filename, ' -> ')
|
2018-06-01 13:46:22 -04:00
|
|
|
let filename = files_to_unstage[-1]
|
2018-08-13 00:08:59 -04:00
|
|
|
let cmd = ['reset', '-q'] + map(copy(files_to_unstage), '"./" . v:val')
|
2018-12-25 14:07:17 -05:00
|
|
|
elseif getline(lnum) =~# '^D'
|
2018-08-13 00:08:59 -04:00
|
|
|
let cmd = ['rm', './' . filename]
|
2018-12-25 14:07:17 -05:00
|
|
|
elseif getline(lnum) =~# '^M'
|
2018-08-13 00:08:59 -04:00
|
|
|
let cmd = ['add', './' . filename]
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2018-08-13 00:08:59 -04:00
|
|
|
let cmd = ['add','-A', './' . filename]
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-12-18 19:53:24 -05:00
|
|
|
if !exists('target')
|
2018-12-25 14:07:17 -05:00
|
|
|
let target = [filename, info.section ==# 'Staged' ? '' : 'Staged']
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2019-01-02 22:01:07 -05:00
|
|
|
call call('s:TreeChomp', cmd)
|
2018-06-01 13:46:22 -04:00
|
|
|
endfor
|
2018-12-18 19:53:24 -05:00
|
|
|
if exists('target')
|
2019-01-02 22:01:07 -05:00
|
|
|
exe s:ReloadStatus()
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
2019-01-02 22:01:07 -05:00
|
|
|
return ''
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2019-01-03 12:18:53 -05:00
|
|
|
function! s:StageToggleOnly(section, lnum1, count) abort
|
|
|
|
let info = s:StageInfo(a:lnum1)
|
|
|
|
if info.section ==# a:section
|
|
|
|
return s:StageToggle(a:lnum1, a:count)
|
|
|
|
else
|
|
|
|
return s:StageNext(a:count ? a:count : 1)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-06-01 13:46:22 -04:00
|
|
|
function! s:StagePatch(lnum1,lnum2) abort
|
|
|
|
let add = []
|
|
|
|
let reset = []
|
|
|
|
|
|
|
|
for lnum in range(a:lnum1,a:lnum2)
|
2019-01-03 00:19:21 -05:00
|
|
|
let info = s:StageInfo(lnum)
|
|
|
|
if empty(info.filename) && info.section ==# 'Staged'
|
2018-06-01 13:46:22 -04:00
|
|
|
return 'Git reset --patch'
|
2019-01-03 00:19:21 -05:00
|
|
|
elseif empty(info.filename) && info.section ==# 'Unstaged'
|
2018-06-01 13:46:22 -04:00
|
|
|
return 'Git add --patch'
|
2019-01-03 00:19:21 -05:00
|
|
|
elseif info.filename ==# ''
|
2018-06-01 13:46:22 -04:00
|
|
|
continue
|
|
|
|
endif
|
|
|
|
execute lnum
|
2019-01-03 00:19:21 -05:00
|
|
|
if info.filename =~ ' -> '
|
|
|
|
let reset += [split(info.filename,' -> ')[1]]
|
|
|
|
elseif info.section ==# 'Staged'
|
|
|
|
let reset += [info.filename]
|
|
|
|
elseif info.status !~# '^D'
|
|
|
|
let add += [info.filename]
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
try
|
|
|
|
if !empty(add)
|
|
|
|
execute "Git add --patch -- ".join(map(add,'s:shellesc(v:val)'))
|
|
|
|
endif
|
|
|
|
if !empty(reset)
|
|
|
|
execute "Git reset --patch -- ".join(map(reset,'s:shellesc(v:val)'))
|
|
|
|
endif
|
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
2019-01-03 00:19:21 -05:00
|
|
|
return s:ReloadStatus()
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gcommit
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
call s:command("-nargs=? -complete=customlist,s:CommitComplete Gcommit :execute s:Commit('<mods>', <q-args>)")
|
|
|
|
|
|
|
|
function! s:Commit(mods, args, ...) abort
|
|
|
|
let mods = s:gsub(a:mods ==# '<mods>' ? '' : a:mods, '<tab>', '-tab')
|
2018-07-19 02:09:51 -04:00
|
|
|
let dir = a:0 ? a:1 : b:git_dir
|
2018-07-27 00:56:21 -04:00
|
|
|
let tree = s:Tree(dir)
|
2018-07-19 02:09:51 -04:00
|
|
|
let msgfile = dir . '/COMMIT_EDITMSG'
|
2018-06-01 13:46:22 -04:00
|
|
|
let outfile = tempname()
|
|
|
|
let errorfile = tempname()
|
|
|
|
try
|
2018-06-25 12:51:34 -04:00
|
|
|
let guioptions = &guioptions
|
2018-06-01 13:46:22 -04:00
|
|
|
try
|
2018-06-25 12:51:34 -04:00
|
|
|
if &guioptions =~# '!'
|
|
|
|
setglobal guioptions-=!
|
|
|
|
endif
|
2018-12-16 22:13:12 -05:00
|
|
|
let cdback = s:Cd(tree)
|
2018-06-01 13:46:22 -04:00
|
|
|
if s:winshell()
|
|
|
|
let command = ''
|
|
|
|
let old_editor = $GIT_EDITOR
|
|
|
|
let $GIT_EDITOR = 'false'
|
|
|
|
else
|
|
|
|
let command = 'env GIT_EDITOR=false '
|
|
|
|
endif
|
2018-08-03 01:33:47 -04:00
|
|
|
let args = s:ShellExpand(a:args)
|
2018-08-01 19:06:56 -04:00
|
|
|
let command .= s:UserCommand() . ' commit ' . args
|
2018-06-01 13:46:22 -04:00
|
|
|
if &shell =~# 'csh'
|
2018-08-01 19:06:56 -04:00
|
|
|
noautocmd silent execute '!('.escape(command, '!#%').' > '.outfile.') >& '.errorfile
|
2018-06-01 13:46:22 -04:00
|
|
|
elseif a:args =~# '\%(^\| \)-\%(-interactive\|p\|-patch\)\>'
|
|
|
|
noautocmd execute '!'.command.' 2> '.errorfile
|
|
|
|
else
|
|
|
|
noautocmd silent execute '!'.command.' > '.outfile.' 2> '.errorfile
|
|
|
|
endif
|
|
|
|
let error = v:shell_error
|
|
|
|
finally
|
2018-12-16 22:13:12 -05:00
|
|
|
execute cdback
|
2018-06-25 12:51:34 -04:00
|
|
|
let &guioptions = guioptions
|
2018-06-01 13:46:22 -04:00
|
|
|
endtry
|
|
|
|
if !has('gui_running')
|
|
|
|
redraw!
|
|
|
|
endif
|
|
|
|
if !error
|
|
|
|
if filereadable(outfile)
|
|
|
|
for line in readfile(outfile)
|
|
|
|
echo line
|
|
|
|
endfor
|
|
|
|
endif
|
2018-12-19 17:08:38 -05:00
|
|
|
call fugitive#ReloadStatus()
|
2018-06-01 13:46:22 -04:00
|
|
|
return ''
|
|
|
|
else
|
|
|
|
let errors = readfile(errorfile)
|
|
|
|
let error = get(errors,-2,get(errors,-1,'!'))
|
|
|
|
if error =~# 'false''\=\.$'
|
|
|
|
let args = s:gsub(args,'%(%(^| )-- )@<!%(^| )@<=%(-[esp]|--edit|--interactive|--patch|--signoff)%($| )','')
|
|
|
|
let args = s:gsub(args,'%(%(^| )-- )@<!%(^| )@<=%(-c|--reedit-message|--reuse-message|-F|--file|-m|--message)%(\s+|\=)%(''[^'']*''|"%(\\.|[^"])*"|\\.|\S)*','')
|
|
|
|
let args = s:sub(args, '\ze -- |$', ' --no-edit --no-interactive --no-signoff')
|
|
|
|
let args = '-F '.s:shellesc(msgfile).' '.args
|
|
|
|
if args !~# '\%(^\| \)--cleanup\>'
|
|
|
|
let args = '--cleanup=strip '.args
|
|
|
|
endif
|
|
|
|
if bufname('%') == '' && line('$') == 1 && getline(1) == '' && !&mod
|
|
|
|
execute mods 'keepalt edit' s:fnameescape(msgfile)
|
|
|
|
elseif a:args =~# '\%(^\| \)-\w*v' || mods =~# '\<tab\>'
|
|
|
|
execute mods 'keepalt -tabedit' s:fnameescape(msgfile)
|
|
|
|
else
|
|
|
|
execute mods 'keepalt split' s:fnameescape(msgfile)
|
|
|
|
endif
|
|
|
|
let b:fugitive_commit_arguments = args
|
|
|
|
setlocal bufhidden=wipe filetype=gitcommit
|
|
|
|
return '1'
|
|
|
|
elseif error ==# '!'
|
2018-12-19 17:08:38 -05:00
|
|
|
echo get(readfile(outfile), -1, '')
|
|
|
|
return ''
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
|
|
|
call s:throw(empty(error)?join(errors, ' '):error)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
finally
|
|
|
|
if exists('old_editor')
|
|
|
|
let $GIT_EDITOR = old_editor
|
|
|
|
endif
|
|
|
|
call delete(outfile)
|
|
|
|
call delete(errorfile)
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:CommitComplete(A,L,P) abort
|
2018-07-28 17:28:30 -04:00
|
|
|
if a:A =~# '^--fixup=\|^--squash='
|
|
|
|
let commits = split(s:TreeChomp('log', '--pretty=format:%s', '@{upstream}..'), "\n")
|
|
|
|
if !v:shell_error
|
|
|
|
let pre = matchstr(a:A, '^--\w*=') . ':/^'
|
|
|
|
return map(commits, 'pre . tr(v:val, "\\ !^$*?[]()''\"`&;<>|#", "....................")')
|
|
|
|
endif
|
|
|
|
elseif a:A =~ '^-' || type(a:A) == type(0) " a:A is 0 on :Gcommit -<Tab>
|
2018-06-01 13:46:22 -04:00
|
|
|
let args = ['-C', '-F', '-a', '-c', '-e', '-i', '-m', '-n', '-o', '-q', '-s', '-t', '-u', '-v', '--all', '--allow-empty', '--amend', '--author=', '--cleanup=', '--dry-run', '--edit', '--file=', '--fixup=', '--include', '--interactive', '--message=', '--no-verify', '--only', '--quiet', '--reedit-message=', '--reuse-message=', '--signoff', '--squash=', '--template=', '--untracked-files', '--verbose']
|
|
|
|
return filter(args,'v:val[0 : strlen(a:A)-1] ==# a:A')
|
|
|
|
else
|
2018-08-11 00:52:48 -04:00
|
|
|
return fugitive#PathComplete(a:A, b:git_dir)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-28 17:28:30 -04:00
|
|
|
return []
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:FinishCommit() abort
|
2018-12-31 12:52:51 -05:00
|
|
|
let buf = +expand('<abuf>')
|
|
|
|
let args = getbufvar(buf, 'fugitive_commit_arguments')
|
2018-06-01 13:46:22 -04:00
|
|
|
if !empty(args)
|
2018-12-31 12:52:51 -05:00
|
|
|
call setbufvar(buf, 'fugitive_commit_arguments', '')
|
|
|
|
if getbufvar(buf, 'fugitive_commit_rebase')
|
|
|
|
call setbufvar(buf, 'fugitive_commit_rebase', 0)
|
|
|
|
let s:rebase_continue = getbufvar(buf, 'git_dir')
|
|
|
|
endif
|
|
|
|
return s:Commit('', args, getbufvar(buf, 'git_dir'))
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gmerge, :Grebase, :Gpull
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
call s:command("-nargs=? -bang -complete=custom,s:RevisionComplete Gmerge " .
|
2018-12-26 16:23:33 -05:00
|
|
|
\ "execute s:Merge('merge', <bang>0, '<mods>', <q-args>)")
|
2018-06-01 13:46:22 -04:00
|
|
|
call s:command("-nargs=? -bang -complete=custom,s:RevisionComplete Grebase " .
|
2018-12-26 16:23:33 -05:00
|
|
|
\ "execute s:Merge('rebase', <bang>0, '<mods>', <q-args>)")
|
2018-06-01 13:46:22 -04:00
|
|
|
call s:command("-nargs=? -bang -complete=custom,s:RemoteComplete Gpull " .
|
2018-12-26 16:23:33 -05:00
|
|
|
\ "execute s:Merge('pull --progress', <bang>0, '<mods>', <q-args>)")
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
function! s:RevisionComplete(A, L, P) abort
|
2018-07-22 13:56:21 -04:00
|
|
|
return s:TreeChomp('rev-parse', '--symbolic', '--branches', '--tags', '--remotes')
|
2018-08-07 15:33:19 -04:00
|
|
|
\ . "\nHEAD\nFETCH_HEAD\nMERGE_HEAD\nORIG_HEAD"
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:RemoteComplete(A, L, P) abort
|
|
|
|
let remote = matchstr(a:L, ' \zs\S\+\ze ')
|
|
|
|
if !empty(remote)
|
2018-07-22 13:56:21 -04:00
|
|
|
let matches = split(s:TreeChomp('ls-remote', remote), "\n")
|
2018-06-01 13:46:22 -04:00
|
|
|
call filter(matches, 'v:val =~# "\t" && v:val !~# "{"')
|
|
|
|
call map(matches, 's:sub(v:val, "^.*\t%(refs/%(heads/|tags/)=)=", "")')
|
|
|
|
else
|
2018-07-22 13:56:21 -04:00
|
|
|
let matches = split(s:TreeChomp('remote'), "\n")
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
return join(matches, "\n")
|
|
|
|
endfunction
|
|
|
|
|
2018-12-31 12:52:51 -05:00
|
|
|
function! s:RebaseSequenceAborter() abort
|
|
|
|
if !exists('s:rebase_sequence_aborter')
|
|
|
|
let temp = tempname() . '.sh'
|
|
|
|
call writefile(
|
|
|
|
\ ['#!/bin/sh',
|
|
|
|
\ 'echo exec false | cat - "$1" > "$1.fugitive"',
|
|
|
|
\ 'mv "$1.fugitive" "$1"'],
|
|
|
|
\ temp)
|
|
|
|
let s:rebase_sequence_aborter = temp
|
2018-12-26 08:39:34 -05:00
|
|
|
endif
|
2018-12-31 12:52:51 -05:00
|
|
|
return s:rebase_sequence_aborter
|
2018-12-26 08:39:34 -05:00
|
|
|
endfunction
|
|
|
|
|
2018-06-01 13:47:48 -04:00
|
|
|
function! fugitive#Cwindow() abort
|
2018-06-01 13:46:22 -04:00
|
|
|
if &buftype == 'quickfix'
|
|
|
|
cwindow
|
|
|
|
else
|
|
|
|
botright cwindow
|
|
|
|
if &buftype == 'quickfix'
|
|
|
|
wincmd p
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let s:common_efm = ''
|
|
|
|
\ . '%+Egit:%.%#,'
|
|
|
|
\ . '%+Eusage:%.%#,'
|
|
|
|
\ . '%+Eerror:%.%#,'
|
|
|
|
\ . '%+Efatal:%.%#,'
|
|
|
|
\ . '%-G%.%#%\e[K%.%#,'
|
|
|
|
\ . '%-G%.%#%\r%.%\+'
|
|
|
|
|
2018-12-31 00:15:10 -05:00
|
|
|
let s:rebase_abbrevs = {
|
|
|
|
\ 'p': 'pick',
|
|
|
|
\ 'r': 'reword',
|
|
|
|
\ 'e': 'edit',
|
|
|
|
\ 's': 'squash',
|
|
|
|
\ 'f': 'fixup',
|
|
|
|
\ 'x': 'exec',
|
|
|
|
\ 'd': 'drop',
|
|
|
|
\ 'l': 'label',
|
|
|
|
\ 't': 'reset',
|
|
|
|
\ 'm': 'merge',
|
|
|
|
\ 'b': 'break',
|
|
|
|
\ }
|
|
|
|
|
2018-12-31 12:52:51 -05:00
|
|
|
function! s:RebaseEdit(cmd, dir) abort
|
|
|
|
return a:cmd . ' +setlocal\ bufhidden=wipe ' . s:fnameescape(a:dir . '/rebase-merge/git-rebase-todo')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Merge(cmd, bang, mods, args, ...) abort
|
|
|
|
let dir = a:0 ? a:1 : b:git_dir
|
2018-12-26 16:23:33 -05:00
|
|
|
let mods = substitute(a:mods, '\C<mods>', '', '') . ' '
|
2018-12-26 10:06:46 -05:00
|
|
|
if a:cmd =~# '^rebase' && ' '.a:args =~# ' -i\| --interactive'
|
2018-12-31 12:52:51 -05:00
|
|
|
let cmd = fugitive#Prepare(dir, '-c', 'sequence.editor=sh ' . s:RebaseSequenceAborter(), 'rebase') . ' ' . a:args
|
|
|
|
let out = system(cmd)[0:-2]
|
|
|
|
for file in ['end', 'msgnum']
|
|
|
|
let file = fugitive#Find('.git/rebase-merge/' . file, dir)
|
|
|
|
if !filereadable(file)
|
|
|
|
return 'echoerr ' . string("fugitive: " . out)
|
|
|
|
endif
|
|
|
|
call writefile([readfile(file)[0] - 1], file)
|
|
|
|
endfor
|
|
|
|
call writefile([], fugitive#Find('.git/rebase-merge/done', dir))
|
|
|
|
if a:bang
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
return s:RebaseEdit(mods . 'split', dir)
|
|
|
|
elseif a:cmd =~# '^rebase' && ' '.a:args =~# ' --edit-todo' && filereadable(dir . '/rebase-merge/git-rebase-todo')
|
|
|
|
return s:RebaseEdit(mods . 'split', dir)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
let [mp, efm] = [&l:mp, &l:efm]
|
2018-12-31 12:52:51 -05:00
|
|
|
let had_merge_msg = filereadable(dir . '/MERGE_MSG')
|
2018-06-01 13:46:22 -04:00
|
|
|
try
|
2018-12-31 12:52:51 -05:00
|
|
|
let cdback = s:Cd(s:Tree(dir))
|
2018-06-01 13:46:22 -04:00
|
|
|
let &l:errorformat = ''
|
|
|
|
\ . '%-Gerror:%.%#false''.,'
|
|
|
|
\ . '%-G%.%# ''git commit'' %.%#,'
|
|
|
|
\ . '%+Emerge:%.%#,'
|
|
|
|
\ . s:common_efm . ','
|
|
|
|
\ . '%+ECannot %.%#: You have unstaged changes.,'
|
|
|
|
\ . '%+ECannot %.%#: Your index contains uncommitted changes.,'
|
|
|
|
\ . '%+EThere is no tracking information for the current branch.,'
|
|
|
|
\ . '%+EYou are not currently on a branch. Please specify which,'
|
2018-12-31 12:52:51 -05:00
|
|
|
\ . '%+I %#git rebase --continue,'
|
2018-06-01 13:46:22 -04:00
|
|
|
\ . 'CONFLICT (%m): %f deleted in %.%#,'
|
|
|
|
\ . 'CONFLICT (%m): Merge conflict in %f,'
|
|
|
|
\ . 'CONFLICT (%m): Rename \"%f\"->%.%#,'
|
|
|
|
\ . 'CONFLICT (%m): Rename %.%#->%f %.%#,'
|
|
|
|
\ . 'CONFLICT (%m): There is a directory with name %f in %.%#,'
|
|
|
|
\ . '%+ECONFLICT %.%#,'
|
|
|
|
\ . '%+EKONFLIKT %.%#,'
|
|
|
|
\ . '%+ECONFLIT %.%#,'
|
|
|
|
\ . "%+EXUNG \u0110\u1ed8T %.%#,"
|
|
|
|
\ . "%+E\u51b2\u7a81 %.%#,"
|
|
|
|
\ . 'U%\t%f'
|
|
|
|
if a:cmd =~# '^merge' && empty(a:args) &&
|
2018-12-31 12:52:51 -05:00
|
|
|
\ (had_merge_msg || isdirectory(dir . '/rebase-apply') ||
|
|
|
|
\ !empty(s:TreeChomp(dir, 'diff-files', '--diff-filter=U')))
|
2018-06-01 13:46:22 -04:00
|
|
|
let &l:makeprg = g:fugitive_git_executable.' diff-files --name-status --diff-filter=U'
|
|
|
|
else
|
2018-07-27 00:19:44 -04:00
|
|
|
let &l:makeprg = s:sub(s:UserCommand() . ' ' . a:cmd .
|
2018-12-30 22:13:06 -05:00
|
|
|
\ (' ' . a:args =~# ' \%(--no-edit\|--abort\|-m\)\>' || a:cmd =~# '^rebase' ? '' : ' --edit') .
|
|
|
|
\ (' ' . a:args =~# ' --autosquash\>' && a:cmd =~# '^rebase' ? ' --interactive' : '') .
|
2018-06-01 13:46:22 -04:00
|
|
|
\ ' ' . a:args, ' *$', '')
|
|
|
|
endif
|
2018-12-30 22:13:06 -05:00
|
|
|
if !empty($GIT_SEQUENCE_EDITOR) || has('win32')
|
|
|
|
let old_sequence_editor = $GIT_SEQUENCE_EDITOR
|
|
|
|
let $GIT_SEQUENCE_EDITOR = 'true'
|
|
|
|
else
|
|
|
|
let &l:makeprg = 'env GIT_SEQUENCE_EDITOR=true ' . &l:makeprg
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
if !empty($GIT_EDITOR) || has('win32')
|
|
|
|
let old_editor = $GIT_EDITOR
|
|
|
|
let $GIT_EDITOR = 'false'
|
|
|
|
else
|
2018-12-30 22:13:06 -05:00
|
|
|
let &l:makeprg = 'env GIT_EDITOR=false ' . substitute(&l:makeprg, '^env ', '', '')
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
silent noautocmd make!
|
|
|
|
catch /^Vim\%((\a\+)\)\=:E211/
|
|
|
|
let err = v:exception
|
|
|
|
finally
|
|
|
|
redraw!
|
|
|
|
let [&l:mp, &l:efm] = [mp, efm]
|
|
|
|
if exists('old_editor')
|
|
|
|
let $GIT_EDITOR = old_editor
|
|
|
|
endif
|
2018-12-30 22:13:06 -05:00
|
|
|
if exists('old_sequence_editor')
|
|
|
|
let $GIT_SEQUENCE_EDITOR = old_editor
|
|
|
|
endif
|
2018-12-16 22:13:12 -05:00
|
|
|
execute cdback
|
2018-06-01 13:46:22 -04:00
|
|
|
endtry
|
|
|
|
call fugitive#ReloadStatus()
|
2018-12-26 08:39:34 -05:00
|
|
|
if empty(filter(getqflist(),'v:val.valid && v:val.type !=# "I"'))
|
2018-12-31 12:52:51 -05:00
|
|
|
if a:cmd =~# '^rebase' &&
|
|
|
|
\ filereadable(dir . '/rebase-merge/amend') &&
|
|
|
|
\ filereadable(dir . '/rebase-merge/done') &&
|
|
|
|
\ get(readfile(dir . '/rebase-merge/done'), -1, '') =~# '^[^e]'
|
2018-06-01 13:46:22 -04:00
|
|
|
cclose
|
2018-12-31 12:52:51 -05:00
|
|
|
return 'exe ' . string(mods . 'Gcommit --amend -n -F ' . s:shellesc(dir . '/rebase-merge/message') . ' -e') . '|let b:fugitive_commit_rebase = 1'
|
|
|
|
elseif !had_merge_msg && filereadable(dir . '/MERGE_MSG')
|
2018-12-26 08:39:34 -05:00
|
|
|
cclose
|
2018-12-31 12:52:51 -05:00
|
|
|
return mods . 'Gcommit --no-status -n -t '.s:shellesc(dir . '/MERGE_MSG')
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
let qflist = getqflist()
|
|
|
|
let found = 0
|
|
|
|
for e in qflist
|
|
|
|
if !empty(e.bufnr)
|
|
|
|
let found = 1
|
|
|
|
let e.pattern = '^<<<<<<<'
|
|
|
|
endif
|
|
|
|
endfor
|
2018-06-01 13:47:48 -04:00
|
|
|
call fugitive#Cwindow()
|
2018-06-01 13:46:22 -04:00
|
|
|
if found
|
|
|
|
call setqflist(qflist, 'r')
|
|
|
|
if !a:bang
|
|
|
|
return 'cfirst'
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
return exists('err') ? 'echoerr '.string(err) : ''
|
|
|
|
endfunction
|
|
|
|
|
2018-12-31 12:52:51 -05:00
|
|
|
function! s:RebaseClean(file) abort
|
|
|
|
if !filereadable(a:file)
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
let old = readfile(a:file)
|
|
|
|
let new = copy(old)
|
|
|
|
for i in range(len(new))
|
|
|
|
let new[i] = substitute(new[i], '^\l\>', '\=get(s:rebase_abbrevs,submatch(0),submatch(0))', '')
|
|
|
|
endfor
|
|
|
|
if new !=# old
|
|
|
|
call writefile(new, a:file)
|
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
augroup fugitive_merge
|
|
|
|
autocmd!
|
|
|
|
autocmd VimLeavePre,BufDelete git-rebase-todo
|
2019-01-01 19:27:47 -05:00
|
|
|
\ if getbufvar(+expand('<abuf>'), '&bufhidden') ==# 'wipe' |
|
2018-12-31 12:52:51 -05:00
|
|
|
\ call s:RebaseClean(expand('<afile>')) |
|
2019-01-01 19:27:47 -05:00
|
|
|
\ if getfsize(FugitiveFind('.git/rebase-merge/done', +expand('<abuf>'))) == 0 |
|
|
|
|
\ let s:rebase_continue = FugitiveGitDir(+expand('<abuf>')) |
|
2018-12-31 12:52:51 -05:00
|
|
|
\ endif |
|
|
|
|
\ endif
|
2019-01-02 14:12:46 -05:00
|
|
|
autocmd BufEnter * nested
|
2018-12-31 12:52:51 -05:00
|
|
|
\ if exists('s:rebase_continue') |
|
|
|
|
\ exe s:Merge('rebase', 0, '', getfsize(fugitive#Find('.git/rebase-merge/git-rebase-todo', s:rebase_continue)) > 0 ? '--continue' : '--abort', remove(s:, 'rebase_continue')) |
|
|
|
|
\ endif
|
|
|
|
augroup END
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Ggrep, :Glog
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
if !exists('g:fugitive_summary_format')
|
|
|
|
let g:fugitive_summary_format = '%s'
|
|
|
|
endif
|
|
|
|
|
2018-07-28 19:09:05 -04:00
|
|
|
function! s:GrepComplete(A, L, P) abort
|
|
|
|
if strpart(a:L, 0, a:P) =~# ' -- '
|
2018-08-11 00:52:48 -04:00
|
|
|
return fugitive#PathComplete(a:A, b:git_dir)
|
2018-07-28 19:09:05 -04:00
|
|
|
else
|
2018-08-11 00:52:48 -04:00
|
|
|
return fugitive#Complete(a:A, b:git_dir)
|
2018-07-28 19:09:05 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Ggrep :execute s:Grep('grep',<bang>0,<q-args>)")
|
|
|
|
call s:command("-bang -nargs=? -complete=customlist,s:GrepComplete Glgrep :execute s:Grep('lgrep',<bang>0,<q-args>)")
|
2018-08-03 01:33:47 -04:00
|
|
|
call s:command("-bar -bang -nargs=* -range=-1 -complete=customlist,s:GrepComplete Glog :call s:Log('grep',<bang>0,<line1>,<count>,<q-args>)")
|
|
|
|
call s:command("-bar -bang -nargs=* -range=-1 -complete=customlist,s:GrepComplete Gllog :call s:Log('lgrep',<bang>0,<line1>,<count>,<q-args>)")
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
function! s:Grep(cmd,bang,arg) abort
|
|
|
|
let grepprg = &grepprg
|
|
|
|
let grepformat = &grepformat
|
|
|
|
try
|
2018-12-16 22:13:12 -05:00
|
|
|
let cdback = s:Cd(s:Tree())
|
2018-07-27 00:19:44 -04:00
|
|
|
let &grepprg = s:UserCommand() . ' --no-pager grep -n --no-color'
|
2018-06-01 13:46:22 -04:00
|
|
|
let &grepformat = '%f:%l:%m,%m %f match%ts,%f'
|
2018-08-03 01:33:47 -04:00
|
|
|
exe a:cmd.'! '.escape(s:ShellExpand(matchstr(a:arg, '\v\C.{-}%($|[''" ]\@=\|)@=')), '|#%')
|
2018-06-01 13:46:22 -04:00
|
|
|
let list = a:cmd =~# '^l' ? getloclist(0) : getqflist()
|
|
|
|
for entry in list
|
|
|
|
if bufname(entry.bufnr) =~ ':'
|
2018-07-22 01:29:49 -04:00
|
|
|
let entry.filename = s:Generate(bufname(entry.bufnr))
|
2018-06-01 13:46:22 -04:00
|
|
|
unlet! entry.bufnr
|
|
|
|
let changed = 1
|
|
|
|
elseif a:arg =~# '\%(^\| \)--cached\>'
|
2018-07-22 01:29:49 -04:00
|
|
|
let entry.filename = s:Generate(':0:'.bufname(entry.bufnr))
|
2018-06-01 13:46:22 -04:00
|
|
|
unlet! entry.bufnr
|
|
|
|
let changed = 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
if a:cmd =~# '^l' && exists('changed')
|
|
|
|
call setloclist(0, list, 'r')
|
|
|
|
elseif exists('changed')
|
|
|
|
call setqflist(list, 'r')
|
|
|
|
endif
|
|
|
|
if !a:bang && !empty(list)
|
|
|
|
return (a:cmd =~# '^l' ? 'l' : 'c').'first'.matchstr(a:arg,'\v\C[''" ]\zs\|.*')
|
|
|
|
else
|
|
|
|
return matchstr(a:arg,'\v\C[''" ]\|\zs.*')
|
|
|
|
endif
|
|
|
|
finally
|
|
|
|
let &grepprg = grepprg
|
|
|
|
let &grepformat = grepformat
|
2018-12-16 22:13:12 -05:00
|
|
|
execute cdback
|
2018-06-01 13:46:22 -04:00
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2018-07-22 21:28:15 -04:00
|
|
|
function! s:Log(cmd, bang, line1, line2, ...) abort
|
2018-08-03 01:33:47 -04:00
|
|
|
let args = ' ' . join(a:000, ' ')
|
|
|
|
let before = substitute(args, ' --\S\@!.*', '', '')
|
|
|
|
let after = strpart(args, len(before))
|
2018-07-22 14:18:59 -04:00
|
|
|
let path = s:Relative('/')
|
2018-08-25 16:04:27 -04:00
|
|
|
let relative = path[1:-1]
|
2018-08-03 01:33:47 -04:00
|
|
|
if path =~# '^/\.git\%(/\|$\)' || len(after)
|
2018-06-01 13:46:22 -04:00
|
|
|
let path = ''
|
|
|
|
endif
|
2018-08-03 01:33:47 -04:00
|
|
|
if before !~# '\s[^[:space:]-]'
|
2018-08-07 15:33:19 -04:00
|
|
|
let owner = s:Owner(@%)
|
|
|
|
if len(owner)
|
|
|
|
let before .= ' ' . s:shellesc(owner)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endif
|
2018-08-03 01:33:47 -04:00
|
|
|
if relative =~# '^\.git\%(/\|$\)'
|
|
|
|
let relative = ''
|
|
|
|
endif
|
|
|
|
if len(relative) && a:line2 > 0
|
|
|
|
let before .= ' -L ' . s:shellesc(a:line1 . ',' . a:line2 . ':' . relative)
|
|
|
|
elseif len(relative) && (empty(after) || a:line2 == 0)
|
|
|
|
let after = (len(after) > 3 ? after : ' -- ') . relative
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
let grepformat = &grepformat
|
|
|
|
let grepprg = &grepprg
|
|
|
|
try
|
2018-12-16 22:13:12 -05:00
|
|
|
let cdback = s:Cd(s:Tree())
|
2019-01-05 17:41:45 -05:00
|
|
|
let format = before =~# ' -g\| --walk-reflogs' ? '%gD %gs' : g:fugitive_summary_format
|
2018-08-03 01:33:47 -04:00
|
|
|
let &grepprg = escape(s:UserCommand() . ' --no-pager log --no-color ' .
|
2019-01-05 17:41:45 -05:00
|
|
|
\ s:shellesc('--pretty=format:fugitive://'.b:git_dir.'//%H'.path.'::'.format), '%#')
|
2018-06-01 13:46:22 -04:00
|
|
|
let &grepformat = '%Cdiff %.%#,%C--- %.%#,%C+++ %.%#,%Z@@ -%\d%\+\,%\d%\+ +%l\,%\d%\+ @@,%-G-%.%#,%-G+%.%#,%-G %.%#,%A%f::%m,%-G%.%#'
|
2018-08-03 01:33:47 -04:00
|
|
|
exe a:cmd . (a:bang ? '! ' : ' ') . s:ShellExpand(before . after)
|
2019-01-05 14:03:45 -05:00
|
|
|
if len(path) && a:line2 == -1
|
|
|
|
redraw
|
|
|
|
echohl WarningMsg
|
|
|
|
echo ':Glog will soon default to all files. Use :0Glog to target current file'
|
|
|
|
echohl NONE
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
finally
|
|
|
|
let &grepformat = grepformat
|
|
|
|
let &grepprg = grepprg
|
2018-12-16 22:13:12 -05:00
|
|
|
execute cdback
|
2018-06-01 13:46:22 -04:00
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gedit, :Gpedit, :Gsplit, :Gvsplit, :Gtabedit, :Gread
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
function! s:UsableWin(nr) abort
|
|
|
|
return a:nr && !getwinvar(a:nr, '&previewwindow') &&
|
2019-01-03 00:23:02 -05:00
|
|
|
\ empty(getwinvar(a:nr, 'fugitive_status')) &&
|
2018-12-31 00:15:10 -05:00
|
|
|
\ index(['gitrebase', 'gitcommit'], getbufvar(winbufnr(a:nr), '&filetype')) < 0 &&
|
2018-06-01 13:46:22 -04:00
|
|
|
\ index(['nofile','help','quickfix'], getbufvar(winbufnr(a:nr), '&buftype')) < 0
|
|
|
|
endfunction
|
|
|
|
|
2018-08-03 22:50:32 -04:00
|
|
|
function! s:EditParse(args) abort
|
2018-07-30 00:47:26 -04:00
|
|
|
let pre = []
|
|
|
|
let args = copy(a:args)
|
|
|
|
while !empty(args) && args[0] =~# '^+'
|
2018-08-20 01:11:29 -04:00
|
|
|
call add(pre, ' ' . escape(remove(args, 0), ' |"'))
|
2018-07-30 00:47:26 -04:00
|
|
|
endwhile
|
|
|
|
if len(args)
|
|
|
|
let file = join(args)
|
|
|
|
elseif empty(expand('%'))
|
|
|
|
let file = ':'
|
2018-08-03 22:50:32 -04:00
|
|
|
elseif empty(s:DirCommitFile(@%)[1]) && s:Relative('./') !~# '^\./\.git\>'
|
2018-08-15 19:24:35 -04:00
|
|
|
let file = ':0:%'
|
2018-07-27 00:19:44 -04:00
|
|
|
else
|
2018-08-15 19:24:35 -04:00
|
|
|
let file = '%'
|
2018-07-27 00:19:44 -04:00
|
|
|
endif
|
2018-08-03 22:50:32 -04:00
|
|
|
return [s:Expand(file), join(pre)]
|
2018-07-27 00:19:44 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-03 22:50:32 -04:00
|
|
|
function! s:BlurStatus() abort
|
2019-01-03 22:47:24 -05:00
|
|
|
if (&previewwindow || exists('w:fugitive_status')) && get(b:,'fugitive_type', '') ==# 'index'
|
2018-07-27 00:19:44 -04:00
|
|
|
let winnrs = filter([winnr('#')] + range(1, winnr('$')), 's:UsableWin(v:val)')
|
|
|
|
if len(winnrs)
|
|
|
|
exe winnrs[0].'wincmd w'
|
|
|
|
else
|
2019-01-03 00:23:02 -05:00
|
|
|
let wide = winwidth(0) >= 160
|
|
|
|
exe 'rightbelow' (winwidth(0) >= 160 ? 'vert' : '') 'new'
|
2018-07-27 00:19:44 -04:00
|
|
|
endif
|
|
|
|
if &diff
|
|
|
|
let mywinnr = winnr()
|
|
|
|
for winnr in range(winnr('$'),1,-1)
|
|
|
|
if winnr != mywinnr && getwinvar(winnr,'&diff')
|
|
|
|
execute winnr.'wincmd w'
|
|
|
|
close
|
|
|
|
if winnr('$') > 1
|
|
|
|
wincmd p
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-27 00:19:44 -04:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
diffoff!
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endif
|
2018-08-03 22:50:32 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Edit(cmd, bang, mods, args, ...) abort
|
|
|
|
let mods = a:mods ==# '<mods>' ? '' : a:mods
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
if a:bang
|
2018-08-18 23:12:09 -04:00
|
|
|
let temp = tempname()
|
2018-08-03 22:50:32 -04:00
|
|
|
try
|
2018-12-16 22:13:12 -05:00
|
|
|
let cdback = s:Cd(s:Tree())
|
2018-08-03 22:50:32 -04:00
|
|
|
let git = s:UserCommand()
|
|
|
|
let args = s:ShellExpand(a:args)
|
|
|
|
silent! execute '!' . escape(git . ' --no-pager ' . args, '!#%') .
|
|
|
|
\ (&shell =~# 'csh' ? ' >& ' . temp : ' > ' . temp . ' 2>&1')
|
|
|
|
finally
|
2018-12-16 22:13:12 -05:00
|
|
|
execute cdback
|
2018-08-03 22:50:32 -04:00
|
|
|
endtry
|
2018-08-18 23:12:09 -04:00
|
|
|
let temp = s:Resolve(temp)
|
2018-08-03 22:50:32 -04:00
|
|
|
let s:temp_files[s:cpath(temp)] = { 'dir': b:git_dir, 'filetype': 'git' }
|
|
|
|
if a:cmd ==# 'edit'
|
|
|
|
call s:BlurStatus()
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-08-03 22:50:32 -04:00
|
|
|
silent execute mods a:cmd temp
|
|
|
|
call fugitive#ReloadStatus()
|
|
|
|
return 'redraw|echo ' . string(':!' . git . ' ' . args)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
|
2018-08-03 22:50:32 -04:00
|
|
|
let [file, pre] = s:EditParse(a:000)
|
2018-06-01 13:46:22 -04:00
|
|
|
try
|
2018-08-03 22:50:32 -04:00
|
|
|
let file = s:Generate(file)
|
2018-06-01 13:46:22 -04:00
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
2018-08-06 10:52:41 -04:00
|
|
|
if file !~# '^\a\a\+:'
|
2018-06-01 13:46:22 -04:00
|
|
|
let file = s:sub(file, '/$', '')
|
|
|
|
endif
|
2018-08-03 22:50:32 -04:00
|
|
|
if a:cmd ==# 'edit'
|
|
|
|
call s:BlurStatus()
|
|
|
|
endif
|
2018-08-20 01:11:29 -04:00
|
|
|
return mods . ' ' . a:cmd . pre . ' ' . s:fnameescape(file)
|
2018-07-27 00:19:44 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Read(count, line1, line2, range, bang, mods, args, ...) abort
|
|
|
|
let mods = a:mods ==# '<mods>' ? '' : a:mods
|
|
|
|
let after = a:line2
|
|
|
|
if a:count < 0
|
|
|
|
let delete = 'silent 1,' . line('$') . 'delete_|'
|
|
|
|
let after = line('$')
|
|
|
|
elseif a:range == 2
|
|
|
|
let delete = 'silent ' . a:line1 . ',' . a:line2 . 'delete_|'
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2018-07-27 00:19:44 -04:00
|
|
|
let delete = ''
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-27 00:19:44 -04:00
|
|
|
if a:bang
|
|
|
|
try
|
2018-12-16 22:13:12 -05:00
|
|
|
let cdback = s:Cd(s:Tree())
|
2018-08-03 22:50:32 -04:00
|
|
|
let git = s:UserCommand()
|
|
|
|
let args = s:ShellExpand(a:args)
|
|
|
|
silent execute mods after.'read!' escape(git . ' --no-pager ' . args, '!#%')
|
2018-07-27 00:19:44 -04:00
|
|
|
finally
|
2018-12-16 22:13:12 -05:00
|
|
|
execute cdback
|
2018-07-27 00:19:44 -04:00
|
|
|
endtry
|
|
|
|
execute delete . 'diffupdate'
|
|
|
|
call fugitive#ReloadStatus()
|
|
|
|
return 'redraw|echo '.string(':!'.git.' '.args)
|
|
|
|
endif
|
2018-08-03 22:50:32 -04:00
|
|
|
let [file, pre] = s:EditParse(a:000)
|
2018-07-27 00:19:44 -04:00
|
|
|
try
|
2018-07-30 00:47:26 -04:00
|
|
|
let file = s:Generate(file)
|
2018-07-27 00:19:44 -04:00
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
2018-08-20 01:11:29 -04:00
|
|
|
if file =~# '^fugitive:' && after is# 0
|
|
|
|
return 'exe ' .string(mods . ' ' . fugitive#FileReadCmd(file, 0, pre)) . '|diffupdate'
|
|
|
|
endif
|
|
|
|
return mods . ' ' . after . 'read' . pre . ' ' . s:fnameescape(file) . '|' . delete . 'diffupdate' . (a:count < 0 ? '|' . line('.') : '')
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:EditRunComplete(A,L,P) abort
|
|
|
|
if a:L =~# '^\w\+!'
|
2018-07-27 00:19:44 -04:00
|
|
|
return s:GitComplete(a:A, a:L, a:P)
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2018-07-28 19:09:05 -04:00
|
|
|
return fugitive#Complete(a:A, a:L, a:P)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-07-28 19:09:05 -04:00
|
|
|
call s:command("-bar -bang -nargs=* -complete=customlist,fugitive#Complete Ge execute s:Edit('edit<bang>', 0, '<mods>', <q-args>, <f-args>)")
|
|
|
|
call s:command("-bar -bang -nargs=* -complete=customlist,fugitive#Complete Gedit execute s:Edit('edit<bang>', 0, '<mods>', <q-args>, <f-args>)")
|
2018-07-27 00:19:44 -04:00
|
|
|
call s:command("-bar -bang -nargs=* -complete=customlist,s:EditRunComplete Gpedit execute s:Edit('pedit', <bang>0, '<mods>', <q-args>, <f-args>)")
|
|
|
|
call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:EditRunComplete Gsplit execute s:Edit((<count> ? <count> : '').'split', <bang>0, '<mods>', <q-args>, <f-args>)")
|
|
|
|
call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:EditRunComplete Gvsplit execute s:Edit((<count> ? <count> : '').'vsplit', <bang>0, '<mods>', <q-args>, <f-args>)")
|
|
|
|
call s:command("-bar -bang -nargs=* -range=0 -complete=customlist,s:EditRunComplete" . (has('patch-7.4.542') ? ' -addr=tabs' : '') . " Gtabedit execute s:Edit((<count> ? <count> : '').'tabedit', <bang>0, '<mods>', <q-args>, <f-args>)")
|
|
|
|
call s:command("-bar -bang -nargs=* -range=-1 -complete=customlist,s:EditRunComplete Gread execute s:Read(<count>, <line1>, <line2>, +'<range>', <bang>0, '<mods>', <q-args>, <f-args>)")
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gwrite, :Gwq
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-07-28 19:09:05 -04:00
|
|
|
call s:command("-bar -bang -nargs=* -complete=customlist,fugitive#Complete Gwrite :execute s:Write(<bang>0,<f-args>)")
|
|
|
|
call s:command("-bar -bang -nargs=* -complete=customlist,fugitive#Complete Gw :execute s:Write(<bang>0,<f-args>)")
|
|
|
|
call s:command("-bar -bang -nargs=* -complete=customlist,fugitive#Complete Gwq :execute s:Wq(<bang>0,<f-args>)")
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
function! s:Write(force,...) abort
|
|
|
|
if exists('b:fugitive_commit_arguments')
|
|
|
|
return 'write|bdelete'
|
|
|
|
elseif expand('%:t') == 'COMMIT_EDITMSG' && $GIT_INDEX_FILE != ''
|
|
|
|
return 'wq'
|
2018-07-27 00:14:47 -04:00
|
|
|
elseif get(b:, 'fugitive_type', '') ==# 'index'
|
2018-06-01 13:46:22 -04:00
|
|
|
return 'Gcommit'
|
2018-08-13 00:08:59 -04:00
|
|
|
elseif &buftype ==# 'nowrite' && getline(4) =~# '^+++ '
|
2018-06-01 13:46:22 -04:00
|
|
|
let filename = getline(4)[6:-1]
|
|
|
|
setlocal buftype=
|
|
|
|
silent write
|
|
|
|
setlocal buftype=nowrite
|
2018-07-28 20:24:15 -04:00
|
|
|
if matchstr(getline(2),'index [[:xdigit:]]\+\.\.\zs[[:xdigit:]]\{7\}') ==# fugitive#RevParse(':0:'.filename)[0:6]
|
2018-08-13 00:08:59 -04:00
|
|
|
let err = s:TreeChomp('apply', '--cached', '--reverse', '--', expand('%:p'))
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2018-08-13 00:08:59 -04:00
|
|
|
let err = s:TreeChomp('apply', '--cached', '--', expand('%:p'))
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
if err !=# ''
|
|
|
|
let v:errmsg = split(err,"\n")[0]
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
elseif a:force
|
|
|
|
return 'bdelete'
|
|
|
|
else
|
|
|
|
return 'Gedit '.fnameescape(filename)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
let mytab = tabpagenr()
|
|
|
|
let mybufnr = bufnr('')
|
2018-08-13 00:08:59 -04:00
|
|
|
let file = a:0 ? s:Generate(s:Expand(join(a:000, ' '))) : fugitive#Real(@%)
|
|
|
|
if empty(file)
|
2018-06-01 13:46:22 -04:00
|
|
|
return 'echoerr '.string('fugitive: cannot determine file path')
|
|
|
|
endif
|
2018-08-13 00:08:59 -04:00
|
|
|
if file =~# '^fugitive:'
|
|
|
|
return 'write' . (a:force ? '! ' : ' ') . s:fnameescape(file)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-08-13 00:08:59 -04:00
|
|
|
let always_permitted = s:cpath(fugitive#Real(@%), file) && s:DirCommitFile(@%)[1] =~# '^0\=$'
|
|
|
|
if !always_permitted && !a:force && (len(s:TreeChomp('diff', '--name-status', 'HEAD', '--', file)) || len(s:TreeChomp('ls-files', '--others', '--', file)))
|
2018-06-01 13:46:22 -04:00
|
|
|
let v:errmsg = 'fugitive: file has uncommitted changes (use ! to override)'
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endif
|
|
|
|
let treebufnr = 0
|
|
|
|
for nr in range(1,bufnr('$'))
|
|
|
|
if fnamemodify(bufname(nr),':p') ==# file
|
|
|
|
let treebufnr = nr
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if treebufnr > 0 && treebufnr != bufnr('')
|
|
|
|
let temp = tempname()
|
|
|
|
silent execute '%write '.temp
|
|
|
|
for tab in [mytab] + range(1,tabpagenr('$'))
|
|
|
|
for winnr in range(1,tabpagewinnr(tab,'$'))
|
|
|
|
if tabpagebuflist(tab)[winnr-1] == treebufnr
|
|
|
|
execute 'tabnext '.tab
|
|
|
|
if winnr != winnr()
|
|
|
|
execute winnr.'wincmd w'
|
|
|
|
let restorewinnr = 1
|
|
|
|
endif
|
|
|
|
try
|
|
|
|
let lnum = line('.')
|
|
|
|
let last = line('$')
|
|
|
|
silent execute '$read '.temp
|
|
|
|
silent execute '1,'.last.'delete_'
|
|
|
|
silent write!
|
|
|
|
silent execute lnum
|
|
|
|
let did = 1
|
|
|
|
finally
|
|
|
|
if exists('restorewinnr')
|
|
|
|
wincmd p
|
|
|
|
endif
|
|
|
|
execute 'tabnext '.mytab
|
|
|
|
endtry
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
if !exists('did')
|
|
|
|
call writefile(readfile(temp,'b'),file,'b')
|
|
|
|
endif
|
|
|
|
else
|
2018-08-13 00:08:59 -04:00
|
|
|
execute 'write! '.s:fnameescape(file)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if a:force
|
2018-08-13 00:08:59 -04:00
|
|
|
let error = s:TreeChomp('add', '--force', '--', file)
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2018-08-13 00:08:59 -04:00
|
|
|
let error = s:TreeChomp('add', '--', file)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
if v:shell_error
|
|
|
|
let v:errmsg = 'fugitive: '.error
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endif
|
2018-08-13 00:08:59 -04:00
|
|
|
if s:cpath(fugitive#Real(@%), file) && s:DirCommitFile(@%)[1] =~# '^\d$'
|
2018-06-01 13:46:22 -04:00
|
|
|
set nomodified
|
|
|
|
endif
|
|
|
|
|
2018-08-13 00:08:59 -04:00
|
|
|
let one = s:Generate(':1:'.file)
|
|
|
|
let two = s:Generate(':2:'.file)
|
|
|
|
let three = s:Generate(':3:'.file)
|
2018-06-01 13:46:22 -04:00
|
|
|
for nr in range(1,bufnr('$'))
|
|
|
|
let name = fnamemodify(bufname(nr), ':p')
|
|
|
|
if bufloaded(nr) && !getbufvar(nr,'&modified') && (name ==# one || name ==# two || name ==# three)
|
|
|
|
execute nr.'bdelete'
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
unlet! restorewinnr
|
2018-08-13 00:08:59 -04:00
|
|
|
let zero = s:Generate(':0:'.file)
|
2018-06-01 13:46:22 -04:00
|
|
|
silent execute 'doautocmd BufWritePost' s:fnameescape(zero)
|
|
|
|
for tab in range(1,tabpagenr('$'))
|
|
|
|
for winnr in range(1,tabpagewinnr(tab,'$'))
|
|
|
|
let bufnr = tabpagebuflist(tab)[winnr-1]
|
|
|
|
let bufname = fnamemodify(bufname(bufnr), ':p')
|
|
|
|
if bufname ==# zero && bufnr != mybufnr
|
|
|
|
execute 'tabnext '.tab
|
|
|
|
if winnr != winnr()
|
|
|
|
execute winnr.'wincmd w'
|
|
|
|
let restorewinnr = 1
|
|
|
|
endif
|
|
|
|
try
|
|
|
|
let lnum = line('.')
|
|
|
|
let last = line('$')
|
|
|
|
silent execute '$read '.s:fnameescape(file)
|
|
|
|
silent execute '1,'.last.'delete_'
|
|
|
|
silent execute lnum
|
|
|
|
set nomodified
|
|
|
|
diffupdate
|
|
|
|
finally
|
|
|
|
if exists('restorewinnr')
|
|
|
|
wincmd p
|
|
|
|
endif
|
|
|
|
execute 'tabnext '.mytab
|
|
|
|
endtry
|
|
|
|
break
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endfor
|
|
|
|
call fugitive#ReloadStatus()
|
|
|
|
return 'checktime'
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Wq(force,...) abort
|
|
|
|
let bang = a:force ? '!' : ''
|
|
|
|
if exists('b:fugitive_commit_arguments')
|
|
|
|
return 'wq'.bang
|
|
|
|
endif
|
|
|
|
let result = call(s:function('s:Write'),[a:force]+a:000)
|
|
|
|
if result =~# '^\%(write\|wq\|echoerr\)'
|
|
|
|
return s:sub(result,'^write','wq')
|
|
|
|
else
|
|
|
|
return result.'|quit'.bang
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
augroup fugitive_commit
|
|
|
|
autocmd!
|
|
|
|
autocmd VimLeavePre,BufDelete COMMIT_EDITMSG execute s:sub(s:FinishCommit(), '^echoerr (.*)', 'echohl ErrorMsg|echo \1|echohl NONE')
|
|
|
|
augroup END
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gpush, :Gfetch
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
call s:command("-nargs=? -bang -complete=custom,s:RemoteComplete Gpush execute s:Dispatch('<bang>', 'push '.<q-args>)")
|
|
|
|
call s:command("-nargs=? -bang -complete=custom,s:RemoteComplete Gfetch execute s:Dispatch('<bang>', 'fetch '.<q-args>)")
|
|
|
|
|
|
|
|
function! s:Dispatch(bang, args)
|
|
|
|
let [mp, efm, cc] = [&l:mp, &l:efm, get(b:, 'current_compiler', '')]
|
|
|
|
try
|
2018-12-16 22:13:12 -05:00
|
|
|
let cdback = s:Cd(s:Tree())
|
2018-06-01 13:46:22 -04:00
|
|
|
let b:current_compiler = 'git'
|
|
|
|
let &l:errorformat = s:common_efm
|
2018-08-03 22:50:32 -04:00
|
|
|
let &l:makeprg = substitute(s:UserCommand() . ' ' . a:args, '\s\+$', '', '')
|
2018-06-01 13:46:22 -04:00
|
|
|
if exists(':Make') == 2
|
|
|
|
noautocmd Make
|
|
|
|
else
|
|
|
|
silent noautocmd make!
|
|
|
|
redraw!
|
2018-06-01 13:47:48 -04:00
|
|
|
return 'call fugitive#Cwindow()'
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
finally
|
|
|
|
let [&l:mp, &l:efm, b:current_compiler] = [mp, efm, cc]
|
|
|
|
if empty(cc) | unlet! b:current_compiler | endif
|
2018-12-16 22:13:12 -05:00
|
|
|
execute cdback
|
2018-06-01 13:46:22 -04:00
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gdiff
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-07-28 19:09:05 -04:00
|
|
|
call s:command("-bang -bar -nargs=* -complete=customlist,fugitive#Complete Gdiff :execute s:Diff('',<bang>0,<f-args>)")
|
|
|
|
call s:command("-bang -bar -nargs=* -complete=customlist,fugitive#Complete Gvdiff :execute s:Diff('keepalt vert ',<bang>0,<f-args>)")
|
|
|
|
call s:command("-bang -bar -nargs=* -complete=customlist,fugitive#Complete Gsdiff :execute s:Diff('keepalt ',<bang>0,<f-args>)")
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
augroup fugitive_diff
|
|
|
|
autocmd!
|
|
|
|
autocmd BufWinLeave *
|
|
|
|
\ if s:can_diffoff(+expand('<abuf>')) && s:diff_window_count() == 2 |
|
|
|
|
\ call s:diffoff_all(getbufvar(+expand('<abuf>'), 'git_dir')) |
|
|
|
|
\ endif
|
|
|
|
autocmd BufWinEnter *
|
|
|
|
\ if s:can_diffoff(+expand('<abuf>')) && s:diff_window_count() == 1 |
|
|
|
|
\ call s:diffoff() |
|
|
|
|
\ endif
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
function! s:can_diffoff(buf) abort
|
|
|
|
return getwinvar(bufwinnr(a:buf), '&diff') &&
|
|
|
|
\ !empty(getbufvar(a:buf, 'git_dir')) &&
|
|
|
|
\ !empty(getwinvar(bufwinnr(a:buf), 'fugitive_diff_restore'))
|
|
|
|
endfunction
|
|
|
|
|
2018-06-01 13:47:48 -04:00
|
|
|
function! fugitive#CanDiffoff(buf) abort
|
2018-06-01 13:46:22 -04:00
|
|
|
return s:can_diffoff(a:buf)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:diff_modifier(count) abort
|
|
|
|
let fdc = matchstr(&diffopt, 'foldcolumn:\zs\d\+')
|
|
|
|
if &diffopt =~# 'horizontal' && &diffopt !~# 'vertical'
|
|
|
|
return 'keepalt '
|
|
|
|
elseif &diffopt =~# 'vertical'
|
|
|
|
return 'keepalt vert '
|
|
|
|
elseif winwidth(0) <= a:count * ((&tw ? &tw : 80) + (empty(fdc) ? 2 : fdc))
|
|
|
|
return 'keepalt '
|
|
|
|
else
|
|
|
|
return 'keepalt vert '
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:diff_window_count() abort
|
|
|
|
let c = 0
|
|
|
|
for nr in range(1,winnr('$'))
|
|
|
|
let c += getwinvar(nr,'&diff')
|
|
|
|
endfor
|
|
|
|
return c
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:diff_restore() abort
|
|
|
|
let restore = 'setlocal nodiff noscrollbind'
|
|
|
|
\ . ' scrollopt=' . &l:scrollopt
|
|
|
|
\ . (&l:wrap ? ' wrap' : ' nowrap')
|
|
|
|
\ . ' foldlevel=999'
|
|
|
|
\ . ' foldmethod=' . &l:foldmethod
|
|
|
|
\ . ' foldcolumn=' . &l:foldcolumn
|
|
|
|
\ . ' foldlevel=' . &l:foldlevel
|
|
|
|
\ . (&l:foldenable ? ' foldenable' : ' nofoldenable')
|
|
|
|
if has('cursorbind')
|
|
|
|
let restore .= (&l:cursorbind ? ' ' : ' no') . 'cursorbind'
|
|
|
|
endif
|
|
|
|
return restore
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:diffthis() abort
|
|
|
|
if !&diff
|
|
|
|
let w:fugitive_diff_restore = s:diff_restore()
|
|
|
|
diffthis
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:diffoff() abort
|
|
|
|
if exists('w:fugitive_diff_restore')
|
|
|
|
execute w:fugitive_diff_restore
|
|
|
|
unlet w:fugitive_diff_restore
|
|
|
|
else
|
|
|
|
diffoff
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:diffoff_all(dir) abort
|
|
|
|
let curwin = winnr()
|
|
|
|
for nr in range(1,winnr('$'))
|
|
|
|
if getwinvar(nr,'&diff')
|
|
|
|
if nr != winnr()
|
|
|
|
execute nr.'wincmd w'
|
|
|
|
let restorewinnr = 1
|
|
|
|
endif
|
|
|
|
if exists('b:git_dir') && b:git_dir ==# a:dir
|
|
|
|
call s:diffoff()
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
execute curwin.'wincmd w'
|
|
|
|
endfunction
|
|
|
|
|
2018-07-19 00:34:04 -04:00
|
|
|
function! s:CompareAge(mine, theirs) abort
|
2018-06-01 13:46:22 -04:00
|
|
|
let scores = {':0': 1, ':1': 2, ':2': 3, ':': 4, ':3': 5}
|
2018-07-19 00:34:04 -04:00
|
|
|
let mine = substitute(a:mine, '^:', '', '')
|
|
|
|
let theirs = substitute(a:theirs, '^:', '', '')
|
|
|
|
let my_score = get(scores, ':'.mine, 0)
|
|
|
|
let their_score = get(scores, ':'.theirs, 0)
|
2018-06-01 13:46:22 -04:00
|
|
|
if my_score || their_score
|
|
|
|
return my_score < their_score ? -1 : my_score != their_score
|
2018-07-19 00:34:04 -04:00
|
|
|
elseif mine ==# theirs
|
2018-06-01 13:46:22 -04:00
|
|
|
return 0
|
|
|
|
endif
|
2018-07-22 13:56:21 -04:00
|
|
|
let base = s:TreeChomp('merge-base', mine, theirs)
|
2018-07-19 00:34:04 -04:00
|
|
|
if base ==# mine
|
2018-06-01 13:46:22 -04:00
|
|
|
return -1
|
2018-07-19 00:34:04 -04:00
|
|
|
elseif base ==# theirs
|
2018-06-01 13:46:22 -04:00
|
|
|
return 1
|
|
|
|
endif
|
2018-08-13 00:08:59 -04:00
|
|
|
let my_time = +s:TreeChomp('log', '--max-count=1', '--pretty=format:%at', a:mine, '--')
|
|
|
|
let their_time = +s:TreeChomp('log', '--max-count=1', '--pretty=format:%at', a:theirs, '--')
|
2018-06-01 13:46:22 -04:00
|
|
|
return my_time < their_time ? -1 : my_time != their_time
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Diff(vert,keepfocus,...) abort
|
|
|
|
let args = copy(a:000)
|
|
|
|
let post = ''
|
|
|
|
if get(args, 0) =~# '^+'
|
|
|
|
let post = remove(args, 0)[1:-1]
|
|
|
|
endif
|
|
|
|
let vert = empty(a:vert) ? s:diff_modifier(2) : a:vert
|
2018-07-22 14:18:59 -04:00
|
|
|
let commit = s:DirCommitFile(@%)[1]
|
2018-07-27 00:35:27 -04:00
|
|
|
let back = exists('*win_getid') ? 'call win_gotoid(' . win_getid() . ')' : 'wincmd p'
|
2018-06-01 13:46:22 -04:00
|
|
|
if exists(':DiffGitCached')
|
|
|
|
return 'DiffGitCached'
|
2018-08-13 00:08:59 -04:00
|
|
|
elseif (empty(args) || args[0] ==# ':') && commit =~# '^[0-1]\=$' && !empty(s:TreeChomp('ls-files', '--unmerged', '--', expand('%:p')))
|
2018-08-06 11:13:30 -04:00
|
|
|
if v:shell_error
|
2018-08-13 00:08:59 -04:00
|
|
|
return 'echoerr ' . string("fugitive: error determining merge status of the current buffer")
|
2018-08-06 11:13:30 -04:00
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
let vert = empty(a:vert) ? s:diff_modifier(3) : a:vert
|
|
|
|
let nr = bufnr('')
|
2018-07-22 14:18:59 -04:00
|
|
|
execute 'leftabove '.vert.'split' s:fnameescape(s:Generate(s:Relative(':2:')))
|
2018-06-01 13:46:22 -04:00
|
|
|
execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>'
|
|
|
|
let nr2 = bufnr('')
|
|
|
|
call s:diffthis()
|
2018-07-27 00:35:27 -04:00
|
|
|
exe back
|
2018-07-22 14:18:59 -04:00
|
|
|
execute 'rightbelow '.vert.'split' s:fnameescape(s:Generate(s:Relative(':3:')))
|
2018-06-01 13:46:22 -04:00
|
|
|
execute 'nnoremap <buffer> <silent> dp :diffput '.nr.'<Bar>diffupdate<CR>'
|
|
|
|
let nr3 = bufnr('')
|
|
|
|
call s:diffthis()
|
2018-07-27 00:35:27 -04:00
|
|
|
exe back
|
2018-06-01 13:46:22 -04:00
|
|
|
call s:diffthis()
|
|
|
|
execute 'nnoremap <buffer> <silent> d2o :diffget '.nr2.'<Bar>diffupdate<CR>'
|
|
|
|
execute 'nnoremap <buffer> <silent> d3o :diffget '.nr3.'<Bar>diffupdate<CR>'
|
|
|
|
return post
|
|
|
|
elseif len(args)
|
|
|
|
let arg = join(args, ' ')
|
|
|
|
if arg ==# ''
|
|
|
|
return post
|
|
|
|
elseif arg ==# '/'
|
2018-08-13 00:08:59 -04:00
|
|
|
let file = s:Relative()
|
2018-06-01 13:46:22 -04:00
|
|
|
elseif arg ==# ':'
|
2018-07-22 14:18:59 -04:00
|
|
|
let file = s:Relative(':0:')
|
2018-06-01 13:46:22 -04:00
|
|
|
elseif arg =~# '^:/.'
|
|
|
|
try
|
2018-07-28 20:24:15 -04:00
|
|
|
let file = fugitive#RevParse(arg).s:Relative(':')
|
2018-06-01 13:46:22 -04:00
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
|
|
|
else
|
2018-07-27 00:19:44 -04:00
|
|
|
let file = s:Expand(arg)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-22 13:56:21 -04:00
|
|
|
if file !~# ':' && file !~# '^/' && s:TreeChomp('cat-file','-t',file) =~# '^\%(tag\|commit\)$'
|
2018-07-22 14:18:59 -04:00
|
|
|
let file = file.s:Relative(':')
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
else
|
2018-08-13 00:08:59 -04:00
|
|
|
let file = empty(commit) ? s:Relative(':0:') : s:Relative()
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
try
|
2018-07-22 01:29:49 -04:00
|
|
|
let spec = s:Generate(file)
|
2018-06-01 13:46:22 -04:00
|
|
|
let restore = s:diff_restore()
|
|
|
|
if exists('+cursorbind')
|
|
|
|
setlocal cursorbind
|
|
|
|
endif
|
|
|
|
let w:fugitive_diff_restore = restore
|
2018-07-22 14:18:59 -04:00
|
|
|
if s:CompareAge(commit, s:DirCommitFile(spec)[1]) < 0
|
2018-06-01 13:46:22 -04:00
|
|
|
execute 'rightbelow '.vert.'diffsplit '.s:fnameescape(spec)
|
|
|
|
else
|
|
|
|
execute 'leftabove '.vert.'diffsplit '.s:fnameescape(spec)
|
|
|
|
endif
|
|
|
|
let &l:readonly = &l:readonly
|
|
|
|
redraw
|
|
|
|
let w:fugitive_diff_restore = restore
|
|
|
|
let winnr = winnr()
|
|
|
|
if getwinvar('#', '&diff')
|
2018-07-27 00:35:27 -04:00
|
|
|
exe back
|
2018-06-01 13:46:22 -04:00
|
|
|
if !a:keepfocus
|
|
|
|
call feedkeys(winnr."\<C-W>w", 'n')
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
return post
|
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gmove, :Gremove
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
function! s:Move(force, rename, destination) abort
|
2018-08-15 19:24:35 -04:00
|
|
|
if a:destination =~# '^\.\.\=\%(/\|$\)'
|
|
|
|
let destination = simplify(getcwd() . '/' . a:destination)
|
|
|
|
elseif a:destination =~# '^\a\+:\|^/'
|
|
|
|
let destination = a:destination
|
2018-08-10 22:01:43 -04:00
|
|
|
elseif a:destination =~# '^:/:\='
|
2018-08-15 19:24:35 -04:00
|
|
|
let destination = s:Tree() . substitute(a:destination, '^:/:\=', '', '')
|
|
|
|
elseif a:destination =~# '^:(\%(top\|top,literal\|literal,top\))'
|
|
|
|
let destination = s:Tree() . matchstr(a:destination, ')\zs.*')
|
|
|
|
elseif a:destination =~# '^:(literal)'
|
|
|
|
let destination = simplify(getcwd() . '/' . matchstr(a:destination, ')\zs.*'))
|
|
|
|
elseif a:rename
|
|
|
|
let destination = expand('%:p:s?[\/]$??:h') . '/' . a:destination
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2018-08-15 19:24:35 -04:00
|
|
|
let destination = s:Tree() . '/' . a:destination
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-08-15 19:24:35 -04:00
|
|
|
let destination = s:Slash(destination)
|
2018-07-24 20:44:06 -04:00
|
|
|
if isdirectory(@%)
|
2018-07-19 00:34:04 -04:00
|
|
|
setlocal noswapfile
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-08-13 00:08:59 -04:00
|
|
|
let message = call('s:TreeChomp', ['mv'] + (a:force ? ['-f'] : []) + ['--', expand('%:p'), destination])
|
2018-06-01 13:46:22 -04:00
|
|
|
if v:shell_error
|
|
|
|
let v:errmsg = 'fugitive: '.message
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endif
|
|
|
|
if isdirectory(destination)
|
|
|
|
let destination = fnamemodify(s:sub(destination,'/$','').'/'.expand('%:t'),':.')
|
|
|
|
endif
|
|
|
|
call fugitive#ReloadStatus()
|
2018-07-24 01:27:55 -04:00
|
|
|
if empty(s:DirCommitFile(@%)[1])
|
2018-06-01 13:46:22 -04:00
|
|
|
if isdirectory(destination)
|
|
|
|
return 'keepalt edit '.s:fnameescape(destination)
|
|
|
|
else
|
|
|
|
return 'keepalt saveas! '.s:fnameescape(destination)
|
|
|
|
endif
|
|
|
|
else
|
2018-07-22 01:29:49 -04:00
|
|
|
return 'file '.s:fnameescape(s:Generate(':0:'.destination))
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:RenameComplete(A,L,P) abort
|
2018-08-10 18:46:19 -04:00
|
|
|
if a:A =~# '^[.:]\=/'
|
2018-07-28 19:09:05 -04:00
|
|
|
return fugitive#PathComplete(a:A)
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2018-08-13 00:08:59 -04:00
|
|
|
let pre = s:Slash(fnamemodify(expand('%:p:s?[\/]$??'), ':h')) . '/'
|
2018-07-28 19:09:05 -04:00
|
|
|
return map(fugitive#PathComplete(pre.a:A), 'strpart(v:val, len(pre))')
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:Remove(after, force) abort
|
2018-07-24 01:27:55 -04:00
|
|
|
if s:DirCommitFile(@%)[1] ==# ''
|
2018-06-01 13:46:22 -04:00
|
|
|
let cmd = ['rm']
|
2018-07-24 01:27:55 -04:00
|
|
|
elseif s:DirCommitFile(@%)[1] ==# '0'
|
2018-06-01 13:46:22 -04:00
|
|
|
let cmd = ['rm','--cached']
|
|
|
|
else
|
|
|
|
let v:errmsg = 'fugitive: rm not supported here'
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endif
|
|
|
|
if a:force
|
|
|
|
let cmd += ['--force']
|
|
|
|
endif
|
2018-08-13 00:08:59 -04:00
|
|
|
let message = call('s:TreeChomp', cmd + ['--', expand('%:p')])
|
2018-06-01 13:46:22 -04:00
|
|
|
if v:shell_error
|
|
|
|
let v:errmsg = 'fugitive: '.s:sub(message,'error:.*\zs\n\(.*-f.*',' (add ! to force)')
|
|
|
|
return 'echoerr '.string(v:errmsg)
|
|
|
|
else
|
|
|
|
call fugitive#ReloadStatus()
|
|
|
|
return a:after . (a:force ? '!' : '')
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
augroup fugitive_remove
|
|
|
|
autocmd!
|
2018-07-24 01:27:55 -04:00
|
|
|
autocmd User Fugitive if s:DirCommitFile(@%)[1] =~# '^0\=$' |
|
2018-07-28 19:09:05 -04:00
|
|
|
\ exe "command! -buffer -bar -bang -nargs=1 -complete=customlist,fugitive#PathComplete Gmove :execute s:Move(<bang>0,0,<q-args>)" |
|
2018-06-01 13:46:22 -04:00
|
|
|
\ exe "command! -buffer -bar -bang -nargs=1 -complete=customlist,s:RenameComplete Grename :execute s:Move(<bang>0,1,<q-args>)" |
|
|
|
|
\ exe "command! -buffer -bar -bang Gremove :execute s:Remove('edit',<bang>0)" |
|
|
|
|
\ exe "command! -buffer -bar -bang Gdelete :execute s:Remove('bdelete',<bang>0)" |
|
|
|
|
\ endif
|
|
|
|
augroup END
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gblame
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-07-19 00:34:04 -04:00
|
|
|
function! s:Keywordprg() abort
|
|
|
|
let args = ' --git-dir='.escape(b:git_dir,"\\\"' ")
|
|
|
|
if has('gui_running') && !has('win32')
|
2018-07-27 00:19:44 -04:00
|
|
|
return s:UserCommand() . ' --no-pager' . args . ' log -1'
|
2018-07-19 00:34:04 -04:00
|
|
|
else
|
2018-07-27 00:19:44 -04:00
|
|
|
return s:UserCommand() . args . ' show'
|
2018-07-19 00:34:04 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-06-01 13:46:22 -04:00
|
|
|
augroup fugitive_blame
|
|
|
|
autocmd!
|
2018-07-19 00:34:04 -04:00
|
|
|
autocmd FileType fugitiveblame setlocal nomodeline | if exists('b:git_dir') | let &l:keywordprg = s:Keywordprg() | endif
|
2018-06-01 13:46:22 -04:00
|
|
|
autocmd Syntax fugitiveblame call s:BlameSyntax()
|
2018-07-25 00:29:03 -04:00
|
|
|
autocmd User Fugitive
|
2018-07-27 08:54:18 -04:00
|
|
|
\ if get(b:, 'fugitive_type') =~# '^\%(file\|blob\|blame\)$' || filereadable(@%) |
|
2018-07-25 00:29:03 -04:00
|
|
|
\ exe "command! -buffer -bar -bang -range=0 -nargs=* Gblame :execute s:Blame(<bang>0,<line1>,<line2>,<count>,'<mods>',[<f-args>])" |
|
|
|
|
\ endif
|
2018-06-01 13:46:22 -04:00
|
|
|
autocmd ColorScheme,GUIEnter * call s:RehighlightBlame()
|
|
|
|
autocmd BufWinLeave * execute getwinvar(+bufwinnr(+expand('<abuf>')), 'fugitive_leave')
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
function! s:linechars(pattern) abort
|
|
|
|
let chars = strlen(s:gsub(matchstr(getline('.'), a:pattern), '.', '.'))
|
|
|
|
if exists('*synconcealed') && &conceallevel > 1
|
|
|
|
for col in range(1, chars)
|
|
|
|
let chars -= synconcealed(line('.'), col)[0]
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
return chars
|
|
|
|
endfunction
|
|
|
|
|
2018-07-25 00:29:03 -04:00
|
|
|
function! s:Blame(bang, line1, line2, count, mods, args) abort
|
2018-06-01 13:46:22 -04:00
|
|
|
if exists('b:fugitive_blamed_bufnr')
|
|
|
|
return 'bdelete'
|
|
|
|
endif
|
|
|
|
try
|
2018-08-13 00:08:59 -04:00
|
|
|
if empty(s:Relative('/'))
|
2018-06-01 13:46:22 -04:00
|
|
|
call s:throw('file or blob required')
|
|
|
|
endif
|
2018-11-18 04:16:08 -05:00
|
|
|
if filter(copy(a:args),'v:val !~# "^\\%(--first-parent\\|--root\\|--show-name\\|-\\=\\%([ltfnsew]\\|[MC]\\d*\\)\\+\\)$"') != []
|
2018-06-01 13:46:22 -04:00
|
|
|
call s:throw('unsupported option')
|
|
|
|
endif
|
|
|
|
call map(a:args,'s:sub(v:val,"^\\ze[^-]","-")')
|
2018-07-25 00:29:03 -04:00
|
|
|
let cmd = ['--no-pager', 'blame', '--show-number']
|
|
|
|
if a:count
|
|
|
|
let cmd += ['-L', a:line1 . ',' . a:line1]
|
|
|
|
endif
|
|
|
|
let cmd += a:args
|
2018-07-24 01:27:55 -04:00
|
|
|
if s:DirCommitFile(@%)[1] =~# '\D\|..'
|
|
|
|
let cmd += [s:DirCommitFile(@%)[1]]
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
|
|
|
let cmd += ['--contents', '-']
|
|
|
|
endif
|
2018-08-31 15:36:44 -04:00
|
|
|
let cmd += ['--', expand('%:p')]
|
|
|
|
let basecmd = escape(fugitive#Prepare(cmd), '!#%')
|
2018-06-01 13:46:22 -04:00
|
|
|
try
|
2018-12-16 22:13:12 -05:00
|
|
|
let cd = s:Cd()
|
2018-07-27 00:56:21 -04:00
|
|
|
let tree = s:Tree()
|
2018-12-16 22:13:12 -05:00
|
|
|
let cdback = s:Cd(tree)
|
2018-07-25 00:29:03 -04:00
|
|
|
if len(tree) && s:cpath(tree) !=# s:cpath(getcwd())
|
|
|
|
let cwd = getcwd()
|
|
|
|
execute cd s:fnameescape(tree)
|
|
|
|
endif
|
2018-08-18 23:12:09 -04:00
|
|
|
let error = tempname()
|
2018-07-25 00:29:03 -04:00
|
|
|
let temp = error.'.fugitiveblame'
|
|
|
|
if &shell =~# 'csh'
|
|
|
|
silent! execute '%write !('.basecmd.' > '.temp.') >& '.error
|
|
|
|
else
|
|
|
|
silent! execute '%write !'.basecmd.' > '.temp.' 2> '.error
|
|
|
|
endif
|
|
|
|
if exists('l:cwd')
|
|
|
|
execute cd s:fnameescape(cwd)
|
|
|
|
unlet cwd
|
|
|
|
endif
|
|
|
|
if v:shell_error
|
|
|
|
call s:throw(join(readfile(error),"\n"))
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
if a:count
|
2018-07-25 00:29:03 -04:00
|
|
|
let edit = substitute(a:mods, '^<mods>$', '', '') . get(['edit', 'split', 'pedit'], a:line2 - a:line1, ' split')
|
|
|
|
return s:BlameCommit(edit, get(readfile(temp), 0, ''))
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
|
|
|
for winnr in range(winnr('$'),1,-1)
|
|
|
|
call setwinvar(winnr, '&scrollbind', 0)
|
|
|
|
if exists('+cursorbind')
|
|
|
|
call setwinvar(winnr, '&cursorbind', 0)
|
|
|
|
endif
|
|
|
|
if getbufvar(winbufnr(winnr), 'fugitive_blamed_bufnr')
|
|
|
|
execute winbufnr(winnr).'bdelete'
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
let bufnr = bufnr('')
|
|
|
|
let restore = 'call setwinvar(bufwinnr('.bufnr.'),"&scrollbind",0)'
|
|
|
|
if exists('+cursorbind')
|
|
|
|
let restore .= '|call setwinvar(bufwinnr('.bufnr.'),"&cursorbind",0)'
|
|
|
|
endif
|
|
|
|
if &l:wrap
|
|
|
|
let restore .= '|call setwinvar(bufwinnr('.bufnr.'),"&wrap",1)'
|
|
|
|
endif
|
|
|
|
if &l:foldenable
|
|
|
|
let restore .= '|call setwinvar(bufwinnr('.bufnr.'),"&foldenable",1)'
|
|
|
|
endif
|
|
|
|
setlocal scrollbind nowrap nofoldenable
|
|
|
|
if exists('+cursorbind')
|
|
|
|
setlocal cursorbind
|
|
|
|
endif
|
|
|
|
let top = line('w0') + &scrolloff
|
|
|
|
let current = line('.')
|
2018-08-18 23:12:09 -04:00
|
|
|
let temp = s:Resolve(temp)
|
2018-08-03 22:50:32 -04:00
|
|
|
let s:temp_files[s:cpath(temp)] = { 'dir': b:git_dir, 'filetype': 'fugitiveblame', 'args': cmd, 'bufnr': bufnr }
|
2018-06-01 13:46:22 -04:00
|
|
|
exe 'keepalt leftabove vsplit '.temp
|
|
|
|
let b:fugitive_blamed_bufnr = bufnr
|
2018-07-18 19:28:45 -04:00
|
|
|
let b:fugitive_type = 'blame'
|
2018-06-01 13:46:22 -04:00
|
|
|
let w:fugitive_leave = restore
|
|
|
|
let b:fugitive_blame_arguments = join(a:args,' ')
|
|
|
|
execute top
|
|
|
|
normal! zt
|
|
|
|
execute current
|
|
|
|
if exists('+cursorbind')
|
|
|
|
setlocal cursorbind
|
|
|
|
endif
|
2018-06-06 20:13:59 -04:00
|
|
|
setlocal nomodified nomodifiable nonumber scrollbind nowrap foldcolumn=0 nofoldenable winfixwidth filetype=fugitiveblame buftype=nowrite
|
2018-06-01 13:46:22 -04:00
|
|
|
if exists('+concealcursor')
|
|
|
|
setlocal concealcursor=nc conceallevel=2
|
|
|
|
endif
|
|
|
|
if exists('+relativenumber')
|
|
|
|
setlocal norelativenumber
|
|
|
|
endif
|
|
|
|
execute "vertical resize ".(s:linechars('.\{-\}\ze\s\+\d\+)')+1)
|
|
|
|
nnoremap <buffer> <silent> <F1> :help fugitive-:Gblame<CR>
|
|
|
|
nnoremap <buffer> <silent> g? :help fugitive-:Gblame<CR>
|
|
|
|
nnoremap <buffer> <silent> q :exe substitute(bufwinnr(b:fugitive_blamed_bufnr).' wincmd w<Bar>'.bufnr('').'bdelete','^-1','','')<CR>
|
|
|
|
nnoremap <buffer> <silent> gq :exe substitute(bufwinnr(b:fugitive_blamed_bufnr).' wincmd w<Bar>'.bufnr('').'bdelete<Bar>if expand("%:p") =~# "^fugitive:[\\/][\\/]"<Bar>Gedit<Bar>endif','^-1','','')<CR>
|
|
|
|
nnoremap <buffer> <silent> <CR> :<C-U>exe <SID>BlameCommit("exe 'norm q'<Bar>edit")<CR>
|
|
|
|
nnoremap <buffer> <silent> - :<C-U>exe <SID>BlameJump('')<CR>
|
|
|
|
nnoremap <buffer> <silent> P :<C-U>exe <SID>BlameJump('^'.v:count1)<CR>
|
|
|
|
nnoremap <buffer> <silent> ~ :<C-U>exe <SID>BlameJump('~'.v:count1)<CR>
|
|
|
|
nnoremap <buffer> <silent> i :<C-U>exe <SID>BlameCommit("exe 'norm q'<Bar>edit")<CR>
|
|
|
|
nnoremap <buffer> <silent> o :<C-U>exe <SID>BlameCommit((&splitbelow ? "botright" : "topleft")." split")<CR>
|
|
|
|
nnoremap <buffer> <silent> O :<C-U>exe <SID>BlameCommit("tabedit")<CR>
|
2018-07-27 00:19:44 -04:00
|
|
|
nnoremap <buffer> <silent> p :<C-U>exe <SID>Edit((&splitbelow ? "botright" : "topleft").' pedit', 0, '', matchstr(getline('.'), '\x\+'), matchstr(getline('.'), '\x\+'))<CR>
|
2018-06-01 13:46:22 -04:00
|
|
|
nnoremap <buffer> <silent> A :<C-u>exe "vertical resize ".(<SID>linechars('.\{-\}\ze [0-9:/+-][0-9:/+ -]* \d\+)')+1+v:count)<CR>
|
|
|
|
nnoremap <buffer> <silent> C :<C-u>exe "vertical resize ".(<SID>linechars('^\S\+')+1+v:count)<CR>
|
|
|
|
nnoremap <buffer> <silent> D :<C-u>exe "vertical resize ".(<SID>linechars('.\{-\}\ze\d\ze\s\+\d\+)')+1-v:count)<CR>
|
|
|
|
redraw
|
|
|
|
syncbind
|
|
|
|
endif
|
|
|
|
finally
|
2018-07-25 00:29:03 -04:00
|
|
|
if exists('l:cwd')
|
|
|
|
execute cd s:fnameescape(cwd)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endtry
|
|
|
|
return ''
|
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
2018-07-25 00:29:03 -04:00
|
|
|
function! s:BlameCommit(cmd, ...) abort
|
|
|
|
let line = a:0 ? a:1 : getline('.')
|
2018-07-25 00:17:12 -04:00
|
|
|
if line =~# '^0\{4,40\} '
|
|
|
|
return 'echoerr ' . string('Not Committed Yet')
|
|
|
|
endif
|
2018-07-27 00:19:44 -04:00
|
|
|
let cmd = s:Edit(a:cmd, 0, '', matchstr(line, '\x\+'), matchstr(line, '\x\+'))
|
2018-06-01 13:46:22 -04:00
|
|
|
if cmd =~# '^echoerr'
|
|
|
|
return cmd
|
|
|
|
endif
|
2018-07-25 00:17:12 -04:00
|
|
|
let lnum = matchstr(line, ' \zs\d\+\ze\s\+[([:digit:]]')
|
|
|
|
let path = matchstr(line, '^\^\=\x\+\s\+\zs.\{-\}\ze\s*\d\+ ')
|
2018-06-01 13:46:22 -04:00
|
|
|
if path ==# ''
|
2018-07-25 00:29:03 -04:00
|
|
|
let path = fugitive#Path(a:0 ? @% : bufname(b:fugitive_blamed_bufnr), '')
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
execute cmd
|
2018-07-25 00:29:03 -04:00
|
|
|
if a:cmd ==# 'pedit'
|
|
|
|
return ''
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
if search('^diff .* b/\M'.escape(path,'\').'$','W')
|
|
|
|
call search('^+++')
|
|
|
|
let head = line('.')
|
|
|
|
while search('^@@ \|^diff ') && getline('.') =~# '^@@ '
|
|
|
|
let top = +matchstr(getline('.'),' +\zs\d\+')
|
|
|
|
let len = +matchstr(getline('.'),' +\d\+,\zs\d\+')
|
|
|
|
if lnum >= top && lnum <= top + len
|
|
|
|
let offset = lnum - top
|
|
|
|
if &scrolloff
|
|
|
|
+
|
|
|
|
normal! zt
|
|
|
|
else
|
|
|
|
normal! zt
|
|
|
|
+
|
|
|
|
endif
|
|
|
|
while offset > 0 && line('.') < line('$')
|
|
|
|
+
|
|
|
|
if getline('.') =~# '^[ +]'
|
|
|
|
let offset -= 1
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
return 'normal! zv'
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
execute head
|
|
|
|
normal! zt
|
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:BlameJump(suffix) abort
|
|
|
|
let commit = matchstr(getline('.'),'^\^\=\zs\x\+')
|
|
|
|
if commit =~# '^0\+$'
|
|
|
|
let commit = ':0'
|
|
|
|
endif
|
|
|
|
let lnum = matchstr(getline('.'),' \zs\d\+\ze\s\+[([:digit:]]')
|
|
|
|
let path = matchstr(getline('.'),'^\^\=\x\+\s\+\zs.\{-\}\ze\s*\d\+ ')
|
|
|
|
if path ==# ''
|
2018-07-22 13:57:28 -04:00
|
|
|
let path = fugitive#Path(bufname(b:fugitive_blamed_bufnr), '')
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
let args = b:fugitive_blame_arguments
|
|
|
|
let offset = line('.') - line('w0')
|
|
|
|
let bufnr = bufnr('%')
|
|
|
|
let winnr = bufwinnr(b:fugitive_blamed_bufnr)
|
|
|
|
if winnr > 0
|
|
|
|
exe winnr.'wincmd w'
|
|
|
|
endif
|
2018-07-27 13:37:44 -04:00
|
|
|
execute 'Gedit' s:fnameescape(commit . a:suffix . ':' . path)
|
2018-06-01 13:46:22 -04:00
|
|
|
execute lnum
|
|
|
|
if winnr > 0
|
|
|
|
exe bufnr.'bdelete'
|
|
|
|
endif
|
|
|
|
if exists(':Gblame')
|
|
|
|
execute 'Gblame '.args
|
|
|
|
execute lnum
|
|
|
|
let delta = line('.') - line('w0') - offset
|
|
|
|
if delta > 0
|
|
|
|
execute 'normal! '.delta."\<C-E>"
|
|
|
|
elseif delta < 0
|
|
|
|
execute 'normal! '.(-delta)."\<C-Y>"
|
|
|
|
endif
|
|
|
|
syncbind
|
|
|
|
endif
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
let s:hash_colors = {}
|
|
|
|
|
|
|
|
function! s:BlameSyntax() abort
|
|
|
|
let b:current_syntax = 'fugitiveblame'
|
|
|
|
let conceal = has('conceal') ? ' conceal' : ''
|
|
|
|
let arg = exists('b:fugitive_blame_arguments') ? b:fugitive_blame_arguments : ''
|
|
|
|
syn match FugitiveblameBoundary "^\^"
|
|
|
|
syn match FugitiveblameBlank "^\s\+\s\@=" nextgroup=FugitiveblameAnnotation,fugitiveblameOriginalFile,FugitiveblameOriginalLineNumber skipwhite
|
|
|
|
syn match FugitiveblameHash "\%(^\^\=\)\@<=\<\x\{7,40\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite
|
|
|
|
syn match FugitiveblameUncommitted "\%(^\^\=\)\@<=\<0\{7,40\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite
|
|
|
|
syn region FugitiveblameAnnotation matchgroup=FugitiveblameDelimiter start="(" end="\%( \d\+\)\@<=)" contained keepend oneline
|
|
|
|
syn match FugitiveblameTime "[0-9:/+-][0-9:/+ -]*[0-9:/+-]\%( \+\d\+)\)\@=" contained containedin=FugitiveblameAnnotation
|
|
|
|
exec 'syn match FugitiveblameLineNumber " *\d\+)\@=" contained containedin=FugitiveblameAnnotation'.conceal
|
|
|
|
exec 'syn match FugitiveblameOriginalFile " \%(\f\+\D\@<=\|\D\@=\f\+\)\%(\%(\s\+\d\+\)\=\s\%((\|\s*\d\+)\)\)\@=" contained nextgroup=FugitiveblameOriginalLineNumber,FugitiveblameAnnotation skipwhite'.(arg =~# 'f' ? '' : conceal)
|
|
|
|
exec 'syn match FugitiveblameOriginalLineNumber " *\d\+\%(\s(\)\@=" contained nextgroup=FugitiveblameAnnotation skipwhite'.(arg =~# 'n' ? '' : conceal)
|
|
|
|
exec 'syn match FugitiveblameOriginalLineNumber " *\d\+\%(\s\+\d\+)\)\@=" contained nextgroup=FugitiveblameShort skipwhite'.(arg =~# 'n' ? '' : conceal)
|
|
|
|
syn match FugitiveblameShort " \d\+)" contained contains=FugitiveblameLineNumber
|
|
|
|
syn match FugitiveblameNotCommittedYet "(\@<=Not Committed Yet\>" contained containedin=FugitiveblameAnnotation
|
2018-07-29 14:24:05 -04:00
|
|
|
hi def link FugitiveblameBoundary Keyword
|
|
|
|
hi def link FugitiveblameHash Identifier
|
|
|
|
hi def link FugitiveblameUncommitted Ignore
|
|
|
|
hi def link FugitiveblameTime PreProc
|
|
|
|
hi def link FugitiveblameLineNumber Number
|
|
|
|
hi def link FugitiveblameOriginalFile String
|
|
|
|
hi def link FugitiveblameOriginalLineNumber Float
|
|
|
|
hi def link FugitiveblameShort FugitiveblameDelimiter
|
|
|
|
hi def link FugitiveblameDelimiter Delimiter
|
|
|
|
hi def link FugitiveblameNotCommittedYet Comment
|
|
|
|
let seen = {}
|
|
|
|
for lnum in range(1, line('$'))
|
|
|
|
let hash = matchstr(getline(lnum), '^\^\=\zs\x\{6\}')
|
|
|
|
if hash ==# '' || hash ==# '000000' || has_key(seen, hash)
|
|
|
|
continue
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
let seen[hash] = 1
|
|
|
|
if &t_Co > 16 && get(g:, 'CSApprox_loaded') && !empty(findfile('autoload/csapprox/per_component.vim', escape(&rtp, ' ')))
|
|
|
|
\ && empty(get(s:hash_colors, hash))
|
|
|
|
let [s, r, g, b; __] = map(matchlist(hash, '\(\x\x\)\(\x\x\)\(\x\x\)'), 'str2nr(v:val,16)')
|
|
|
|
let color = csapprox#per_component#Approximate(r, g, b)
|
|
|
|
if color == 16 && &background ==# 'dark'
|
|
|
|
let color = 8
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
let s:hash_colors[hash] = ' ctermfg='.color
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2018-07-29 14:24:05 -04:00
|
|
|
let s:hash_colors[hash] = ''
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
exe 'syn match FugitiveblameHash'.hash.' "\%(^\^\=\)\@<='.hash.'\x\{1,34\}\>" nextgroup=FugitiveblameAnnotation,FugitiveblameOriginalLineNumber,fugitiveblameOriginalFile skipwhite'
|
|
|
|
endfor
|
|
|
|
call s:RehighlightBlame()
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-07-29 14:24:05 -04:00
|
|
|
function! s:RehighlightBlame() abort
|
|
|
|
for [hash, cterm] in items(s:hash_colors)
|
|
|
|
if !empty(cterm) || has('gui_running') || has('termguicolors') && &termguicolors
|
|
|
|
exe 'hi FugitiveblameHash'.hash.' guifg=#'.hash.get(s:hash_colors, hash, '')
|
|
|
|
else
|
|
|
|
exe 'hi link FugitiveblameHash'.hash.' Identifier'
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
endfor
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-08-06 02:01:32 -04:00
|
|
|
" Section: :Gbrowse
|
2018-07-29 14:24:05 -04:00
|
|
|
|
|
|
|
call s:command("-bar -bang -range=0 -nargs=* -complete=customlist,fugitive#Complete Gbrowse :execute s:Browse(<bang>0,<line1>,<count>,<f-args>)")
|
|
|
|
|
|
|
|
let s:redirects = {}
|
|
|
|
|
|
|
|
function! s:Browse(bang,line1,count,...) abort
|
2018-06-01 13:46:22 -04:00
|
|
|
try
|
2018-07-29 14:24:05 -04:00
|
|
|
let validremote = '\.\|\.\=/.*\|[[:alnum:]_-]\+\%(://.\{-\}\)\='
|
|
|
|
if a:0
|
|
|
|
let remote = matchstr(join(a:000, ' '),'@\zs\%('.validremote.'\)$')
|
|
|
|
let rev = substitute(join(a:000, ' '),'@\%('.validremote.'\)$','','')
|
|
|
|
else
|
|
|
|
let remote = ''
|
|
|
|
let rev = ''
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
if rev ==# ''
|
2018-07-31 15:16:03 -04:00
|
|
|
let rev = s:DirRev(@%)[1]
|
2018-07-31 02:42:14 -04:00
|
|
|
endif
|
|
|
|
if rev =~# '^:\=$'
|
2018-08-13 00:08:59 -04:00
|
|
|
let expanded = s:Relative()
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2018-07-29 14:24:05 -04:00
|
|
|
let expanded = s:Expand(rev)
|
2018-07-22 22:37:28 -04:00
|
|
|
endif
|
2018-07-28 21:08:56 -04:00
|
|
|
let cdir = fugitive#CommonDir(b:git_dir)
|
2018-07-31 15:16:03 -04:00
|
|
|
for dir in ['tags/', 'heads/', 'remotes/']
|
2018-07-31 19:44:03 -04:00
|
|
|
if expanded !~# '^[./]' && filereadable(cdir . '/refs/' . dir . expanded)
|
2018-08-13 00:08:59 -04:00
|
|
|
let expanded = '.git/refs/' . dir . expanded
|
2018-07-31 15:16:03 -04:00
|
|
|
endif
|
|
|
|
endfor
|
2018-07-29 14:24:05 -04:00
|
|
|
let full = s:Generate(expanded)
|
|
|
|
let commit = ''
|
|
|
|
if full =~? '^fugitive:'
|
|
|
|
let [dir, commit, path] = s:DirCommitFile(full)
|
|
|
|
if commit =~# '^:\=\d$'
|
|
|
|
let commit = ''
|
2018-07-22 22:37:28 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
if commit =~ '..'
|
|
|
|
let type = s:TreeChomp('cat-file','-t',commit.s:sub(path,'^/',':'))
|
|
|
|
let branch = matchstr(expanded, '^[^:]*')
|
|
|
|
else
|
|
|
|
let type = 'blob'
|
2018-07-22 22:37:28 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
let path = path[1:-1]
|
|
|
|
elseif empty(s:Tree())
|
|
|
|
let path = '.git/' . full[strlen(b:git_dir)+1:-1]
|
|
|
|
let type = ''
|
2018-07-22 22:37:28 -04:00
|
|
|
else
|
2018-07-29 14:24:05 -04:00
|
|
|
let path = full[strlen(s:Tree())+1:-1]
|
|
|
|
if path =~# '^\.git/'
|
|
|
|
let type = ''
|
|
|
|
elseif isdirectory(full)
|
|
|
|
let type = 'tree'
|
|
|
|
else
|
|
|
|
let type = 'blob'
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-17 00:11:07 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
if type ==# 'tree' && !empty(path)
|
|
|
|
let path = s:sub(path, '/\=$', '/')
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-08-07 15:33:19 -04:00
|
|
|
if path =~# '^\.git/.*HEAD$' && filereadable(b:git_dir . '/' . path[5:-1])
|
2018-07-29 14:24:05 -04:00
|
|
|
let body = readfile(b:git_dir . '/' . path[5:-1])[0]
|
|
|
|
if body =~# '^\x\{40\}$'
|
|
|
|
let commit = body
|
|
|
|
let type = 'commit'
|
|
|
|
let path = ''
|
|
|
|
elseif body =~# '^ref: refs/'
|
|
|
|
let path = '.git/' . matchstr(body,'ref: \zs.*')
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
|
|
|
|
let merge = ''
|
|
|
|
if path =~# '^\.git/refs/remotes/.'
|
|
|
|
if empty(remote)
|
|
|
|
let remote = matchstr(path, '^\.git/refs/remotes/\zs[^/]\+')
|
|
|
|
let branch = matchstr(path, '^\.git/refs/remotes/[^/]\+/\zs.\+')
|
|
|
|
else
|
|
|
|
let merge = matchstr(path, '^\.git/refs/remotes/[^/]\+/\zs.\+')
|
|
|
|
let path = '.git/refs/heads/'.merge
|
|
|
|
endif
|
|
|
|
elseif path =~# '^\.git/refs/heads/.'
|
|
|
|
let branch = path[16:-1]
|
|
|
|
elseif !exists('branch')
|
|
|
|
let branch = FugitiveHead()
|
|
|
|
endif
|
|
|
|
if !empty(branch)
|
|
|
|
let r = fugitive#Config('branch.'.branch.'.remote')
|
|
|
|
let m = fugitive#Config('branch.'.branch.'.merge')[11:-1]
|
|
|
|
if r ==# '.' && !empty(m)
|
|
|
|
let r2 = fugitive#Config('branch.'.m.'.remote')
|
|
|
|
if r2 !~# '^\.\=$'
|
|
|
|
let r = r2
|
|
|
|
let m = fugitive#Config('branch.'.m.'.merge')[11:-1]
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if empty(remote)
|
|
|
|
let remote = r
|
|
|
|
endif
|
|
|
|
if r ==# '.' || r ==# remote
|
|
|
|
let merge = m
|
|
|
|
if path =~# '^\.git/refs/heads/.'
|
|
|
|
let path = '.git/refs/heads/'.merge
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2018-07-31 17:26:39 -04:00
|
|
|
let line1 = a:count > 0 ? a:line1 : 0
|
|
|
|
let line2 = a:count > 0 ? a:count : 0
|
2018-07-29 14:24:05 -04:00
|
|
|
if empty(commit) && path !~# '^\.git/'
|
|
|
|
if a:line1 && !a:count && !empty(merge)
|
|
|
|
let commit = merge
|
|
|
|
else
|
2018-07-31 17:26:39 -04:00
|
|
|
let commit = ''
|
|
|
|
if len(merge)
|
2018-09-19 17:37:06 -04:00
|
|
|
let owner = s:Owner(@%)
|
|
|
|
let commit = s:TreeChomp('merge-base', 'refs/remotes/' . remote . '/' . merge, empty(owner) ? 'HEAD' : owner, '--')
|
|
|
|
if v:shell_error
|
|
|
|
let commit = ''
|
|
|
|
endif
|
2018-07-31 17:26:39 -04:00
|
|
|
if a:count && !a:0 && commit =~# '^\x\{40\}$'
|
2018-08-18 23:12:09 -04:00
|
|
|
let blame_list = tempname()
|
2018-07-31 17:26:39 -04:00
|
|
|
call writefile([commit, ''], blame_list, 'b')
|
2018-08-18 23:12:09 -04:00
|
|
|
let blame_in = tempname()
|
2018-08-01 14:14:25 -04:00
|
|
|
silent exe '%write' blame_in
|
2018-08-13 00:08:59 -04:00
|
|
|
let blame = split(s:TreeChomp('blame', '--contents', blame_in, '-L', a:line1.','.a:count, '-S', blame_list, '-s', '--show-number', './' . path), "\n")
|
2018-07-31 17:26:39 -04:00
|
|
|
if !v:shell_error
|
|
|
|
let blame_regex = '^\^\x\+\s\+\zs\d\+\ze\s'
|
|
|
|
if get(blame, 0) =~# blame_regex && get(blame, -1) =~# blame_regex
|
|
|
|
let line1 = +matchstr(blame[0], blame_regex)
|
|
|
|
let line2 = +matchstr(blame[-1], blame_regex)
|
|
|
|
else
|
|
|
|
call s:throw("Can't browse to uncommitted change")
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if empty(commit)
|
2018-07-28 20:24:15 -04:00
|
|
|
let commit = readfile(b:git_dir . '/HEAD', '', 1)[0]
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
2018-07-31 17:26:39 -04:00
|
|
|
let i = 0
|
|
|
|
while commit =~# '^ref: ' && i < 10
|
|
|
|
let commit = readfile(cdir . '/' . commit[5:-1], '', 1)[0]
|
|
|
|
let i -= 1
|
|
|
|
endwhile
|
2018-07-21 16:52:06 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
|
|
|
|
if empty(remote)
|
|
|
|
let remote = '.'
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
let raw = fugitive#RemoteUrl(remote)
|
|
|
|
if empty(raw)
|
|
|
|
let raw = remote
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
|
2018-07-29 14:24:05 -04:00
|
|
|
if raw =~# '^https\=://' && s:executable('curl')
|
|
|
|
if !has_key(s:redirects, raw)
|
|
|
|
let s:redirects[raw] = matchstr(system('curl -I ' .
|
|
|
|
\ s:shellesc(raw . '/info/refs?service=git-upload-pack')),
|
|
|
|
\ 'Location: \zs\S\+\ze/info/refs?')
|
|
|
|
endif
|
|
|
|
if len(s:redirects[raw])
|
|
|
|
let raw = s:redirects[raw]
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
|
2018-07-29 14:24:05 -04:00
|
|
|
let opts = {
|
|
|
|
\ 'dir': b:git_dir,
|
2018-07-28 20:26:31 -04:00
|
|
|
\ 'repo': fugitive#repo(),
|
2018-07-29 14:24:05 -04:00
|
|
|
\ 'remote': raw,
|
|
|
|
\ 'revision': 'No longer provided',
|
|
|
|
\ 'commit': commit,
|
|
|
|
\ 'path': path,
|
|
|
|
\ 'type': type,
|
2018-07-31 17:26:39 -04:00
|
|
|
\ 'line1': line1,
|
|
|
|
\ 'line2': line2}
|
2018-06-01 13:46:22 -04:00
|
|
|
|
2018-09-13 10:51:08 -04:00
|
|
|
let url = ''
|
2018-07-29 14:24:05 -04:00
|
|
|
for Handler in get(g:, 'fugitive_browse_handlers', [])
|
|
|
|
let url = call(Handler, [copy(opts)])
|
|
|
|
if !empty(url)
|
|
|
|
break
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
endfor
|
|
|
|
|
|
|
|
if empty(url)
|
|
|
|
call s:throw("No Gbrowse handler found for '".raw."'")
|
|
|
|
endif
|
|
|
|
|
|
|
|
let url = s:gsub(url, '[ <>]', '\="%".printf("%02X",char2nr(submatch(0)))')
|
|
|
|
if a:bang
|
|
|
|
if has('clipboard')
|
|
|
|
let @+ = url
|
2018-07-17 00:11:07 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
return 'echomsg '.string(url)
|
|
|
|
elseif exists(':Browse') == 2
|
|
|
|
return 'echomsg '.string(url).'|Browse '.url
|
|
|
|
else
|
|
|
|
if !exists('g:loaded_netrw')
|
|
|
|
runtime! autoload/netrw.vim
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
if exists('*netrw#BrowseX')
|
|
|
|
return 'echomsg '.string(url).'|call netrw#BrowseX('.string(url).', 0)'
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
2018-07-29 14:24:05 -04:00
|
|
|
return 'echomsg '.string(url).'|call netrw#NetrwBrowseX('.string(url).', 0)'
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Section: Go to file
|
|
|
|
|
|
|
|
nnoremap <SID>: :<C-U><C-R>=v:count ? v:count : ''<CR>
|
2018-06-20 14:24:35 -04:00
|
|
|
function! fugitive#MapCfile(...) abort
|
2018-07-26 21:53:43 -04:00
|
|
|
exe 'cnoremap <buffer> <expr> <Plug><cfile>' (a:0 ? a:1 : 'fugitive#Cfile()')
|
|
|
|
let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') . '|sil! exe "cunmap <buffer> <Plug><cfile>"'
|
2018-06-01 13:46:22 -04:00
|
|
|
if !exists('g:fugitive_no_maps')
|
2018-07-26 21:53:43 -04:00
|
|
|
call s:map('n', 'gf', '<SID>:find <Plug><cfile><CR>', '<silent><unique>', 1)
|
|
|
|
call s:map('n', '<C-W>f', '<SID>:sfind <Plug><cfile><CR>', '<silent><unique>', 1)
|
|
|
|
call s:map('n', '<C-W><C-F>', '<SID>:sfind <Plug><cfile><CR>', '<silent><unique>', 1)
|
|
|
|
call s:map('n', '<C-W>gf', '<SID>:tabfind <Plug><cfile><CR>', '<silent><unique>', 1)
|
|
|
|
call s:map('c', '<C-R><C-F>', '<Plug><cfile>', '<silent><unique>', 1)
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-07-19 00:34:04 -04:00
|
|
|
function! s:ContainingCommit() abort
|
2018-08-07 15:33:19 -04:00
|
|
|
let commit = s:Owner(@%)
|
|
|
|
return empty(commit) ? 'HEAD' : commit
|
2018-07-19 00:34:04 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-12-19 16:39:55 -05:00
|
|
|
function! s:SquashArgument() abort
|
2018-12-25 14:07:17 -05:00
|
|
|
if &filetype == 'fugitive'
|
2018-12-31 00:15:10 -05:00
|
|
|
return matchstr(getline('.'), '^\%(\%(\x\x\x\)\@!\l\+\s\+\)\=\zs[0-9a-f]\{4,\}\ze ')
|
2018-12-25 14:07:17 -05:00
|
|
|
else
|
|
|
|
return s:Owner(@%)
|
|
|
|
endif
|
2018-12-19 16:39:55 -05:00
|
|
|
endfunction
|
|
|
|
|
2018-07-24 20:44:50 -04:00
|
|
|
function! s:NavigateUp(count) abort
|
2018-07-31 02:42:14 -04:00
|
|
|
let rev = substitute(s:DirRev(@%)[1], '^$', ':', 'g')
|
2018-07-21 20:37:56 -04:00
|
|
|
let c = a:count
|
|
|
|
while c
|
2018-07-29 14:22:33 -04:00
|
|
|
if rev =~# ':.*/.'
|
|
|
|
let rev = matchstr(rev, '.*\ze/.\+', '')
|
|
|
|
elseif rev =~# '.:.'
|
|
|
|
let rev = matchstr(rev, '^.[^:]*:')
|
2018-07-21 20:37:56 -04:00
|
|
|
elseif rev =~# '^:'
|
2018-07-29 14:22:33 -04:00
|
|
|
let rev = 'HEAD^{}'
|
2018-07-21 20:37:56 -04:00
|
|
|
elseif rev =~# ':$'
|
|
|
|
let rev = rev[0:-2]
|
|
|
|
else
|
|
|
|
return rev.'~'.c
|
|
|
|
endif
|
|
|
|
let c -= 1
|
|
|
|
endwhile
|
|
|
|
return rev
|
|
|
|
endfunction
|
|
|
|
|
2018-06-20 14:24:35 -04:00
|
|
|
function! fugitive#MapJumps(...) abort
|
2018-07-25 00:29:03 -04:00
|
|
|
if get(b:, 'fugitive_type', '') ==# 'blob'
|
|
|
|
nnoremap <buffer> <silent> <CR> :<C-U>.Gblame<CR>
|
|
|
|
else
|
|
|
|
nnoremap <buffer> <silent> <CR> :<C-U>exe <SID>GF("edit")<CR>
|
|
|
|
endif
|
2018-06-01 13:46:22 -04:00
|
|
|
if !&modifiable
|
2018-08-11 02:36:53 -04:00
|
|
|
let nowait = v:version >= 704 ? '<nowait>' : ''
|
2018-07-25 00:29:03 -04:00
|
|
|
if get(b:, 'fugitive_type', '') ==# 'blob'
|
|
|
|
nnoremap <buffer> <silent> o :<C-U>.,.+1Gblame<CR>
|
2018-12-25 19:35:13 -05:00
|
|
|
nnoremap <buffer> <silent> S :<C-U>echoerr 'Use gO'<CR>
|
|
|
|
nnoremap <buffer> <silent> gO :<C-U>vertical .,.+1Gblame<CR>
|
2018-07-25 00:29:03 -04:00
|
|
|
nnoremap <buffer> <silent> O :<C-U>tab .,.+1Gblame<CR>
|
|
|
|
nnoremap <buffer> <silent> p :<C-U>.,.+2Gblame<CR>
|
|
|
|
else
|
|
|
|
nnoremap <buffer> <silent> o :<C-U>exe <SID>GF("split")<CR>
|
2018-12-25 19:35:13 -05:00
|
|
|
nnoremap <buffer> <silent> S :<C-U>echoerr 'Use gO'<CR>
|
|
|
|
nnoremap <buffer> <silent> gO :<C-U>exe <SID>GF("vsplit")<CR>
|
2018-07-25 00:29:03 -04:00
|
|
|
nnoremap <buffer> <silent> O :<C-U>exe <SID>GF("tabedit")<CR>
|
|
|
|
nnoremap <buffer> <silent> p :<C-U>exe <SID>GF("pedit")<CR>
|
|
|
|
endif
|
2018-08-11 02:36:53 -04:00
|
|
|
exe "nnoremap <buffer> <silent>" nowait "- :<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>NavigateUp(v:count1))<Bar> if getline(1) =~# '^tree \x\{40\}$' && empty(getline(2))<Bar>call search('^'.escape(expand('#:t'),'.*[]~\').'/\=$','wc')<Bar>endif<CR>"
|
2018-07-27 13:37:44 -04:00
|
|
|
nnoremap <buffer> <silent> P :<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>ContainingCommit().'^'.v:count1.<SID>Relative(':'))<CR>
|
|
|
|
nnoremap <buffer> <silent> ~ :<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>ContainingCommit().'~'.v:count1.<SID>Relative(':'))<CR>
|
|
|
|
nnoremap <buffer> <silent> C :<C-U>exe 'Gedit ' . <SID>fnameescape(<SID>ContainingCommit())<CR>
|
2019-01-01 17:10:05 -05:00
|
|
|
nnoremap <buffer> <silent> cc :<C-U>echoerr 'Use C'<CR>
|
|
|
|
nnoremap <buffer> <silent> co :<C-U>echoerr 'Use CTRL-W C'<CR>
|
|
|
|
nnoremap <buffer> <silent> <C-W>C :<C-U>exe 'Gsplit ' . <SID>fnameescape(<SID>ContainingCommit())<CR>
|
|
|
|
nnoremap <buffer> <silent> cp :<C-U>echoerr 'Use gC'<CR>
|
|
|
|
nnoremap <buffer> <silent> gC :<C-U>exe 'Gpedit ' . <SID>fnameescape(<SID>ContainingCommit())<CR>
|
|
|
|
nnoremap <buffer> <silent> gc :<C-U>exe 'Gpedit ' . <SID>fnameescape(<SID>ContainingCommit())<CR>
|
2018-12-19 16:39:55 -05:00
|
|
|
nnoremap <buffer> cf :<C-U>Gcommit --fixup=<C-R>=<SID>SquashArgument()<CR>
|
|
|
|
nnoremap <buffer> cs :<C-U>Gcommit --squash=<C-R>=<SID>SquashArgument()<CR>
|
|
|
|
nnoremap <buffer> cA :<C-U>Gcommit --edit --squash=<C-R>=<SID>SquashArgument()<CR>
|
2018-08-10 19:20:12 -04:00
|
|
|
nmap <buffer> . <SID>: <Plug><cfile><Home>
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-07-26 21:53:43 -04:00
|
|
|
function! s:StatusCfile(...) abort
|
2018-12-25 14:07:17 -05:00
|
|
|
let tree = FugitiveTreeForGitDir(b:git_dir)
|
|
|
|
let lead = s:cpath(tree, getcwd()) ? './' : tree . '/'
|
2019-01-03 00:19:21 -05:00
|
|
|
let info = s:StageInfo()
|
2018-12-25 14:07:17 -05:00
|
|
|
let line = getline('.')
|
2019-01-03 00:19:21 -05:00
|
|
|
if len(info.sigil) && len(info.section) && len(info.filename)
|
|
|
|
if info.section ==# 'Unstaged' && info.sigil !=# '-'
|
|
|
|
return [lead . info.filename, info.offset, 'normal!zv']
|
|
|
|
elseif info.section ==# 'Staged' && info.sigil ==# '-'
|
|
|
|
return ['@:' . info.filename, info.offset, 'normal!zv']
|
|
|
|
else
|
|
|
|
return [':0:' . info.filename, info.offset, 'normal!zv']
|
|
|
|
endif
|
|
|
|
elseif len(info.filename)
|
|
|
|
return [lead . info.filename]
|
|
|
|
elseif len(info.commit)
|
|
|
|
return [info.commit]
|
2018-12-25 14:07:17 -05:00
|
|
|
elseif line =~# '^\%(Head\|Merge\|Rebase\|Upstream\|Pull\|Push\): '
|
2019-01-03 00:19:21 -05:00
|
|
|
return [matchstr(line, ' \zs.*')]
|
2018-12-25 14:07:17 -05:00
|
|
|
else
|
2019-01-03 00:19:21 -05:00
|
|
|
return ['']
|
2018-12-25 14:07:17 -05:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#StatusCfile() abort
|
2019-01-03 00:19:21 -05:00
|
|
|
let file = s:Generate(s:StatusCfile()[0])
|
2018-12-25 14:07:17 -05:00
|
|
|
return empty(file) ? fugitive#Cfile() : s:fnameescape(file)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:MessageCfile(...) abort
|
2018-08-10 19:20:12 -04:00
|
|
|
let tree = FugitiveTreeForGitDir(b:git_dir)
|
|
|
|
let lead = s:cpath(tree, getcwd()) ? './' : tree . '/'
|
2018-07-26 21:53:43 -04:00
|
|
|
if getline('.') =~# '^.\=\trenamed:.* -> '
|
2018-08-10 19:20:12 -04:00
|
|
|
return lead . matchstr(getline('.'),' -> \zs.*')
|
2018-07-26 21:53:43 -04:00
|
|
|
elseif getline('.') =~# '^.\=\t\(\k\| \)\+\p\?: *.'
|
2018-08-10 19:20:12 -04:00
|
|
|
return lead . matchstr(getline('.'),': *\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$')
|
2018-07-26 21:53:43 -04:00
|
|
|
elseif getline('.') =~# '^.\=\t.'
|
2018-08-10 19:20:12 -04:00
|
|
|
return lead . matchstr(getline('.'),'\t\zs.*')
|
2018-07-26 21:53:43 -04:00
|
|
|
elseif getline('.') =~# ': needs merge$'
|
2018-08-10 19:20:12 -04:00
|
|
|
return lead . matchstr(getline('.'),'.*\ze: needs merge$')
|
2018-07-26 21:53:43 -04:00
|
|
|
elseif getline('.') =~# '^\%(. \)\=Not currently on any branch.$'
|
|
|
|
return 'HEAD'
|
|
|
|
elseif getline('.') =~# '^\%(. \)\=On branch '
|
|
|
|
return 'refs/heads/'.getline('.')[12:]
|
|
|
|
elseif getline('.') =~# "^\\%(. \\)\=Your branch .*'"
|
|
|
|
return matchstr(getline('.'),"'\\zs\\S\\+\\ze'")
|
|
|
|
else
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-12-25 14:07:17 -05:00
|
|
|
function! fugitive#MessageCfile() abort
|
|
|
|
let file = s:Generate(s:MessageCfile())
|
2018-08-29 17:15:05 -04:00
|
|
|
return empty(file) ? fugitive#Cfile() : s:fnameescape(file)
|
2018-07-26 21:53:43 -04:00
|
|
|
endfunction
|
|
|
|
|
2018-07-25 16:08:59 -04:00
|
|
|
function! s:cfile() abort
|
2018-06-01 13:46:22 -04:00
|
|
|
try
|
2018-07-24 20:44:06 -04:00
|
|
|
let myhash = s:DirRev(@%)[1]
|
|
|
|
if len(myhash)
|
|
|
|
try
|
2018-07-28 20:24:15 -04:00
|
|
|
let myhash = fugitive#RevParse(myhash)
|
2018-07-24 20:44:06 -04:00
|
|
|
catch /^fugitive:/
|
|
|
|
let myhash = ''
|
|
|
|
endtry
|
2018-07-19 00:34:04 -04:00
|
|
|
endif
|
2018-07-24 20:44:06 -04:00
|
|
|
if empty(myhash) && getline(1) =~# '^\%(commit\|tag\) \w'
|
2018-06-01 13:46:22 -04:00
|
|
|
let myhash = matchstr(getline(1),'^\w\+ \zs\S\+')
|
|
|
|
endif
|
|
|
|
|
2018-07-29 14:22:33 -04:00
|
|
|
let showtree = (getline(1) =~# '^tree ' && getline(2) == "")
|
|
|
|
|
|
|
|
let treebase = substitute(s:DirCommitFile(@%)[1], '^\d$', ':&', '') . ':' .
|
|
|
|
\ s:Relative('') . (s:Relative('') =~# '^$\|/$' ? '' : '/')
|
|
|
|
|
|
|
|
if getline('.') =~# '^\d\{6\} \l\{3,8\} \x\{40\}\t'
|
2018-07-24 20:44:06 -04:00
|
|
|
return [treebase . s:sub(matchstr(getline('.'),'\t\zs.*'),'/$','')]
|
2018-07-29 14:22:33 -04:00
|
|
|
elseif showtree
|
2018-07-24 20:44:06 -04:00
|
|
|
return [treebase . s:sub(getline('.'),'/$','')]
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
let dcmds = []
|
|
|
|
|
|
|
|
" Index
|
|
|
|
if getline('.') =~# '^\d\{6\} \x\{40\} \d\t'
|
|
|
|
let ref = matchstr(getline('.'),'\x\{40\}')
|
|
|
|
let file = ':'.s:sub(matchstr(getline('.'),'\d\t.*'),'\t',':')
|
|
|
|
return [file]
|
|
|
|
endif
|
|
|
|
|
|
|
|
if getline('.') =~# '^ref: '
|
|
|
|
let ref = strpart(getline('.'),5)
|
|
|
|
|
|
|
|
elseif getline('.') =~# '^commit \x\{40\}\>'
|
|
|
|
let ref = matchstr(getline('.'),'\x\{40\}')
|
|
|
|
return [ref]
|
|
|
|
|
|
|
|
elseif getline('.') =~# '^parent \x\{40\}\>'
|
|
|
|
let ref = matchstr(getline('.'),'\x\{40\}')
|
|
|
|
let line = line('.')
|
|
|
|
let parent = 0
|
|
|
|
while getline(line) =~# '^parent '
|
|
|
|
let parent += 1
|
|
|
|
let line -= 1
|
|
|
|
endwhile
|
|
|
|
return [ref]
|
|
|
|
|
2018-07-29 14:22:33 -04:00
|
|
|
elseif getline('.') =~# '^tree \x\{40\}$'
|
2018-06-01 13:46:22 -04:00
|
|
|
let ref = matchstr(getline('.'),'\x\{40\}')
|
2018-07-28 20:24:15 -04:00
|
|
|
if len(myhash) && fugitive#RevParse(myhash.':') ==# ref
|
2018-06-01 13:46:22 -04:00
|
|
|
let ref = myhash.':'
|
|
|
|
endif
|
|
|
|
return [ref]
|
|
|
|
|
|
|
|
elseif getline('.') =~# '^object \x\{40\}$' && getline(line('.')+1) =~ '^type \%(commit\|tree\|blob\)$'
|
|
|
|
let ref = matchstr(getline('.'),'\x\{40\}')
|
|
|
|
let type = matchstr(getline(line('.')+1),'type \zs.*')
|
|
|
|
|
|
|
|
elseif getline('.') =~# '^\l\{3,8\} '.myhash.'$'
|
2018-07-31 02:42:14 -04:00
|
|
|
let ref = s:DirRev(@%)[1]
|
2018-06-01 13:46:22 -04:00
|
|
|
|
|
|
|
elseif getline('.') =~# '^\l\{3,8\} \x\{40\}\>'
|
|
|
|
let ref = matchstr(getline('.'),'\x\{40\}')
|
|
|
|
echoerr "warning: unknown context ".matchstr(getline('.'),'^\l*')
|
|
|
|
|
|
|
|
elseif getline('.') =~# '^[+-]\{3\} [abciow12]\=/'
|
|
|
|
let ref = getline('.')[4:]
|
|
|
|
|
2018-06-17 17:23:59 -04:00
|
|
|
elseif getline('.') =~# '^[+-]' && search('^@@ -\d\+\%(,\d\+\)\= +\d\+','bnW')
|
2018-06-01 13:46:22 -04:00
|
|
|
let type = getline('.')[0]
|
|
|
|
let lnum = line('.') - 1
|
|
|
|
let offset = 0
|
2018-06-17 17:23:59 -04:00
|
|
|
while getline(lnum) !~# '^@@ -\d\+\%(,\d\+\)\= +\d\+'
|
2018-06-01 13:46:22 -04:00
|
|
|
if getline(lnum) =~# '^[ '.type.']'
|
|
|
|
let offset += 1
|
|
|
|
endif
|
|
|
|
let lnum -= 1
|
|
|
|
endwhile
|
|
|
|
let offset += matchstr(getline(lnum), type.'\zs\d\+')
|
|
|
|
let ref = getline(search('^'.type.'\{3\} [abciow12]/','bnW'))[4:-1]
|
|
|
|
let dcmds = [offset, 'normal!zv']
|
|
|
|
|
|
|
|
elseif getline('.') =~# '^rename from '
|
|
|
|
let ref = 'a/'.getline('.')[12:]
|
|
|
|
elseif getline('.') =~# '^rename to '
|
|
|
|
let ref = 'b/'.getline('.')[10:]
|
|
|
|
|
2018-06-17 17:23:59 -04:00
|
|
|
elseif getline('.') =~# '^@@ -\d\+\%(,\d\+\)\= +\d\+'
|
2018-06-01 13:46:22 -04:00
|
|
|
let diff = getline(search('^diff --git \%([abciow12]/.*\|/dev/null\) \%([abciow12]/.*\|/dev/null\)', 'bcnW'))
|
|
|
|
let offset = matchstr(getline('.'), '+\zs\d\+')
|
|
|
|
|
|
|
|
let dref = matchstr(diff, '\Cdiff --git \zs\%([abciow12]/.*\|/dev/null\)\ze \%([abciow12]/.*\|/dev/null\)')
|
|
|
|
let ref = matchstr(diff, '\Cdiff --git \%([abciow12]/.*\|/dev/null\) \zs\%([abciow12]/.*\|/dev/null\)')
|
|
|
|
let dcmd = 'Gdiff! +'.offset
|
|
|
|
|
|
|
|
elseif getline('.') =~# '^diff --git \%([abciow12]/.*\|/dev/null\) \%([abciow12]/.*\|/dev/null\)'
|
|
|
|
let dref = matchstr(getline('.'),'\Cdiff --git \zs\%([abciow12]/.*\|/dev/null\)\ze \%([abciow12]/.*\|/dev/null\)')
|
|
|
|
let ref = matchstr(getline('.'),'\Cdiff --git \%([abciow12]/.*\|/dev/null\) \zs\%([abciow12]/.*\|/dev/null\)')
|
|
|
|
let dcmd = 'Gdiff!'
|
|
|
|
|
|
|
|
elseif getline('.') =~# '^index ' && getline(line('.')-1) =~# '^diff --git \%([abciow12]/.*\|/dev/null\) \%([abciow12]/.*\|/dev/null\)'
|
|
|
|
let line = getline(line('.')-1)
|
|
|
|
let dref = matchstr(line,'\Cdiff --git \zs\%([abciow12]/.*\|/dev/null\)\ze \%([abciow12]/.*\|/dev/null\)')
|
|
|
|
let ref = matchstr(line,'\Cdiff --git \%([abciow12]/.*\|/dev/null\) \zs\%([abciow12]/.*\|/dev/null\)')
|
|
|
|
let dcmd = 'Gdiff!'
|
|
|
|
|
|
|
|
elseif line('$') == 1 && getline('.') =~ '^\x\{40\}$'
|
|
|
|
let ref = getline('.')
|
|
|
|
|
|
|
|
elseif expand('<cword>') =~# '^\x\{7,40\}\>'
|
|
|
|
return [expand('<cword>')]
|
|
|
|
|
|
|
|
else
|
|
|
|
let ref = ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
let prefixes = {
|
|
|
|
\ '1': '',
|
|
|
|
\ '2': '',
|
|
|
|
\ 'b': ':0:',
|
|
|
|
\ 'i': ':0:',
|
|
|
|
\ 'o': '',
|
|
|
|
\ 'w': ''}
|
|
|
|
|
|
|
|
if len(myhash)
|
|
|
|
let prefixes.a = myhash.'^:'
|
|
|
|
let prefixes.b = myhash.':'
|
|
|
|
endif
|
|
|
|
let ref = substitute(ref, '^\(\w\)/', '\=get(prefixes, submatch(1), "HEAD:")', '')
|
|
|
|
if exists('dref')
|
|
|
|
let dref = substitute(dref, '^\(\w\)/', '\=get(prefixes, submatch(1), "HEAD:")', '')
|
|
|
|
endif
|
|
|
|
|
|
|
|
if ref ==# '/dev/null'
|
|
|
|
" Empty blob
|
|
|
|
let ref = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'
|
|
|
|
endif
|
|
|
|
|
|
|
|
if exists('dref')
|
|
|
|
return [ref, dcmd . ' ' . s:fnameescape(dref)] + dcmds
|
|
|
|
elseif ref != ""
|
|
|
|
return [ref] + dcmds
|
|
|
|
endif
|
|
|
|
|
|
|
|
endif
|
|
|
|
return []
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:GF(mode) abort
|
2018-07-25 16:08:59 -04:00
|
|
|
try
|
2019-01-03 00:19:21 -05:00
|
|
|
let results = &filetype ==# 'fugitive' ? s:StatusCfile() : &filetype ==# 'gitcommit' ? [s:MessageCfile()] : s:cfile()
|
2018-07-25 16:08:59 -04:00
|
|
|
catch /^fugitive:/
|
|
|
|
return 'echoerr v:errmsg'
|
|
|
|
endtry
|
2018-07-30 00:47:26 -04:00
|
|
|
if len(results) > 1
|
|
|
|
return 'G' . a:mode .
|
|
|
|
\ ' +' . escape(join(results[1:-1], '|'), '| ') . ' ' .
|
|
|
|
\ s:fnameescape(results[0])
|
2018-12-31 01:52:03 -05:00
|
|
|
elseif len(results) && len(results[0])
|
2018-07-30 00:47:26 -04:00
|
|
|
return 'G' . a:mode . ' ' . s:fnameescape(results[0])
|
2018-06-01 13:46:22 -04:00
|
|
|
else
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2018-07-25 16:08:59 -04:00
|
|
|
function! fugitive#Cfile() abort
|
2018-06-01 13:46:22 -04:00
|
|
|
let pre = ''
|
2018-07-25 16:08:59 -04:00
|
|
|
let results = s:cfile()
|
|
|
|
if empty(results)
|
2018-06-01 13:46:22 -04:00
|
|
|
let cfile = expand('<cfile>')
|
|
|
|
if &includeexpr =~# '\<v:fname\>'
|
|
|
|
sandbox let cfile = eval(substitute(&includeexpr, '\C\<v:fname\>', '\=string(cfile)', 'g'))
|
|
|
|
endif
|
2018-07-25 16:08:59 -04:00
|
|
|
return cfile
|
|
|
|
elseif len(results) > 1
|
|
|
|
let pre = '+' . join(map(results[1:-1], 'escape(v:val, " ")'), '\|') . ' '
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
2018-07-25 16:08:59 -04:00
|
|
|
return pre . s:fnameescape(s:Generate(results[0]))
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Section: Statusline
|
|
|
|
|
|
|
|
function! fugitive#Statusline(...) abort
|
|
|
|
if !exists('b:git_dir')
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
let status = ''
|
2018-07-24 01:27:55 -04:00
|
|
|
let commit = s:DirCommitFile(@%)[1]
|
|
|
|
if len(commit)
|
2018-09-24 17:04:06 -04:00
|
|
|
let status .= ':' . commit[0:6]
|
2018-06-01 13:46:22 -04:00
|
|
|
endif
|
|
|
|
let status .= '('.FugitiveHead(7).')'
|
2018-07-24 19:54:24 -04:00
|
|
|
return '[Git'.status.']'
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#statusline(...) abort
|
|
|
|
return fugitive#Statusline()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#head(...) abort
|
|
|
|
if !exists('b:git_dir')
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
|
2018-08-06 01:36:37 -04:00
|
|
|
return fugitive#Head(a:0 ? a:1 : 0)
|
2018-06-01 13:46:22 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Section: Folding
|
|
|
|
|
|
|
|
function! fugitive#Foldtext() abort
|
|
|
|
if &foldmethod !=# 'syntax'
|
|
|
|
return foldtext()
|
|
|
|
endif
|
|
|
|
|
|
|
|
let line_foldstart = getline(v:foldstart)
|
|
|
|
if line_foldstart =~# '^diff '
|
|
|
|
let [add, remove] = [-1, -1]
|
|
|
|
let filename = ''
|
|
|
|
for lnum in range(v:foldstart, v:foldend)
|
|
|
|
let line = getline(lnum)
|
|
|
|
if filename ==# '' && line =~# '^[+-]\{3\} [abciow12]/'
|
|
|
|
let filename = line[6:-1]
|
|
|
|
endif
|
|
|
|
if line =~# '^+'
|
|
|
|
let add += 1
|
|
|
|
elseif line =~# '^-'
|
|
|
|
let remove += 1
|
|
|
|
elseif line =~# '^Binary '
|
|
|
|
let binary = 1
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
if filename ==# ''
|
|
|
|
let filename = matchstr(line_foldstart, '^diff .\{-\} [abciow12]/\zs.*\ze [abciow12]/')
|
|
|
|
endif
|
|
|
|
if filename ==# ''
|
|
|
|
let filename = line_foldstart[5:-1]
|
|
|
|
endif
|
|
|
|
if exists('binary')
|
|
|
|
return 'Binary: '.filename
|
|
|
|
else
|
|
|
|
return (add<10&&remove<100?' ':'') . add . '+ ' . (remove<10&&add<100?' ':'') . remove . '- ' . filename
|
|
|
|
endif
|
|
|
|
elseif line_foldstart =~# '^# .*:$'
|
|
|
|
let lines = getline(v:foldstart, v:foldend)
|
|
|
|
call filter(lines, 'v:val =~# "^#\t"')
|
|
|
|
cal map(lines, "s:sub(v:val, '^#\t%(modified: +|renamed: +)=', '')")
|
|
|
|
cal map(lines, "s:sub(v:val, '^([[:alpha:] ]+): +(.*)', '\\2 (\\1)')")
|
|
|
|
return line_foldstart.' '.join(lines, ', ')
|
|
|
|
endif
|
|
|
|
return foldtext()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#foldtext() abort
|
|
|
|
return fugitive#Foldtext()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
augroup fugitive_folding
|
|
|
|
autocmd!
|
|
|
|
autocmd User Fugitive
|
|
|
|
\ if &filetype =~# '^git\%(commit\)\=$' && &foldtext ==# 'foldtext()' |
|
|
|
|
\ set foldtext=fugitive#Foldtext() |
|
|
|
|
\ endif
|
|
|
|
augroup END
|
2018-07-29 14:24:05 -04:00
|
|
|
|
|
|
|
" Section: Initialization
|
|
|
|
|
|
|
|
function! fugitive#Init() abort
|
|
|
|
if exists('#User#FugitiveBoot')
|
|
|
|
try
|
|
|
|
let [save_mls, &modelines] = [&mls, 0]
|
|
|
|
doautocmd User FugitiveBoot
|
|
|
|
finally
|
|
|
|
let &mls = save_mls
|
|
|
|
endtry
|
|
|
|
endif
|
|
|
|
if !exists('g:fugitive_no_maps')
|
2018-08-10 19:20:31 -04:00
|
|
|
call s:map('c', '<C-R><C-G>', '<SID>fnameescape(fugitive#Object(@%))', '<expr>')
|
|
|
|
call s:map('n', 'y<C-G>', ':<C-U>call setreg(v:register, fugitive#Object(@%))<CR>', '<silent>')
|
2018-07-29 14:24:05 -04:00
|
|
|
endif
|
|
|
|
if expand('%:p') =~# ':[\/][\/]'
|
|
|
|
let &l:path = s:sub(&path, '^\.%(,|$)', '')
|
|
|
|
endif
|
|
|
|
if stridx(&tags, escape(b:git_dir, ', ')) == -1
|
|
|
|
if filereadable(b:git_dir.'/tags')
|
|
|
|
let &l:tags = escape(b:git_dir.'/tags', ', ').','.&tags
|
|
|
|
endif
|
|
|
|
if &filetype !=# '' && filereadable(b:git_dir.'/'.&filetype.'.tags')
|
|
|
|
let &l:tags = escape(b:git_dir.'/'.&filetype.'.tags', ', ').','.&tags
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
try
|
|
|
|
let [save_mls, &modelines] = [&mls, 0]
|
|
|
|
call s:define_commands()
|
|
|
|
doautocmd User Fugitive
|
|
|
|
finally
|
|
|
|
let &mls = save_mls
|
|
|
|
endtry
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#is_git_dir(path) abort
|
|
|
|
return FugitiveIsGitDir(a:path)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#extract_git_dir(path) abort
|
|
|
|
return FugitiveExtractGitDir(a:path)
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! fugitive#detect(path) abort
|
|
|
|
return FugitiveDetect(a:path)
|
|
|
|
endfunction
|
2018-08-06 02:01:32 -04:00
|
|
|
|
|
|
|
" Section: End
|