Encapsulate b:git_dir
This commit is contained in:
parent
0171b2a5b0
commit
b44b7b8ae7
@ -222,8 +222,12 @@ function! fugitive#CommonDir(dir) abort
|
|||||||
return s:commondirs[a:dir]
|
return s:commondirs[a:dir]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:Dir(...) abort
|
||||||
|
return a:0 ? FugitiveGitDir(a:1) : FugitiveGitDir()
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:Tree(...) abort
|
function! s:Tree(...) abort
|
||||||
return FugitiveTreeForGitDir(a:0 ? a:1 : get(b:, 'git_dir', ''))
|
return a:0 ? FugitiveWorkTree(a:1) : FugitiveWorkTree()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:PreparePathArgs(cmd, dir, literal) abort
|
function! s:PreparePathArgs(cmd, dir, literal) abort
|
||||||
@ -267,7 +271,7 @@ function! fugitive#Prepare(...) abort
|
|||||||
if cmd[i] =~# '^$\|[\/.]' && cmd[i] !~# '^-'
|
if cmd[i] =~# '^$\|[\/.]' && cmd[i] !~# '^-'
|
||||||
let dir = remove(cmd, 0)
|
let dir = remove(cmd, 0)
|
||||||
elseif type(cmd[i]) ==# type(0)
|
elseif type(cmd[i]) ==# type(0)
|
||||||
let dir = getbufvar(remove(cmd, i), 'git_dir')
|
let dir = s:Dir(remove(cmd, i))
|
||||||
elseif cmd[i] ==# '-c' && len(cmd) > i + 1
|
elseif cmd[i] ==# '-c' && len(cmd) > i + 1
|
||||||
let key = matchstr(cmd[i+1], '^[^=]*')
|
let key = matchstr(cmd[i+1], '^[^=]*')
|
||||||
if has_key(s:prepare_env, tolower(key)) || key !~# '\.'
|
if has_key(s:prepare_env, tolower(key)) || key !~# '\.'
|
||||||
@ -298,7 +302,7 @@ function! fugitive#Prepare(...) abort
|
|||||||
endif
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
if !exists('dir')
|
if !exists('dir')
|
||||||
let dir = get(b:, 'git_dir', '')
|
let dir = s:Dir()
|
||||||
endif
|
endif
|
||||||
let tree = s:Tree(dir)
|
let tree = s:Tree(dir)
|
||||||
call s:PreparePathArgs(cmd, dir, !exists('explicit_pathspec_option'))
|
call s:PreparePathArgs(cmd, dir, !exists('explicit_pathspec_option'))
|
||||||
@ -318,7 +322,7 @@ function! s:TreeChomp(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#Head(...) abort
|
function! fugitive#Head(...) abort
|
||||||
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
let dir = a:0 > 1 ? a:2 : s:Dir()
|
||||||
if empty(dir) || !filereadable(dir . '/HEAD')
|
if empty(dir) || !filereadable(dir . '/HEAD')
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
@ -334,7 +338,7 @@ function! fugitive#Head(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#RevParse(rev, ...) abort
|
function! fugitive#RevParse(rev, ...) abort
|
||||||
let hash = system(s:Prepare(a:0 ? a:1 : b:git_dir, 'rev-parse', '--verify', a:rev, '--'))[0:-2]
|
let hash = system(s:Prepare(a:0 ? a:1 : s:Dir(), 'rev-parse', '--verify', a:rev, '--'))[0:-2]
|
||||||
if !v:shell_error && hash =~# '^\x\{40\}$'
|
if !v:shell_error && hash =~# '^\x\{40\}$'
|
||||||
return hash
|
return hash
|
||||||
endif
|
endif
|
||||||
@ -353,7 +357,7 @@ endfunction
|
|||||||
|
|
||||||
let s:config = {}
|
let s:config = {}
|
||||||
function! fugitive#Config(...) abort
|
function! fugitive#Config(...) abort
|
||||||
let dir = get(b:, 'git_dir', '')
|
let dir = s:Dir()
|
||||||
let name = ''
|
let name = ''
|
||||||
if a:0 >= 2 && type(a:2) == type({})
|
if a:0 >= 2 && type(a:2) == type({})
|
||||||
let name = substitute(a:1, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
let name = substitute(a:1, '^[^.]\+\|[^.]\+$', '\L&', 'g')
|
||||||
@ -404,7 +408,7 @@ function! s:Remote(dir) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#RemoteUrl(...) abort
|
function! fugitive#RemoteUrl(...) abort
|
||||||
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
let dir = a:0 > 1 ? a:2 : s:Dir()
|
||||||
let remote = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
let remote = !a:0 || a:1 =~# '^\.\=$' ? s:Remote(dir) : a:1
|
||||||
if !fugitive#GitVersion(2, 7)
|
if !fugitive#GitVersion(2, 7)
|
||||||
return fugitive#Config('remote.' . remote . '.url')
|
return fugitive#Config('remote.' . remote . '.url')
|
||||||
@ -437,7 +441,7 @@ let s:repo_prototype = {}
|
|||||||
let s:repos = {}
|
let s:repos = {}
|
||||||
|
|
||||||
function! fugitive#repo(...) abort
|
function! fugitive#repo(...) abort
|
||||||
let dir = a:0 ? a:1 : (exists('b:git_dir') && b:git_dir !=# '' ? b:git_dir : FugitiveExtractGitDir(expand('%:p')))
|
let dir = a:0 ? a:1 : (len(s:Dir()) ? s:Dir() : FugitiveExtractGitDir(expand('%:p')))
|
||||||
if dir !=# ''
|
if dir !=# ''
|
||||||
if has_key(s:repos, dir)
|
if has_key(s:repos, dir)
|
||||||
let repo = get(s:repos, dir)
|
let repo = get(s:repos, dir)
|
||||||
@ -549,7 +553,7 @@ function! s:DirRev(url) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Owner(path, ...) abort
|
function! s:Owner(path, ...) abort
|
||||||
let dir = a:0 ? a:1 : get(b:, 'git_dir', '')
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
if empty(dir)
|
if empty(dir)
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
@ -606,7 +610,7 @@ function! fugitive#Path(url, ...) abort
|
|||||||
if empty(a:url)
|
if empty(a:url)
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
let dir = a:0 > 1 ? a:2 : s:Dir()
|
||||||
let tree = s:Tree(dir)
|
let tree = s:Tree(dir)
|
||||||
if !a:0
|
if !a:0
|
||||||
return fugitive#Real(a:url)
|
return fugitive#Real(a:url)
|
||||||
@ -667,7 +671,7 @@ function! fugitive#Find(object, ...) abort
|
|||||||
elseif s:Slash(a:object) =~# '^\.\.\=\%(/\|$\)'
|
elseif s:Slash(a:object) =~# '^\.\.\=\%(/\|$\)'
|
||||||
return s:PlatformSlash(simplify(getcwd() . '/' . a:object))
|
return s:PlatformSlash(simplify(getcwd() . '/' . a:object))
|
||||||
endif
|
endif
|
||||||
let dir = a:0 ? a:1 : get(b:, 'git_dir', '')
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
if empty(dir)
|
if empty(dir)
|
||||||
let file = matchstr(a:object, '^\%(:\d:\|[^:]*:\)\zs.*', '', '')
|
let file = matchstr(a:object, '^\%(:\d:\|[^:]*:\)\zs.*', '', '')
|
||||||
let dir = FugitiveExtractGitDir(file)
|
let dir = FugitiveExtractGitDir(file)
|
||||||
@ -763,7 +767,7 @@ function! fugitive#Find(object, ...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Generate(rev, ...) abort
|
function! s:Generate(rev, ...) abort
|
||||||
let dir = a:0 ? a:1 : get(b:, 'git_dir', '')
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
let tree = s:Tree(dir)
|
let tree = s:Tree(dir)
|
||||||
let object = a:rev
|
let object = a:rev
|
||||||
if a:rev =~# '^/\.git\%(/\|$\)'
|
if a:rev =~# '^/\.git\%(/\|$\)'
|
||||||
@ -784,7 +788,7 @@ function! s:DotRelative(path) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#Object(...) abort
|
function! fugitive#Object(...) abort
|
||||||
let dir = a:0 > 1 ? a:2 : get(b:, 'git_dir', '')
|
let dir = a:0 > 1 ? a:2 : s:Dir()
|
||||||
let [fdir, rev] = s:DirRev(a:0 ? a:1 : @%)
|
let [fdir, rev] = s:DirRev(a:0 ? a:1 : @%)
|
||||||
if s:cpath(dir) !=# s:cpath(fdir)
|
if s:cpath(dir) !=# s:cpath(fdir)
|
||||||
let rev = ''
|
let rev = ''
|
||||||
@ -1223,7 +1227,7 @@ function! s:GlobComplete(lead, pattern) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#PathComplete(base, ...) abort
|
function! fugitive#PathComplete(base, ...) abort
|
||||||
let dir = a:0 == 1 ? a:1 : get(b:, 'git_dir', '')
|
let dir = a:0 == 1 ? a:1 : s:Dir()
|
||||||
let tree = s:Tree(dir) . '/'
|
let tree = s:Tree(dir) . '/'
|
||||||
let strip = '^\%(:/:\=\|:(top)\|:(top,literal)\|:(literal,top)\|:(literal)\)'
|
let strip = '^\%(:/:\=\|:(top)\|:(top,literal)\|:(literal,top)\|:(literal)\)'
|
||||||
let base = substitute(a:base, strip, '', '')
|
let base = substitute(a:base, strip, '', '')
|
||||||
@ -1250,7 +1254,7 @@ function! fugitive#PathComplete(base, ...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#Complete(base, ...) abort
|
function! fugitive#Complete(base, ...) abort
|
||||||
let dir = a:0 == 1 ? a:1 : get(b:, 'git_dir', '')
|
let dir = a:0 == 1 ? a:1 : s:Dir()
|
||||||
let cwd = a:0 == 1 ? s:Tree(dir) : getcwd()
|
let cwd = a:0 == 1 ? s:Tree(dir) : getcwd()
|
||||||
let tree = s:Tree(dir) . '/'
|
let tree = s:Tree(dir) . '/'
|
||||||
let subdir = ''
|
let subdir = ''
|
||||||
@ -1390,7 +1394,7 @@ function! fugitive#BufReadStatus() abort
|
|||||||
silent doautocmd BufReadPre
|
silent doautocmd BufReadPre
|
||||||
let cmd = [fnamemodify(amatch, ':h')]
|
let cmd = [fnamemodify(amatch, ':h')]
|
||||||
setlocal noro ma nomodeline buftype=nowrite
|
setlocal noro ma nomodeline buftype=nowrite
|
||||||
if s:cpath(fnamemodify($GIT_INDEX_FILE !=# '' ? $GIT_INDEX_FILE : b:git_dir . '/index', ':p')) !=# s:cpath(amatch)
|
if s:cpath(fnamemodify($GIT_INDEX_FILE !=# '' ? $GIT_INDEX_FILE : s:Dir() . '/index', ':p')) !=# s:cpath(amatch)
|
||||||
let cmd += ['-c', 'GIT_INDEX_FILE=' . amatch]
|
let cmd += ['-c', 'GIT_INDEX_FILE=' . amatch]
|
||||||
endif
|
endif
|
||||||
let cmd += ['status', '--porcelain', '-bz']
|
let cmd += ['status', '--porcelain', '-bz']
|
||||||
@ -1862,14 +1866,15 @@ endfunction
|
|||||||
|
|
||||||
let s:aliases = {}
|
let s:aliases = {}
|
||||||
function! s:Aliases() abort
|
function! s:Aliases() abort
|
||||||
if !has_key(s:aliases, b:git_dir)
|
let dir = s:Dir()
|
||||||
let s:aliases[b:git_dir] = {}
|
if !has_key(s:aliases, dir)
|
||||||
|
let s:aliases[dir] = {}
|
||||||
let lines = split(s:TreeChomp('config','-z','--get-regexp','^alias[.]'),"\1")
|
let lines = split(s:TreeChomp('config','-z','--get-regexp','^alias[.]'),"\1")
|
||||||
for line in v:shell_error ? [] : lines
|
for line in v:shell_error ? [] : lines
|
||||||
let s:aliases[b:git_dir][matchstr(line, '\.\zs.\{-}\ze\n')] = matchstr(line, '\n\zs.*')
|
let s:aliases[dir][matchstr(line, '\.\zs.\{-}\ze\n')] = matchstr(line, '\n\zs.*')
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
return s:aliases[b:git_dir]
|
return s:aliases[dir]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:GitComplete(A, L, P) abort
|
function! s:GitComplete(A, L, P) abort
|
||||||
@ -1878,9 +1883,9 @@ function! s:GitComplete(A, L, P) abort
|
|||||||
let cmds = s:Subcommands()
|
let cmds = s:Subcommands()
|
||||||
return filter(sort(cmds+keys(s:Aliases())), 'strpart(v:val, 0, strlen(a:A)) ==# a:A')
|
return filter(sort(cmds+keys(s:Aliases())), 'strpart(v:val, 0, strlen(a:A)) ==# a:A')
|
||||||
elseif pre =~# ' -- '
|
elseif pre =~# ' -- '
|
||||||
return fugitive#PathComplete(a:A, b:git_dir)
|
return fugitive#PathComplete(a:A, s:Dir())
|
||||||
else
|
else
|
||||||
return fugitive#Complete(a:A, b:git_dir)
|
return fugitive#Complete(a:A, s:Dir())
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -1895,7 +1900,7 @@ function! s:DirArg(path) abort
|
|||||||
if path =~# '^/\|^\a\+:\|^\.\.\=\%(/\|$\)'
|
if path =~# '^/\|^\a\+:\|^\.\.\=\%(/\|$\)'
|
||||||
return path
|
return path
|
||||||
else
|
else
|
||||||
return (empty(s:Tree()) ? b:git_dir : s:Tree()) . '/' . path
|
return (empty(s:Tree()) ? s:Dir() : s:Tree()) . '/' . path
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -2506,7 +2511,7 @@ function! s:StageDelete(lnum, count) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:DoToggleHeadHeader(value) abort
|
function! s:DoToggleHeadHeader(value) abort
|
||||||
exe 'edit' s:fnameescape(b:git_dir)
|
exe 'edit' s:fnameescape(s:Dir())
|
||||||
call search('\C^index$', 'wc')
|
call search('\C^index$', 'wc')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -2634,7 +2639,7 @@ call s:command("-nargs=? -complete=customlist,s:CommitComplete Gcommit :execute
|
|||||||
|
|
||||||
function! s:Commit(mods, args, ...) abort
|
function! s:Commit(mods, args, ...) abort
|
||||||
let mods = s:gsub(a:mods ==# '<mods>' ? '' : a:mods, '<tab>', '-tab')
|
let mods = s:gsub(a:mods ==# '<mods>' ? '' : a:mods, '<tab>', '-tab')
|
||||||
let dir = a:0 ? a:1 : b:git_dir
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
let tree = s:Tree(dir)
|
let tree = s:Tree(dir)
|
||||||
let msgfile = dir . '/COMMIT_EDITMSG'
|
let msgfile = dir . '/COMMIT_EDITMSG'
|
||||||
let outfile = tempname()
|
let outfile = tempname()
|
||||||
@ -2728,7 +2733,7 @@ function! s:CommitComplete(A,L,P) abort
|
|||||||
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']
|
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')
|
return filter(args,'v:val[0 : strlen(a:A)-1] ==# a:A')
|
||||||
else
|
else
|
||||||
return fugitive#PathComplete(a:A, b:git_dir)
|
return fugitive#PathComplete(a:A, s:Dir())
|
||||||
endif
|
endif
|
||||||
return []
|
return []
|
||||||
endfunction
|
endfunction
|
||||||
@ -2740,9 +2745,9 @@ function! s:FinishCommit() abort
|
|||||||
call setbufvar(buf, 'fugitive_commit_arguments', '')
|
call setbufvar(buf, 'fugitive_commit_arguments', '')
|
||||||
if getbufvar(buf, 'fugitive_commit_rebase')
|
if getbufvar(buf, 'fugitive_commit_rebase')
|
||||||
call setbufvar(buf, 'fugitive_commit_rebase', 0)
|
call setbufvar(buf, 'fugitive_commit_rebase', 0)
|
||||||
let s:rebase_continue = getbufvar(buf, 'git_dir')
|
let s:rebase_continue = s:Dir(buf)
|
||||||
endif
|
endif
|
||||||
return s:Commit('', args, getbufvar(buf, 'git_dir'))
|
return s:Commit('', args, s:Dir(buf))
|
||||||
endif
|
endif
|
||||||
return ''
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
@ -2824,7 +2829,7 @@ function! s:RebaseEdit(cmd, dir) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:Merge(cmd, bang, mods, args, ...) abort
|
function! s:Merge(cmd, bang, mods, args, ...) abort
|
||||||
let dir = a:0 ? a:1 : b:git_dir
|
let dir = a:0 ? a:1 : s:Dir()
|
||||||
let mods = substitute(a:mods, '\C<mods>', '', '') . ' '
|
let mods = substitute(a:mods, '\C<mods>', '', '') . ' '
|
||||||
if a:cmd =~# '^rebase' && ' '.a:args =~# ' -i\| --interactive'
|
if a:cmd =~# '^rebase' && ' '.a:args =~# ' -i\| --interactive'
|
||||||
let cmd = fugitive#Prepare(dir, '-c', 'sequence.editor=sh ' . s:RebaseSequenceAborter(), 'rebase') . ' ' . a:args
|
let cmd = fugitive#Prepare(dir, '-c', 'sequence.editor=sh ' . s:RebaseSequenceAborter(), 'rebase') . ' ' . a:args
|
||||||
@ -2974,9 +2979,9 @@ endif
|
|||||||
|
|
||||||
function! s:GrepComplete(A, L, P) abort
|
function! s:GrepComplete(A, L, P) abort
|
||||||
if strpart(a:L, 0, a:P) =~# ' -- '
|
if strpart(a:L, 0, a:P) =~# ' -- '
|
||||||
return fugitive#PathComplete(a:A, b:git_dir)
|
return fugitive#PathComplete(a:A, s:Dir())
|
||||||
else
|
else
|
||||||
return fugitive#Complete(a:A, b:git_dir)
|
return fugitive#Complete(a:A, s:Dir())
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@ -3054,7 +3059,7 @@ function! s:Log(cmd, bang, line1, line2, ...) abort
|
|||||||
let cdback = s:Cd(s:Tree())
|
let cdback = s:Cd(s:Tree())
|
||||||
let format = before =~# ' -g\| --walk-reflogs' ? '%gD %gs' : g:fugitive_summary_format
|
let format = before =~# ' -g\| --walk-reflogs' ? '%gD %gs' : g:fugitive_summary_format
|
||||||
let &grepprg = escape(s:UserCommand() . ' --no-pager log --no-color ' .
|
let &grepprg = escape(s:UserCommand() . ' --no-pager log --no-color ' .
|
||||||
\ s:shellesc('--pretty=format:fugitive://'.b:git_dir.'//%H'.path.'::'.format), '%#')
|
\ s:shellesc('--pretty=format:fugitive://'.s:Dir().'//%H'.path.'::'.format), '%#')
|
||||||
let &grepformat = '%Cdiff %.%#,%C--- %.%#,%C+++ %.%#,%Z@@ -%\d%\+\,%\d%\+ +%l\,%\d%\+ @@,%-G-%.%#,%-G+%.%#,%-G %.%#,%A%f::%m,%-G%.%#'
|
let &grepformat = '%Cdiff %.%#,%C--- %.%#,%C+++ %.%#,%Z@@ -%\d%\+\,%\d%\+ +%l\,%\d%\+ @@,%-G-%.%#,%-G+%.%#,%-G %.%#,%A%f::%m,%-G%.%#'
|
||||||
exe a:cmd . (a:bang ? '! ' : ' ') . s:ShellExpand(before . after)
|
exe a:cmd . (a:bang ? '! ' : ' ') . s:ShellExpand(before . after)
|
||||||
if len(path) && a:line2 == -1
|
if len(path) && a:line2 == -1
|
||||||
@ -3136,7 +3141,7 @@ function! s:Edit(cmd, bang, mods, args, ...) abort
|
|||||||
execute cdback
|
execute cdback
|
||||||
endtry
|
endtry
|
||||||
let temp = s:Resolve(temp)
|
let temp = s:Resolve(temp)
|
||||||
let s:temp_files[s:cpath(temp)] = { 'dir': b:git_dir, 'filetype': 'git' }
|
let s:temp_files[s:cpath(temp)] = { 'dir': s:Dir(), 'filetype': 'git' }
|
||||||
if a:cmd ==# 'edit'
|
if a:cmd ==# 'edit'
|
||||||
call s:BlurStatus()
|
call s:BlurStatus()
|
||||||
endif
|
endif
|
||||||
@ -3416,7 +3421,7 @@ augroup fugitive_diff
|
|||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufWinLeave *
|
autocmd BufWinLeave *
|
||||||
\ if s:can_diffoff(+expand('<abuf>')) && s:diff_window_count() == 2 |
|
\ if s:can_diffoff(+expand('<abuf>')) && s:diff_window_count() == 2 |
|
||||||
\ call s:diffoff_all(getbufvar(+expand('<abuf>'), 'git_dir')) |
|
\ call s:diffoff_all(s:Dir(+expand('<abuf>'))) |
|
||||||
\ endif
|
\ endif
|
||||||
autocmd BufWinEnter *
|
autocmd BufWinEnter *
|
||||||
\ if s:can_diffoff(+expand('<abuf>')) && s:diff_window_count() == 1 |
|
\ if s:can_diffoff(+expand('<abuf>')) && s:diff_window_count() == 1 |
|
||||||
@ -3426,12 +3431,12 @@ augroup END
|
|||||||
|
|
||||||
function! s:can_diffoff(buf) abort
|
function! s:can_diffoff(buf) abort
|
||||||
return getwinvar(bufwinnr(a:buf), '&diff') &&
|
return getwinvar(bufwinnr(a:buf), '&diff') &&
|
||||||
\ !empty(getbufvar(a:buf, 'git_dir')) &&
|
\ !empty(s:Dir(a:buf)) &&
|
||||||
\ !empty(getwinvar(bufwinnr(a:buf), 'fugitive_diff_restore'))
|
\ !empty(getwinvar(bufwinnr(a:buf), 'fugitive_diff_restore'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#CanDiffoff(buf) abort
|
function! fugitive#CanDiffoff(buf) abort
|
||||||
return s:can_diffoff(a:buf)
|
return s:can_diffoff(bufnr(a:buf))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:diff_modifier(count) abort
|
function! s:diff_modifier(count) abort
|
||||||
@ -3494,7 +3499,7 @@ function! s:diffoff_all(dir) abort
|
|||||||
execute nr.'wincmd w'
|
execute nr.'wincmd w'
|
||||||
let restorewinnr = 1
|
let restorewinnr = 1
|
||||||
endif
|
endif
|
||||||
if exists('b:git_dir') && b:git_dir ==# a:dir
|
if s:Dir() ==# a:dir
|
||||||
call s:diffoff()
|
call s:diffoff()
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@ -3692,7 +3697,7 @@ augroup END
|
|||||||
" Section: :Gblame
|
" Section: :Gblame
|
||||||
|
|
||||||
function! s:Keywordprg() abort
|
function! s:Keywordprg() abort
|
||||||
let args = ' --git-dir='.escape(b:git_dir,"\\\"' ")
|
let args = ' --git-dir='.escape(s:Dir(),"\\\"' ")
|
||||||
if has('gui_running') && !has('win32')
|
if has('gui_running') && !has('win32')
|
||||||
return s:UserCommand() . ' --no-pager' . args . ' log -1'
|
return s:UserCommand() . ' --no-pager' . args . ' log -1'
|
||||||
else
|
else
|
||||||
@ -3702,7 +3707,7 @@ endfunction
|
|||||||
|
|
||||||
augroup fugitive_blame
|
augroup fugitive_blame
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd FileType fugitiveblame setlocal nomodeline | if exists('b:git_dir') | let &l:keywordprg = s:Keywordprg() | endif
|
autocmd FileType fugitiveblame setlocal nomodeline | if len(s:Dir()) | let &l:keywordprg = s:Keywordprg() | endif
|
||||||
autocmd Syntax fugitiveblame call s:BlameSyntax()
|
autocmd Syntax fugitiveblame call s:BlameSyntax()
|
||||||
autocmd User Fugitive
|
autocmd User Fugitive
|
||||||
\ if get(b:, 'fugitive_type') =~# '^\%(file\|blob\|blame\)$' || filereadable(@%) |
|
\ if get(b:, 'fugitive_type') =~# '^\%(file\|blob\|blame\)$' || filereadable(@%) |
|
||||||
@ -3793,7 +3798,7 @@ function! s:Blame(bang, line1, line2, count, mods, args) abort
|
|||||||
let top = line('w0') + &scrolloff
|
let top = line('w0') + &scrolloff
|
||||||
let current = line('.')
|
let current = line('.')
|
||||||
let temp = s:Resolve(temp)
|
let temp = s:Resolve(temp)
|
||||||
let s:temp_files[s:cpath(temp)] = { 'dir': b:git_dir, 'filetype': 'fugitiveblame', 'args': cmd, 'bufnr': bufnr }
|
let s:temp_files[s:cpath(temp)] = { 'dir': s:Dir(), 'filetype': 'fugitiveblame', 'args': cmd, 'bufnr': bufnr }
|
||||||
exe 'keepalt leftabove vsplit '.temp
|
exe 'keepalt leftabove vsplit '.temp
|
||||||
let b:fugitive_blamed_bufnr = bufnr
|
let b:fugitive_blamed_bufnr = bufnr
|
||||||
let b:fugitive_type = 'blame'
|
let b:fugitive_type = 'blame'
|
||||||
@ -3992,6 +3997,7 @@ call s:command("-bar -bang -range=0 -nargs=* -complete=customlist,fugitive#Compl
|
|||||||
let s:redirects = {}
|
let s:redirects = {}
|
||||||
|
|
||||||
function! s:Browse(bang,line1,count,...) abort
|
function! s:Browse(bang,line1,count,...) abort
|
||||||
|
let dir = s:Dir()
|
||||||
try
|
try
|
||||||
let validremote = '\.\|\.\=/.*\|[[:alnum:]_-]\+\%(://.\{-\}\)\='
|
let validremote = '\.\|\.\=/.*\|[[:alnum:]_-]\+\%(://.\{-\}\)\='
|
||||||
if a:0
|
if a:0
|
||||||
@ -4009,16 +4015,16 @@ function! s:Browse(bang,line1,count,...) abort
|
|||||||
else
|
else
|
||||||
let expanded = s:Expand(rev)
|
let expanded = s:Expand(rev)
|
||||||
endif
|
endif
|
||||||
let cdir = fugitive#CommonDir(b:git_dir)
|
let cdir = fugitive#CommonDir(s:Dir())
|
||||||
for dir in ['tags/', 'heads/', 'remotes/']
|
for subdir in ['tags/', 'heads/', 'remotes/']
|
||||||
if expanded !~# '^[./]' && filereadable(cdir . '/refs/' . dir . expanded)
|
if expanded !~# '^[./]' && filereadable(cdir . '/refs/' . subdir . expanded)
|
||||||
let expanded = '.git/refs/' . dir . expanded
|
let expanded = '.git/refs/' . subdir . expanded
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
let full = s:Generate(expanded)
|
let full = s:Generate(expanded)
|
||||||
let commit = ''
|
let commit = ''
|
||||||
if full =~? '^fugitive:'
|
if full =~? '^fugitive:'
|
||||||
let [dir, commit, path] = s:DirCommitFile(full)
|
let [pathdir, commit, path] = s:DirCommitFile(full)
|
||||||
if commit =~# '^:\=\d$'
|
if commit =~# '^:\=\d$'
|
||||||
let commit = ''
|
let commit = ''
|
||||||
endif
|
endif
|
||||||
@ -4029,11 +4035,11 @@ function! s:Browse(bang,line1,count,...) abort
|
|||||||
let type = 'blob'
|
let type = 'blob'
|
||||||
endif
|
endif
|
||||||
let path = path[1:-1]
|
let path = path[1:-1]
|
||||||
elseif empty(s:Tree())
|
elseif empty(s:Tree(dir))
|
||||||
let path = '.git/' . full[strlen(b:git_dir)+1:-1]
|
let path = '.git/' . full[strlen(dir)+1:-1]
|
||||||
let type = ''
|
let type = ''
|
||||||
else
|
else
|
||||||
let path = full[strlen(s:Tree())+1:-1]
|
let path = full[strlen(s:Tree(dir))+1:-1]
|
||||||
if path =~# '^\.git/'
|
if path =~# '^\.git/'
|
||||||
let type = ''
|
let type = ''
|
||||||
elseif isdirectory(full)
|
elseif isdirectory(full)
|
||||||
@ -4045,8 +4051,8 @@ function! s:Browse(bang,line1,count,...) abort
|
|||||||
if type ==# 'tree' && !empty(path)
|
if type ==# 'tree' && !empty(path)
|
||||||
let path = s:sub(path, '/\=$', '/')
|
let path = s:sub(path, '/\=$', '/')
|
||||||
endif
|
endif
|
||||||
if path =~# '^\.git/.*HEAD$' && filereadable(b:git_dir . '/' . path[5:-1])
|
if path =~# '^\.git/.*HEAD$' && filereadable(dir . '/' . path[5:-1])
|
||||||
let body = readfile(b:git_dir . '/' . path[5:-1])[0]
|
let body = readfile(dir . '/' . path[5:-1])[0]
|
||||||
if body =~# '^\x\{40\}$'
|
if body =~# '^\x\{40\}$'
|
||||||
let commit = body
|
let commit = body
|
||||||
let type = 'commit'
|
let type = 'commit'
|
||||||
@ -4123,7 +4129,7 @@ function! s:Browse(bang,line1,count,...) abort
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
if empty(commit)
|
if empty(commit)
|
||||||
let commit = readfile(b:git_dir . '/HEAD', '', 1)[0]
|
let commit = readfile(dir . '/HEAD', '', 1)[0]
|
||||||
endif
|
endif
|
||||||
let i = 0
|
let i = 0
|
||||||
while commit =~# '^ref: ' && i < 10
|
while commit =~# '^ref: ' && i < 10
|
||||||
@ -4152,8 +4158,8 @@ function! s:Browse(bang,line1,count,...) abort
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let opts = {
|
let opts = {
|
||||||
\ 'dir': b:git_dir,
|
\ 'dir': dir,
|
||||||
\ 'repo': fugitive#repo(),
|
\ 'repo': fugitive#repo(dir),
|
||||||
\ 'remote': raw,
|
\ 'remote': raw,
|
||||||
\ 'revision': 'No longer provided',
|
\ 'revision': 'No longer provided',
|
||||||
\ 'commit': commit,
|
\ 'commit': commit,
|
||||||
@ -4304,7 +4310,7 @@ function! fugitive#MapJumps(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:StatusCfile(...) abort
|
function! s:StatusCfile(...) abort
|
||||||
let tree = FugitiveTreeForGitDir(b:git_dir)
|
let tree = s:Tree()
|
||||||
let lead = s:cpath(tree, getcwd()) ? './' : tree . '/'
|
let lead = s:cpath(tree, getcwd()) ? './' : tree . '/'
|
||||||
let info = s:StageInfo()
|
let info = s:StageInfo()
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
@ -4333,7 +4339,7 @@ function! fugitive#StatusCfile() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:MessageCfile(...) abort
|
function! s:MessageCfile(...) abort
|
||||||
let tree = FugitiveTreeForGitDir(b:git_dir)
|
let tree = s:Tree()
|
||||||
let lead = s:cpath(tree, getcwd()) ? './' : tree . '/'
|
let lead = s:cpath(tree, getcwd()) ? './' : tree . '/'
|
||||||
if getline('.') =~# '^.\=\trenamed:.* -> '
|
if getline('.') =~# '^.\=\trenamed:.* -> '
|
||||||
return lead . matchstr(getline('.'),' -> \zs.*')
|
return lead . matchstr(getline('.'),' -> \zs.*')
|
||||||
@ -4548,7 +4554,7 @@ endfunction
|
|||||||
" Section: Statusline
|
" Section: Statusline
|
||||||
|
|
||||||
function! fugitive#Statusline(...) abort
|
function! fugitive#Statusline(...) abort
|
||||||
if !exists('b:git_dir')
|
if empty(s:Dir())
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
let status = ''
|
let status = ''
|
||||||
@ -4565,7 +4571,7 @@ function! fugitive#statusline(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#head(...) abort
|
function! fugitive#head(...) abort
|
||||||
if !exists('b:git_dir')
|
if empty(s:Dir())
|
||||||
return ''
|
return ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -4647,12 +4653,13 @@ function! fugitive#Init() abort
|
|||||||
if expand('%:p') =~# ':[\/][\/]'
|
if expand('%:p') =~# ':[\/][\/]'
|
||||||
let &l:path = s:sub(&path, '^\.%(,|$)', '')
|
let &l:path = s:sub(&path, '^\.%(,|$)', '')
|
||||||
endif
|
endif
|
||||||
if stridx(&tags, escape(b:git_dir, ', ')) == -1
|
let dir = s:Dir()
|
||||||
if filereadable(b:git_dir.'/tags')
|
if stridx(&tags, escape(dir, ', ')) == -1
|
||||||
let &l:tags = escape(b:git_dir.'/tags', ', ').','.&tags
|
if filereadable(dir.'/tags')
|
||||||
|
let &l:tags = escape(dir.'/tags', ', ').','.&tags
|
||||||
endif
|
endif
|
||||||
if &filetype !=# '' && filereadable(b:git_dir.'/'.&filetype.'.tags')
|
if &filetype !=# '' && filereadable(dir.'/'.&filetype.'.tags')
|
||||||
let &l:tags = escape(b:git_dir.'/'.&filetype.'.tags', ', ').','.&tags
|
let &l:tags = escape(dir.'/'.&filetype.'.tags', ', ').','.&tags
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
try
|
try
|
||||||
|
@ -29,7 +29,7 @@ function! FugitiveCommonDir(...) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! FugitiveWorkTree(...) abort
|
function! FugitiveWorkTree(...) abort
|
||||||
return FugitiveTreeForGitDir(FugitiveGitDir(a:0 ? a:1 : -1))
|
return s:Tree(FugitiveGitDir(a:0 ? a:1 : -1))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! FugitiveReal(...) abort
|
function! FugitiveReal(...) abort
|
||||||
@ -110,7 +110,7 @@ endfunction
|
|||||||
|
|
||||||
let s:worktree_for_dir = {}
|
let s:worktree_for_dir = {}
|
||||||
let s:dir_for_worktree = {}
|
let s:dir_for_worktree = {}
|
||||||
function! FugitiveTreeForGitDir(path) abort
|
function! s:Tree(path) abort
|
||||||
let dir = a:path
|
let dir = a:path
|
||||||
if dir =~# '/\.git$'
|
if dir =~# '/\.git$'
|
||||||
return len(dir) ==# 5 ? '/' : dir[0:-6]
|
return len(dir) ==# 5 ? '/' : dir[0:-6]
|
||||||
@ -173,7 +173,7 @@ function! FugitiveExtractGitDir(path) abort
|
|||||||
return simplify(fnamemodify($GIT_DIR, ':p:s?[\/]$??'))
|
return simplify(fnamemodify($GIT_DIR, ':p:s?[\/]$??'))
|
||||||
endif
|
endif
|
||||||
if FugitiveIsGitDir($GIT_DIR)
|
if FugitiveIsGitDir($GIT_DIR)
|
||||||
call FugitiveWorkTree(simplify(fnamemodify($GIT_DIR, ':p:s?[\/]$??')))
|
call s:Tree(simplify(fnamemodify($GIT_DIR, ':p:s?[\/]$??')))
|
||||||
if has_key(s:dir_for_worktree, root)
|
if has_key(s:dir_for_worktree, root)
|
||||||
return s:dir_for_worktree[root]
|
return s:dir_for_worktree[root]
|
||||||
endif
|
endif
|
||||||
@ -228,7 +228,7 @@ function! s:ProjectionistDetect() abort
|
|||||||
let dir = FugitiveExtractGitDir(file)
|
let dir = FugitiveExtractGitDir(file)
|
||||||
let base = matchstr(file, '^fugitive://.\{-\}//\x\+')
|
let base = matchstr(file, '^fugitive://.\{-\}//\x\+')
|
||||||
if empty(base)
|
if empty(base)
|
||||||
let base = FugitiveTreeForGitDir(dir)
|
let base = s:Tree(dir)
|
||||||
endif
|
endif
|
||||||
if len(base)
|
if len(base)
|
||||||
if exists('+shellslash') && !&shellslash
|
if exists('+shellslash') && !&shellslash
|
||||||
@ -251,21 +251,21 @@ augroup fugitive
|
|||||||
autocmd CmdWinEnter * call FugitiveDetect(expand('#:p'))
|
autocmd CmdWinEnter * call FugitiveDetect(expand('#:p'))
|
||||||
|
|
||||||
autocmd FileType git
|
autocmd FileType git
|
||||||
\ if exists('b:git_dir') |
|
\ if len(FugitiveGitDir()) |
|
||||||
\ call fugitive#MapJumps() |
|
\ call fugitive#MapJumps() |
|
||||||
\ call fugitive#MapCfile() |
|
\ call fugitive#MapCfile() |
|
||||||
\ endif
|
\ endif
|
||||||
autocmd FileType gitcommit
|
autocmd FileType gitcommit
|
||||||
\ if exists('b:git_dir') |
|
\ if len(FugitiveGitDir()) |
|
||||||
\ call fugitive#MapCfile('fugitive#MessageCfile()') |
|
\ call fugitive#MapCfile('fugitive#MessageCfile()') |
|
||||||
\ endif
|
\ endif
|
||||||
autocmd FileType fugitive
|
autocmd FileType fugitive
|
||||||
\ if exists('b:git_dir') |
|
\ if len(FugitiveGitDir()) |
|
||||||
\ call fugitive#MapCfile('fugitive#StatusCfile()') |
|
\ call fugitive#MapCfile('fugitive#StatusCfile()') |
|
||||||
\ endif
|
\ endif
|
||||||
autocmd FileType gitrebase
|
autocmd FileType gitrebase
|
||||||
\ let &l:include = '^\%(pick\|squash\|edit\|reword\|fixup\|drop\|[pserfd]\)\>' |
|
\ let &l:include = '^\%(pick\|squash\|edit\|reword\|fixup\|drop\|[pserfd]\)\>' |
|
||||||
\ if exists('b:git_dir') |
|
\ if len(FugitiveGitDir()) |
|
||||||
\ let &l:includeexpr = 'v:fname =~# ''^\x\{4,40\}$'' ? FugitiveFind(v:fname) : ' .
|
\ let &l:includeexpr = 'v:fname =~# ''^\x\{4,40\}$'' ? FugitiveFind(v:fname) : ' .
|
||||||
\ (len(&l:includeexpr) ? &l:includeexpr : 'v:fname') |
|
\ (len(&l:includeexpr) ? &l:includeexpr : 'v:fname') |
|
||||||
\ endif |
|
\ endif |
|
||||||
|
Loading…
x
Reference in New Issue
Block a user