mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-09 03:53:47 -05:00
Compare commits
37 Commits
v2.2
...
nested/tes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f61beed747 | ||
|
|
d854197c03 | ||
|
|
d8ce8d1d03 | ||
|
|
23faeadc7c | ||
|
|
1ecd12d523 | ||
|
|
f8aa87a4b5 | ||
|
|
dba8a0705d | ||
|
|
8cf3d94a3a | ||
|
|
28de2a1ddd | ||
|
|
01cda4d443 | ||
|
|
b5188a1b4f | ||
|
|
8e63140181 | ||
|
|
cec56ef5ff | ||
|
|
1e755064e9 | ||
|
|
0b43b51d77 | ||
|
|
5dcf8a0175 | ||
|
|
2509641eac | ||
|
|
073f3a37b9 | ||
|
|
b7b23001de | ||
|
|
b319b69453 | ||
|
|
03cc95cc19 | ||
|
|
7c4a906147 | ||
|
|
b5b2548a87 | ||
|
|
ca727b07f1 | ||
|
|
0fbbe0b3a4 | ||
|
|
1c844375fa | ||
|
|
e065e4f841 | ||
|
|
21b6dd7aee | ||
|
|
935a2cccd3 | ||
|
|
c2908b174d | ||
|
|
b0e38f08dc | ||
|
|
4cc201cbe3 | ||
|
|
baa05dcfda | ||
|
|
0095769029 | ||
|
|
e8b94098bb | ||
|
|
eb8eb1850a | ||
|
|
933f6a1e1d |
@@ -220,32 +220,38 @@ that are part of Git repositories).
|
||||
:[range]Gblame [flags] Run git-blame on the given range.
|
||||
|
||||
*fugitive-:Gbrowse*
|
||||
:[range]Gbrowse If the remote for the current branch is on GitHub,
|
||||
open the current file, blob, tree, commit, or tag
|
||||
(with git-web--browse) on GitHub. Otherwise, open the
|
||||
current file, blob, tree, commit, or tag in
|
||||
git-instaweb (if you have issues, verify you can run
|
||||
"git instaweb" from a terminal). If a range is given,
|
||||
it is appropriately appended to the URL as an anchor.
|
||||
:Gbrowse Open the current file, blob, tree, commit, or tag
|
||||
in your browser at the upstream hosting provider
|
||||
indicated by the "origin" remote. If a range is
|
||||
given, it is appropriately appended to the URL as an
|
||||
anchor.
|
||||
|
||||
To use with GitHub FI, point g:fugitive_github_domains
|
||||
at a list of domains:
|
||||
>
|
||||
let g:fugitive_github_domains = ['https://example.com']
|
||||
~
|
||||
:[range]Gbrowse! Like :Gbrowse, but put the URL on the clipboard rather
|
||||
than opening it.
|
||||
Upstream providers can be added by installing an
|
||||
appropriate Vim plugin. For example, GitHub can be
|
||||
supported by installing rhubarb.vim, available at
|
||||
<https://github.com/tpope/vim-rhubarb>. (Native
|
||||
support for GitHub is currently included, but that is
|
||||
slated to be removed.)
|
||||
|
||||
:[range]Gbrowse {revision}
|
||||
Like :Gbrowse, but for a given |fugitive-revision|. A
|
||||
If no upstream support is available, a local instance
|
||||
of git-instaweb will be started and used instead.
|
||||
|
||||
:Gbrowse {revision} Like :Gbrowse, but for a given |fugitive-revision|. A
|
||||
useful value here is -, which ties the URL to the
|
||||
latest commit rather than a volatile branch.
|
||||
|
||||
:[range]Gbrowse [...]@{remote}
|
||||
Force using the given remote rather than the remote
|
||||
:Gbrowse [...]@{remote} Force using the given remote rather than the remote
|
||||
for the current branch. The remote is used to
|
||||
determine which GitHub repository to link to.
|
||||
|
||||
:{range}Gbrowse [args] Appends an anchor to the URL that emphasizes the
|
||||
selected lines. You almost certainly want to give a
|
||||
"-" argument in this case to force the URL to include
|
||||
an exact revision.
|
||||
|
||||
:[range]Gbrowse! [args] Like :Gbrowse, but put the URL on the clipboard rather
|
||||
than opening it.
|
||||
|
||||
MAPPINGS *fugitive-mappings*
|
||||
|
||||
These maps are available everywhere.
|
||||
|
||||
@@ -143,11 +143,11 @@ function! fugitive#extract_git_dir(path) abort
|
||||
break
|
||||
endif
|
||||
if root ==# $GIT_WORK_TREE && fugitive#is_git_dir($GIT_DIR)
|
||||
return $GIT_DIR
|
||||
return simplify(fnamemodify(expand($GIT_DIR), ':p:s?[\/]$??'))
|
||||
endif
|
||||
if fugitive#is_git_dir($GIT_DIR)
|
||||
" Ensure that we've cached the worktree
|
||||
call s:configured_tree($GIT_DIR)
|
||||
call s:configured_tree(simplify(fnamemodify(expand($GIT_DIR), ':p:s?[\/]$??')))
|
||||
if has_key(s:dir_for_worktree, root)
|
||||
return s:dir_for_worktree[root]
|
||||
endif
|
||||
@@ -193,8 +193,10 @@ function! fugitive#detect(path) abort
|
||||
let &mls = save_mls
|
||||
endtry
|
||||
endif
|
||||
cnoremap <buffer> <expr> <C-R><C-G> fnameescape(<SID>recall())
|
||||
nnoremap <buffer> <silent> y<C-G> :call setreg(v:register, <SID>recall())<CR>
|
||||
if !exists('g:fugitive_no_maps')
|
||||
cnoremap <buffer> <expr> <C-R><C-G> fnameescape(<SID>recall())
|
||||
nnoremap <buffer> <silent> y<C-G> :call setreg(v:register, <SID>recall())<CR>
|
||||
endif
|
||||
let buffer = fugitive#buffer()
|
||||
if expand('%:p') =~# '//'
|
||||
call buffer.setvar('&path', s:sub(buffer.getvar('&path'), '^\.%(,|$)', ''))
|
||||
@@ -218,7 +220,7 @@ endfunction
|
||||
|
||||
augroup fugitive
|
||||
autocmd!
|
||||
autocmd BufNewFile,BufReadPost * call fugitive#detect(expand('<amatch>:p'))
|
||||
autocmd BufNewFile,BufReadPost * call fugitive#detect(expand('%:p'))
|
||||
autocmd FileType netrw call fugitive#detect(expand('%:p'))
|
||||
autocmd User NERDTreeInit,NERDTreeNewRoot call fugitive#detect(b:NERDTreeRoot.path.str())
|
||||
autocmd VimEnter * if expand('<amatch>')==''|call fugitive#detect(getcwd())|endif
|
||||
@@ -296,49 +298,86 @@ function! s:repo_bare() dict abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:repo_disambiguate(spec) dict abort
|
||||
if a:spec =~# '^:[0-3]:\|^:\=/\|^:\=$\|^\x\{40\}$'
|
||||
return a:spec
|
||||
elseif a:spec =~# '^:'
|
||||
return ':0' . a:spec
|
||||
elseif a:spec ==# '^\.'
|
||||
return '/' . a:spec
|
||||
elseif a:spec =~# '^[^:~^]*\.\.'
|
||||
let before = self.qualify_ref(matchstr(a:spec, '.\{-\}\ze\.\.'))
|
||||
let after = self.qualify_ref(matchstr(a:spec, '\.\.\.\=\zs.*'))
|
||||
if before =~# '^/' || after =~# '^/'
|
||||
return '/' . a:spec
|
||||
else
|
||||
return before . matchstr(a:spec, '\.\.\.\=') . after
|
||||
endif
|
||||
endif
|
||||
let head = s:sub(a:spec, '[:~^].*|\@\{.*', '')
|
||||
let rest = strpart(a:spec, len(head))
|
||||
if head ==# '@'
|
||||
return 'HEAD'.rest
|
||||
endif
|
||||
if head =~# "[[?*\001-\037\177]".'\|\%([./]\|\.lock\)\%(/\|$\)'
|
||||
return '/' . a:spec
|
||||
endif
|
||||
let packed = {}
|
||||
if filereadable(self.dir('packed-refs'))
|
||||
for [v, k] in map(readfile(self.dir('packed-refs')), 'split(v:val, " ")')
|
||||
let packed[k] = v
|
||||
endfor
|
||||
endif
|
||||
for pattern in ['%s', 'refs/%s', 'refs/tags/%s', 'refs/heads/%s', 'refs/remotes/%s', 'refs/remotes/%s/HEAD']
|
||||
let ref = printf(pattern, head)
|
||||
if filereadable(self.dir(ref)) || has_key(packed, ref)
|
||||
return ref . rest
|
||||
endif
|
||||
endfor
|
||||
let tag = matchstr(head, '.*\ze-\d\+-g\x\+$')
|
||||
if !empty(tag) && (filereadable(self.dir('refs/tags/'.tag)) || has_key(packed, ref))
|
||||
return head . rest
|
||||
endif
|
||||
if head =~# '^\x\{4,40\}$'
|
||||
try
|
||||
return self.rev_parse(head) . rest
|
||||
catch /^fugitive:/
|
||||
endtry
|
||||
endif
|
||||
return '/' . a:spec
|
||||
endfunction
|
||||
|
||||
function! s:repo_translate(spec) dict abort
|
||||
if a:spec ==# '.' || a:spec ==# '/.'
|
||||
return self.bare() ? self.dir() : self.tree()
|
||||
elseif a:spec =~# '^/\=\.git$' && self.bare()
|
||||
let spec = self.disambiguate(a:spec)
|
||||
if spec =~# '^/\=\.git$' && self.bare()
|
||||
return self.dir()
|
||||
elseif a:spec =~# '^/\=\.git/'
|
||||
return self.dir(s:sub(a:spec, '^/=\.git/', ''))
|
||||
elseif a:spec =~# '^/'
|
||||
return self.tree().a:spec
|
||||
elseif a:spec =~# '^:[0-3]:'
|
||||
return 'fugitive://'.self.dir().'//'.a:spec[1].'/'.a:spec[3:-1]
|
||||
elseif a:spec ==# ':'
|
||||
elseif spec =~# '^/\=\.git/'
|
||||
return self.dir(s:sub(spec, '^/=\.git/', ''))
|
||||
elseif spec =~# '^/'
|
||||
return self.tree().spec
|
||||
elseif spec =~# '^:[0-3]:'
|
||||
return 'fugitive://'.self.dir().'//'.spec[1].'/'.spec[3:-1]
|
||||
elseif spec ==# ':'
|
||||
if $GIT_INDEX_FILE =~# '/[^/]*index[^/]*\.lock$' && fnamemodify($GIT_INDEX_FILE,':p')[0:strlen(self.dir())] ==# self.dir('') && filereadable($GIT_INDEX_FILE)
|
||||
return fnamemodify($GIT_INDEX_FILE,':p')
|
||||
else
|
||||
return self.dir('index')
|
||||
endif
|
||||
elseif a:spec =~# '^:/'
|
||||
let ref = self.rev_parse(matchstr(a:spec,'.[^:]*'))
|
||||
elseif spec =~# '^:/'
|
||||
let ref = self.rev_parse(matchstr(spec,'.[^:]*'))
|
||||
return 'fugitive://'.self.dir().'//'.ref
|
||||
elseif a:spec =~# '^:'
|
||||
return 'fugitive://'.self.dir().'//0/'.a:spec[1:-1]
|
||||
elseif a:spec =~# 'HEAD\|^refs/' && a:spec !~ ':' && filereadable(self.dir(a:spec))
|
||||
return self.dir(a:spec)
|
||||
elseif filereadable(self.dir('refs/'.a:spec))
|
||||
return self.dir('refs/'.a:spec)
|
||||
elseif filereadable(self.dir('refs/tags/'.a:spec))
|
||||
return self.dir('refs/tags/'.a:spec)
|
||||
elseif filereadable(self.dir('refs/heads/'.a:spec))
|
||||
return self.dir('refs/heads/'.a:spec)
|
||||
elseif filereadable(self.dir('refs/remotes/'.a:spec))
|
||||
return self.dir('refs/remotes/'.a:spec)
|
||||
elseif filereadable(self.dir('refs/remotes/'.a:spec.'/HEAD'))
|
||||
return self.dir('refs/remotes/'.a:spec,'/HEAD')
|
||||
else
|
||||
try
|
||||
let ref = self.rev_parse(matchstr(a:spec,'[^:]*'))
|
||||
let path = s:sub(matchstr(a:spec,':.*'),'^:','/')
|
||||
return 'fugitive://'.self.dir().'//'.ref.path
|
||||
catch /^fugitive:/
|
||||
return self.tree(a:spec)
|
||||
endtry
|
||||
endif
|
||||
|
||||
let ref = matchstr(spec,'[^:]*')
|
||||
let path = s:sub(matchstr(spec,':.*'),'^:','/')
|
||||
if empty(path) && ref !~# '[~^]'
|
||||
if filereadable(self.dir(ref))
|
||||
return self.dir(ref)
|
||||
else
|
||||
return self.dir('packed-refs')
|
||||
endif
|
||||
endif
|
||||
return 'fugitive://'.self.dir().'//'.self.rev_parse(ref).path
|
||||
endfunction
|
||||
|
||||
function! s:repo_head(...) dict abort
|
||||
@@ -357,7 +396,7 @@ function! s:repo_head(...) dict abort
|
||||
return branch
|
||||
endfunction
|
||||
|
||||
call s:add_methods('repo',['dir','tree','bare','translate','head'])
|
||||
call s:add_methods('repo',['dir','tree','bare','disambiguate','translate','head'])
|
||||
|
||||
function! s:repo_git_command(...) dict abort
|
||||
let git = g:fugitive_git_executable . ' --git-dir='.s:shellesc(self.git_dir)
|
||||
@@ -402,6 +441,11 @@ function! s:repo_superglob(base) dict abort
|
||||
if a:base !~# '^/'
|
||||
let heads = ["HEAD","ORIG_HEAD","FETCH_HEAD","MERGE_HEAD"]
|
||||
let heads += sort(split(s:repo().git_chomp("rev-parse","--symbolic","--branches","--tags","--remotes"),"\n"))
|
||||
" Add any stashes.
|
||||
if filereadable(s:repo().dir('refs/stash'))
|
||||
let heads += ["stash"]
|
||||
let heads += sort(split(s:repo().git_chomp("stash","list","--pretty=format:%gd"),"\n"))
|
||||
endif
|
||||
call filter(heads,'v:val[ 0 : strlen(a:base)-1 ] ==# a:base')
|
||||
let results += heads
|
||||
endif
|
||||
@@ -555,13 +599,24 @@ function! s:buffer_commit() dict abort
|
||||
return matchstr(self.spec(),'^fugitive://.\{-\}//\zs\w*')
|
||||
endfunction
|
||||
|
||||
function! s:cpath(path) abort
|
||||
if exists('+fileignorecase') && &fileignorecase
|
||||
return tolower(a:path)
|
||||
else
|
||||
return a:path
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:buffer_path(...) dict abort
|
||||
let rev = matchstr(self.spec(),'^fugitive://.\{-\}//\zs.*')
|
||||
if rev != ''
|
||||
let rev = s:sub(rev,'\w*','')
|
||||
elseif self.spec()[0 : len(self.repo().dir())] ==# self.repo().dir() . '/'
|
||||
elseif s:cpath(self.spec()[0 : len(self.repo().dir())]) ==#
|
||||
\ s:cpath(self.repo().dir() . '/')
|
||||
let rev = '/.git'.self.spec()[strlen(self.repo().dir()) : -1]
|
||||
elseif !self.repo().bare() && self.spec()[0 : len(self.repo().tree())] ==# self.repo().tree() . '/'
|
||||
elseif !self.repo().bare() &&
|
||||
\ s:cpath(self.spec()[0 : len(self.repo().tree())]) ==#
|
||||
\ s:cpath(self.repo().tree() . '/')
|
||||
let rev = self.spec()[strlen(self.repo().tree()) : -1]
|
||||
endif
|
||||
return s:sub(s:sub(rev,'.\zs/$',''),'^/',a:0 ? a:1 : '')
|
||||
@@ -668,8 +723,17 @@ function! s:Git(bang, args) abort
|
||||
let git .= ' --no-pager'
|
||||
endif
|
||||
let args = matchstr(a:args,'\v\C.{-}%($|\\@<!%(\\\\)*\|)@=')
|
||||
call s:ExecuteInTree('!'.git.' '.args)
|
||||
call fugitive#reload_status()
|
||||
if exists(':terminal')
|
||||
let dir = s:repo().tree()
|
||||
tabedit %
|
||||
execute 'lcd' fnameescape(dir)
|
||||
execute 'terminal' git args
|
||||
else
|
||||
call s:ExecuteInTree('!'.git.' '.args)
|
||||
if has('win32')
|
||||
call fugitive#reload_status()
|
||||
endif
|
||||
endif
|
||||
return matchstr(a:args, '\v\C\\@<!%(\\\\)*\|\zs.*')
|
||||
endfunction
|
||||
|
||||
@@ -706,6 +770,7 @@ augroup fugitive_status
|
||||
autocmd!
|
||||
if !has('win32')
|
||||
autocmd FocusGained,ShellCmdPost * call fugitive#reload_status()
|
||||
autocmd BufDelete term://* call fugitive#reload_status()
|
||||
endif
|
||||
augroup END
|
||||
|
||||
@@ -971,7 +1036,7 @@ function! s:StagePatch(lnum1,lnum2) abort
|
||||
execute "Git add --patch -- ".join(map(add,'s:shellesc(v:val)'))
|
||||
endif
|
||||
if !empty(reset)
|
||||
execute "Git reset --patch -- ".join(map(add,'s:shellesc(v:val)'))
|
||||
execute "Git reset --patch -- ".join(map(reset,'s:shellesc(v:val)'))
|
||||
endif
|
||||
if exists('first_filename')
|
||||
silent! edit!
|
||||
@@ -1043,7 +1108,7 @@ function! s:Commit(args, ...) abort
|
||||
if bufname('%') == '' && line('$') == 1 && getline(1) == '' && !&mod
|
||||
execute 'keepalt edit '.s:fnameescape(msgfile)
|
||||
elseif a:args =~# '\%(^\| \)-\%(-verbose\|\w*v\)\>'
|
||||
execute 'keepalt tabedit '.s:fnameescape(msgfile)
|
||||
execute 'keepalt '.(tabpagenr()-1).'tabedit '.s:fnameescape(msgfile)
|
||||
elseif s:buffer().type() ==# 'index'
|
||||
execute 'keepalt edit '.s:fnameescape(msgfile)
|
||||
execute (search('^#','n')+1).'wincmd+'
|
||||
@@ -1164,13 +1229,15 @@ function! s:Merge(cmd, bang, args) abort
|
||||
\ !empty(s:repo().git_chomp('diff-files', '--diff-filter=U')))
|
||||
let &l:makeprg = g:fugitive_git_executable.' diff-files --name-status --diff-filter=U'
|
||||
else
|
||||
let &l:makeprg = s:sub(g:fugitive_git_executable.' -c core.editor=false '.
|
||||
\ a:cmd . (a:args =~# ' \%(--no-edit\|--abort\|-m\)\>' ? '' : ' --edit') . ' ' . a:args,
|
||||
\ ' *$', '')
|
||||
let &l:makeprg = s:sub(g:fugitive_git_executable . ' ' . a:cmd .
|
||||
\ (a:args =~# ' \%(--no-edit\|--abort\|-m\)\>' ? '' : ' --edit') .
|
||||
\ ' ' . a:args, ' *$', '')
|
||||
endif
|
||||
if !empty($GIT_EDITOR)
|
||||
if !empty($GIT_EDITOR) || has('win32')
|
||||
let old_editor = $GIT_EDITOR
|
||||
let $GIT_EDITOR = 'false'
|
||||
else
|
||||
let &l:makeprg = 'env GIT_EDITOR=false ' . &l:makeprg
|
||||
endif
|
||||
execute cd fnameescape(s:repo().tree())
|
||||
silent noautocmd make!
|
||||
@@ -1227,8 +1294,8 @@ function! s:Grep(cmd,bang,arg) abort
|
||||
let dir = getcwd()
|
||||
try
|
||||
execute cd.'`=s:repo().tree()`'
|
||||
let &grepprg = s:repo().git_command('--no-pager', 'grep', '-n')
|
||||
let &grepformat = '%f:%l:%m'
|
||||
let &grepprg = s:repo().git_command('--no-pager', 'grep', '-n', '--no-color')
|
||||
let &grepformat = '%f:%l:%m,%f'
|
||||
exe a:cmd.'! '.escape(matchstr(a:arg,'\v\C.{-}%($|[''" ]\@=\|)@='),'|')
|
||||
let list = a:cmd =~# '^l' ? getloclist(0) : getqflist()
|
||||
for entry in list
|
||||
@@ -1303,7 +1370,14 @@ function! s:Edit(cmd,bang,...) abort
|
||||
let buffer = s:buffer()
|
||||
if a:cmd !~# 'read'
|
||||
if &previewwindow && getbufvar('','fugitive_type') ==# 'index'
|
||||
wincmd p
|
||||
if winnr('$') == 1
|
||||
let tabs = (&go =~# 'e' || !has('gui_running')) && &stal && (tabpagenr('$') >= &stal)
|
||||
execute 'rightbelow' (&lines - &previewheight - &cmdheight - tabs - 1 - !!&laststatus).'new'
|
||||
elseif winnr('#')
|
||||
wincmd p
|
||||
else
|
||||
wincmd w
|
||||
endif
|
||||
if &diff
|
||||
let mywinnr = winnr()
|
||||
for winnr in range(winnr('$'),1,-1)
|
||||
@@ -1334,7 +1408,7 @@ function! s:Edit(cmd,bang,...) abort
|
||||
return 'redraw|echo '.string(':!'.git.' '.args)
|
||||
else
|
||||
let temp = resolve(tempname())
|
||||
let s:temp_files[tolower(temp)] = { 'dir': buffer.repo().dir(), 'args': arglist }
|
||||
let s:temp_files[s:cpath(temp)] = { 'dir': buffer.repo().dir(), 'args': arglist }
|
||||
silent execute a:cmd.' '.temp
|
||||
if a:cmd =~# 'pedit'
|
||||
wincmd P
|
||||
@@ -1431,6 +1505,9 @@ function! s:Write(force,...) abort
|
||||
let mytab = tabpagenr()
|
||||
let mybufnr = bufnr('')
|
||||
let path = a:0 ? join(a:000, ' ') : s:buffer().path()
|
||||
if empty(path)
|
||||
return 'echoerr '.string('fugitive: cannot determine file path')
|
||||
endif
|
||||
if path =~# '^:\d\>'
|
||||
return 'write'.(a:force ? '! ' : ' ').s:fnameescape(s:repo().translate(s:buffer().expand(path)))
|
||||
endif
|
||||
@@ -1588,9 +1665,9 @@ endfunction
|
||||
|
||||
" Section: Gdiff
|
||||
|
||||
call s:command("-bang -bar -nargs=* -complete=customlist,s:EditComplete Gdiff :execute s:Diff('',<f-args>)")
|
||||
call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gvdiff :execute s:Diff('keepalt vert ',<f-args>)")
|
||||
call s:command("-bar -nargs=* -complete=customlist,s:EditComplete Gsdiff :execute s:Diff('keepalt ',<f-args>)")
|
||||
call s:command("-bang -bar -nargs=* -complete=customlist,s:EditComplete Gdiff :execute s:Diff('',<bang>0,<f-args>)")
|
||||
call s:command("-bang -bar -nargs=* -complete=customlist,s:EditComplete Gvdiff :execute s:Diff('keepalt vert ',<bang>0,<f-args>)")
|
||||
call s:command("-bang -bar -nargs=* -complete=customlist,s:EditComplete Gsdiff :execute s:Diff('keepalt ',<bang>0,<f-args>)")
|
||||
|
||||
augroup fugitive_diff
|
||||
autocmd!
|
||||
@@ -1667,6 +1744,7 @@ function! s:diffoff() abort
|
||||
endfunction
|
||||
|
||||
function! s:diffoff_all(dir) abort
|
||||
let curwin = winnr()
|
||||
for nr in range(1,winnr('$'))
|
||||
if getwinvar(nr,'&diff')
|
||||
if nr != winnr()
|
||||
@@ -1678,6 +1756,7 @@ function! s:diffoff_all(dir) abort
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
execute curwin.'wincmd w'
|
||||
endfunction
|
||||
|
||||
function! s:buffer_compare_age(commit) dict abort
|
||||
@@ -1702,11 +1781,16 @@ endfunction
|
||||
|
||||
call s:add_methods('buffer',['compare_age'])
|
||||
|
||||
function! s:Diff(vert,...) abort
|
||||
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
|
||||
if exists(':DiffGitCached')
|
||||
return 'DiffGitCached'
|
||||
elseif (!a:0 || a:1 == ':') && s:buffer().commit() =~# '^[0-1]\=$' && s:repo().git_chomp_in_tree('ls-files', '--unmerged', '--', s:buffer().path()) !=# ''
|
||||
elseif (empty(args) || args[0] == ':') && s:buffer().commit() =~# '^[0-1]\=$' && s:repo().git_chomp_in_tree('ls-files', '--unmerged', '--', s:buffer().path()) !=# ''
|
||||
let vert = empty(a:vert) ? s:diff_modifier(3) : a:vert
|
||||
let nr = bufnr('')
|
||||
execute 'leftabove '.vert.'split `=fugitive#buffer().repo().translate(s:buffer().expand('':2''))`'
|
||||
@@ -1718,11 +1802,11 @@ function! s:Diff(vert,...) abort
|
||||
call s:diffthis()
|
||||
wincmd p
|
||||
call s:diffthis()
|
||||
return ''
|
||||
elseif a:0
|
||||
let arg = join(a:000, ' ')
|
||||
return post
|
||||
elseif len(args)
|
||||
let arg = join(args, ' ')
|
||||
if arg ==# ''
|
||||
return ''
|
||||
return post
|
||||
elseif arg ==# '/'
|
||||
let file = s:buffer().path('/')
|
||||
elseif arg ==# ':'
|
||||
@@ -1755,13 +1839,17 @@ function! s:Diff(vert,...) abort
|
||||
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')
|
||||
wincmd p
|
||||
call feedkeys("\<C-W>p", 'n')
|
||||
if !a:keepfocus
|
||||
call feedkeys(winnr."\<C-W>w", 'n')
|
||||
endif
|
||||
endif
|
||||
return ''
|
||||
return post
|
||||
catch /^fugitive:/
|
||||
return 'echoerr v:errmsg'
|
||||
endtry
|
||||
@@ -1831,7 +1919,7 @@ function! s:Remove(force) abort
|
||||
return 'echoerr '.string(v:errmsg)
|
||||
else
|
||||
call fugitive#reload_status()
|
||||
return 'bdelete'.(a:force ? '!' : '')
|
||||
return 'edit'.(a:force ? '!' : '')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -1933,7 +2021,7 @@ function! s:Blame(bang,line1,line2,count,args) abort
|
||||
endif
|
||||
let top = line('w0') + &scrolloff
|
||||
let current = line('.')
|
||||
let s:temp_files[tolower(temp)] = { 'dir': s:repo().dir(), 'args': cmd }
|
||||
let s:temp_files[s:cpath(temp)] = { 'dir': s:repo().dir(), 'args': cmd }
|
||||
exe 'keepalt leftabove vsplit '.temp
|
||||
let b:fugitive_blamed_bufnr = bufnr
|
||||
let w:fugitive_leave = restore
|
||||
@@ -2043,15 +2131,17 @@ function! s:BlameJump(suffix) abort
|
||||
if winnr > 0
|
||||
exe bufnr.'bdelete'
|
||||
endif
|
||||
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>"
|
||||
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
|
||||
syncbind
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
@@ -2225,7 +2315,14 @@ function! s:Browse(bang,line1,count,...) abort
|
||||
elseif exists(':Browse') == 2
|
||||
return 'echomsg '.string(url).'|Browse '.url
|
||||
else
|
||||
return 'echomsg '.string(url).'|call netrw#NetrwBrowseX('.string(url).', 0)'
|
||||
if !exists('g:loaded_netrw')
|
||||
runtime! autoload/netrw.vim
|
||||
endif
|
||||
if exists('*netrw#BrowseX')
|
||||
return 'echomsg '.string(url).'|call netrw#BrowseX('.string(url).', 0)'
|
||||
else
|
||||
return 'echomsg '.string(url).'|call netrw#NetrwBrowseX('.string(url).', 0)'
|
||||
endif
|
||||
endif
|
||||
catch /^fugitive:/
|
||||
return 'echoerr v:errmsg'
|
||||
@@ -2258,6 +2355,8 @@ function! s:github_url(opts, ...) abort
|
||||
else
|
||||
return root . '/commits/' . branch
|
||||
endif
|
||||
elseif path =~# '^\.git/refs/tags/'
|
||||
return root . '/releases/tag/' . matchstr(path,'[^/]\+$')
|
||||
elseif path =~# '^\.git/refs/.'
|
||||
return root . '/commits/' . matchstr(path,'[^/]\+$')
|
||||
elseif path =~# '.git/\%(config$\|hooks\>\)'
|
||||
@@ -2283,11 +2382,8 @@ function! s:github_url(opts, ...) abort
|
||||
if get(a:opts, 'line2') && a:opts.line1 == a:opts.line2
|
||||
let url .= '#L' . a:opts.line1
|
||||
elseif get(a:opts, 'line2')
|
||||
let url .= '#L' . a:opts.line1 . '-' . a:opts.line2
|
||||
let url .= '#L' . a:opts.line1 . '-L' . a:opts.line2
|
||||
endif
|
||||
elseif a:opts.type == 'tag'
|
||||
let commit = matchstr(getline(3),'^tag \zs.*')
|
||||
let url = root . '/tree/' . commit
|
||||
else
|
||||
let url = root . '/commit/' . commit
|
||||
endif
|
||||
@@ -2357,11 +2453,17 @@ function! s:ReplaceCmd(cmd,...) abort
|
||||
let prefix = 'env GIT_INDEX_FILE='.s:shellesc(a:1).' '
|
||||
endif
|
||||
endif
|
||||
let redir = ' > '.tmp
|
||||
if &shellpipe =~ '2>&1'
|
||||
let redir .= ' 2>&1'
|
||||
endif
|
||||
if s:winshell()
|
||||
let cmd_escape_char = &shellxquote == '(' ? '^' : '^^^'
|
||||
call system('cmd /c "'.prefix.s:gsub(a:cmd,'[<>]', cmd_escape_char.'&').' > '.tmp.'"')
|
||||
call system('cmd /c "'.prefix.s:gsub(a:cmd,'[<>]', cmd_escape_char.'&').redir.'"')
|
||||
elseif &shell =~# 'fish'
|
||||
call system(' begin;'.prefix.a:cmd.redir.';end ')
|
||||
else
|
||||
call system(' ('.prefix.a:cmd.' > '.tmp.') ')
|
||||
call system(' ('.prefix.a:cmd.redir.') ')
|
||||
endif
|
||||
finally
|
||||
if exists('old_index')
|
||||
@@ -2631,6 +2733,10 @@ augroup fugitive_files
|
||||
\ if exists('b:git_dir') |
|
||||
\ call s:JumpInit() |
|
||||
\ endif
|
||||
autocmd FileType git,gitcommit,gitrebase
|
||||
\ if exists('b:git_dir') |
|
||||
\ call s:GFInit() |
|
||||
\ endif
|
||||
augroup END
|
||||
|
||||
" Section: Temp files
|
||||
@@ -2642,10 +2748,10 @@ endif
|
||||
augroup fugitive_temp
|
||||
autocmd!
|
||||
autocmd BufNewFile,BufReadPost *
|
||||
\ if has_key(s:temp_files,tolower(expand('<afile>:p'))) |
|
||||
\ let b:git_dir = s:temp_files[tolower(expand('<afile>:p'))].dir |
|
||||
\ if has_key(s:temp_files,s:cpath(expand('<afile>:p'))) |
|
||||
\ let b:git_dir = s:temp_files[s:cpath(expand('<afile>:p'))].dir |
|
||||
\ let b:git_type = 'temp' |
|
||||
\ let b:git_args = s:temp_files[tolower(expand('<afile>:p'))].args |
|
||||
\ let b:git_args = s:temp_files[s:cpath(expand('<afile>:p'))].args |
|
||||
\ call fugitive#detect(expand('<afile>:p')) |
|
||||
\ setlocal bufhidden=delete nobuflisted |
|
||||
\ nnoremap <buffer> <silent> q :<C-U>bdelete<CR>|
|
||||
@@ -2654,7 +2760,18 @@ augroup END
|
||||
|
||||
" Section: Go to file
|
||||
|
||||
function! s:JumpInit() abort
|
||||
nnoremap <SID>: :<C-U><C-R>=v:count ? v:count : ''<CR>
|
||||
function! s:GFInit(...) abort
|
||||
cnoremap <buffer> <expr> <Plug><cfile> fugitive#cfile()
|
||||
if !exists('g:fugitive_no_maps') && empty(mapcheck('gf', 'n'))
|
||||
nmap <buffer> <silent> gf <SID>:find <Plug><cfile><CR>
|
||||
nmap <buffer> <silent> <C-W>f <SID>:sfind <Plug><cfile><CR>
|
||||
nmap <buffer> <silent> <C-W><C-F> <SID>:sfind <Plug><cfile><CR>
|
||||
nmap <buffer> <silent> <C-W>gf <SID>:tabfind <Plug><cfile><CR>
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:JumpInit(...) abort
|
||||
nnoremap <buffer> <silent> <CR> :<C-U>exe <SID>GF("edit")<CR>
|
||||
if !&modifiable
|
||||
nnoremap <buffer> <silent> o :<C-U>exe <SID>GF("split")<CR>
|
||||
@@ -2673,7 +2790,7 @@ function! s:JumpInit() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:GF(mode) abort
|
||||
function! s:cfile() abort
|
||||
try
|
||||
let buffer = s:buffer()
|
||||
let myhash = buffer.sha1()
|
||||
@@ -2683,12 +2800,10 @@ function! s:GF(mode) abort
|
||||
|
||||
if buffer.type('tree')
|
||||
let showtree = (getline(1) =~# '^tree ' && getline(2) == "")
|
||||
if showtree && line('.') == 1
|
||||
return ""
|
||||
elseif showtree && line('.') > 2
|
||||
return s:Edit(a:mode,0,buffer.commit().':'.s:buffer().path().(buffer.path() =~# '^$\|/$' ? '' : '/').s:sub(getline('.'),'/$',''))
|
||||
if showtree && line('.') > 2
|
||||
return [buffer.commit().':'.s:buffer().path().(buffer.path() =~# '^$\|/$' ? '' : '/').s:sub(getline('.'),'/$','')]
|
||||
elseif getline('.') =~# '^\d\{6\} \l\{3,8\} \x\{40\}\t'
|
||||
return s:Edit(a:mode,0,buffer.commit().':'.s:buffer().path().(buffer.path() =~# '^$\|/$' ? '' : '/').s:sub(matchstr(getline('.'),'\t\zs.*'),'/$',''))
|
||||
return [buffer.commit().':'.s:buffer().path().(buffer.path() =~# '^$\|/$' ? '' : '/').s:sub(matchstr(getline('.'),'\t\zs.*'),'/$','')]
|
||||
endif
|
||||
|
||||
elseif buffer.type('blob')
|
||||
@@ -2698,38 +2813,40 @@ function! s:GF(mode) abort
|
||||
catch /^fugitive:/
|
||||
endtry
|
||||
if exists('sha1')
|
||||
return s:Edit(a:mode,0,ref)
|
||||
return [ref]
|
||||
endif
|
||||
|
||||
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 s:Edit(a:mode,0,file)
|
||||
return [file]
|
||||
|
||||
elseif getline('.') =~# '^#\trenamed:.* -> '
|
||||
let file = '/'.matchstr(getline('.'),' -> \zs.*')
|
||||
return s:Edit(a:mode,0,file)
|
||||
return [file]
|
||||
elseif getline('.') =~# '^#\t[[:alpha:] ]\+: *.'
|
||||
let file = '/'.matchstr(getline('.'),': *\zs.\{-\}\ze\%( ([^()[:digit:]]\+)\)\=$')
|
||||
return s:Edit(a:mode,0,file)
|
||||
return [file]
|
||||
elseif getline('.') =~# '^#\t.'
|
||||
let file = '/'.matchstr(getline('.'),'#\t\zs.*')
|
||||
return s:Edit(a:mode,0,file)
|
||||
return [file]
|
||||
elseif getline('.') =~# ': needs merge$'
|
||||
let file = '/'.matchstr(getline('.'),'.*\ze: needs merge$')
|
||||
return s:Edit(a:mode,0,file).'|Gdiff'
|
||||
return [file, 'Gdiff!']
|
||||
|
||||
elseif getline('.') ==# '# Not currently on any branch.'
|
||||
return s:Edit(a:mode,0,'HEAD')
|
||||
return ['HEAD']
|
||||
elseif getline('.') =~# '^# On branch '
|
||||
let file = 'refs/heads/'.getline('.')[12:]
|
||||
return s:Edit(a:mode,0,file)
|
||||
return [file]
|
||||
elseif getline('.') =~# "^# Your branch .*'"
|
||||
let file = matchstr(getline('.'),"'\\zs\\S\\+\\ze'")
|
||||
return s:Edit(a:mode,0,file)
|
||||
return [file]
|
||||
endif
|
||||
|
||||
let showtree = (getline(1) =~# '^tree ' && getline(2) == "")
|
||||
@@ -2739,7 +2856,7 @@ function! s:GF(mode) abort
|
||||
|
||||
elseif getline('.') =~# '^commit \x\{40\}\>'
|
||||
let ref = matchstr(getline('.'),'\x\{40\}')
|
||||
return s:Edit(a:mode,0,ref)
|
||||
return [ref]
|
||||
|
||||
elseif getline('.') =~# '^parent \x\{40\}\>'
|
||||
let ref = matchstr(getline('.'),'\x\{40\}')
|
||||
@@ -2749,21 +2866,21 @@ function! s:GF(mode) abort
|
||||
let parent += 1
|
||||
let line -= 1
|
||||
endwhile
|
||||
return s:Edit(a:mode,0,ref)
|
||||
return [ref]
|
||||
|
||||
elseif getline('.') =~ '^tree \x\{40\}$'
|
||||
let ref = matchstr(getline('.'),'\x\{40\}')
|
||||
if s:repo().rev_parse(myhash.':') == ref
|
||||
let ref = myhash.':'
|
||||
endif
|
||||
return s:Edit(a:mode,0,ref)
|
||||
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.'$'
|
||||
return ''
|
||||
let ref = buffer.rev()
|
||||
|
||||
elseif getline('.') =~# '^\l\{3,8\} \x\{40\}\>'
|
||||
let ref = matchstr(getline('.'),'\x\{40\}')
|
||||
@@ -2784,18 +2901,25 @@ function! s:GF(mode) abort
|
||||
endwhile
|
||||
let offset += matchstr(getline(lnum), type.'\zs\d\+')
|
||||
let ref = getline(search('^'.type.'\{3\} [ab]/','bnW'))[4:-1]
|
||||
let dcmd = '+'.offset.'|normal! zv'
|
||||
let dref = ''
|
||||
let dcmds = [offset, 'normal!zv']
|
||||
|
||||
elseif getline('.') =~# '^rename from '
|
||||
let ref = 'a/'.getline('.')[12:]
|
||||
elseif getline('.') =~# '^rename to '
|
||||
let ref = 'b/'.getline('.')[10:]
|
||||
|
||||
elseif getline('.') =~# '^@@ -\d\+,\d\+ +\d\+,'
|
||||
let diff = getline(search('^diff --git \%(a/.*\|/dev/null\) \%(b/.*\|/dev/null\)', 'bcnW'))
|
||||
let offset = matchstr(getline('.'), '+\zs\d\+')
|
||||
|
||||
let dref = matchstr(diff, '\Cdiff --git \zs\%(a/.*\|/dev/null\)\ze \%(b/.*\|/dev/null\)')
|
||||
let ref = matchstr(diff, '\Cdiff --git \%(a/.*\|/dev/null\) \zs\%(b/.*\|/dev/null\)')
|
||||
let dcmd = 'Gdiff! +'.offset
|
||||
|
||||
elseif getline('.') =~# '^diff --git \%(a/.*\|/dev/null\) \%(b/.*\|/dev/null\)'
|
||||
let dref = matchstr(getline('.'),'\Cdiff --git \zs\%(a/.*\|/dev/null\)\ze \%(b/.*\|/dev/null\)')
|
||||
let ref = matchstr(getline('.'),'\Cdiff --git \%(a/.*\|/dev/null\) \zs\%(b/.*\|/dev/null\)')
|
||||
let dcmd = 'Gdiff'
|
||||
let dcmd = 'Gdiff!'
|
||||
|
||||
elseif getline('.') =~# '^index ' && getline(line('.')-1) =~# '^diff --git \%(a/.*\|/dev/null\) \%(b/.*\|/dev/null\)'
|
||||
let line = getline(line('.')-1)
|
||||
@@ -2807,7 +2931,7 @@ function! s:GF(mode) abort
|
||||
let ref = getline('.')
|
||||
|
||||
elseif expand('<cword>') =~# '^\x\{7,40\}\>'
|
||||
return s:Edit(a:mode,0,expand('<cword>'))
|
||||
return [expand('<cword>')]
|
||||
|
||||
else
|
||||
let ref = ''
|
||||
@@ -2833,16 +2957,38 @@ function! s:GF(mode) abort
|
||||
endif
|
||||
|
||||
if exists('dref')
|
||||
return s:Edit(a:mode,0,ref) . '|'.dcmd.' '.s:fnameescape(dref)
|
||||
return [ref, dcmd . ' ' . s:fnameescape(dref)] + dcmds
|
||||
elseif ref != ""
|
||||
return s:Edit(a:mode,0,ref)
|
||||
return [ref] + dcmds
|
||||
endif
|
||||
|
||||
endif
|
||||
return ''
|
||||
return []
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:GF(mode) abort
|
||||
try
|
||||
let results = s:cfile()
|
||||
catch /^fugitive:/
|
||||
return 'echoerr v:errmsg'
|
||||
endtry
|
||||
if len(results)
|
||||
return s:Edit(a:mode, 0, results[0]).join(map(results[1:-1], '"|".v:val'), '')
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! fugitive#cfile() abort
|
||||
let pre = ''
|
||||
let results = s:cfile()
|
||||
if empty(results)
|
||||
return expand('<cfile>')
|
||||
elseif len(results) > 1
|
||||
let pre = '+' . join(map(results[1:-1], 'escape(v:val, " ")'), '\|') . ' '
|
||||
endif
|
||||
return pre . s:fnameescape(fugitive#repo().translate(results[0]))
|
||||
endfunction
|
||||
|
||||
" Section: Statusline
|
||||
@@ -2880,6 +3026,11 @@ function! fugitive#head(...) abort
|
||||
return s:repo().head(a:0 ? a:1 : 0)
|
||||
endfunction
|
||||
|
||||
augroup fugitive_statusline
|
||||
autocmd!
|
||||
autocmd User Flags call Hoist('buffer', function('fugitive#statusline'))
|
||||
augroup END
|
||||
|
||||
" Section: Folding
|
||||
|
||||
function! fugitive#foldtext() abort
|
||||
|
||||
Reference in New Issue
Block a user