diff --git a/README.md b/README.md index 6e3adb1..13101cc 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ Commands | `History/` | Search history | | `Snippets` | Snippets ([UltiSnips][us]) | | `Commits` | Git commits (requires [fugitive.vim][f]) | +| `BCommits` | Git commits for the current buffer | | `Commands` | Commands | | `Helptags` | Help tags [1](#helptags) | diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index d626c35..6f8a73c 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -615,7 +615,7 @@ function! fzf#vim#windows(...) endfunction " ------------------------------------------------------------------ -" Commits +" Commits / BCommits " ------------------------------------------------------------------ function! s:commits_sink(lines) if len(a:lines) < 2 @@ -641,20 +641,35 @@ function! s:commits_sink(lines) endfor endfunction -function! fzf#vim#commits(...) +function! s:commits(buffer_local, args) let s:git_root = s:chomp(system('git rev-parse --show-toplevel')) if v:shell_error call s:warn('Not in git repository') return endif + let source = 'git log --graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"' + let current = expand('%:S') + let managed = 0 + if !empty(current) + call system('git show '.current.' 2> /dev/null') + let managed = !v:shell_error + endif + + if a:buffer_local + if !managed + call s:warn('The current buffer is not in the working tree') + return + endif + let source .= ' --follow '.current + endif + let options = { - \ 'source': 'git log --graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"', + \ 'source': source, \ 'sink*': function('s:commits_sink'), \ 'options': '--ansi --multi --no-sort --reverse --inline-info --prompt "Commits> "'.s:expect() \ } - let current = expand('%:S') if !empty(current) call system('git show '.current) if !v:shell_error @@ -662,7 +677,15 @@ function! fzf#vim#commits(...) endif endif - call s:fzf(options, a:000) + call s:fzf(options, a:args) +endfunction + +function! fzf#vim#commits(...) + return s:commits(0, a:000) +endfunction + +function! fzf#vim#buffer_commits(...) + return s:commits(1, a:000) endfunction " ---------------------------------------------------------------------------- diff --git a/doc/fzf-vim.txt b/doc/fzf-vim.txt index 9ec1fec..f21ad49 100644 --- a/doc/fzf-vim.txt +++ b/doc/fzf-vim.txt @@ -90,6 +90,7 @@ COMMANDS *fzf-vim-commands* `History/` | Search history `Snippets` | Snippets ({UltiSnips}{6}) `Commits` | Git commits (requires {fugitive.vim}{7}) + `BCommits` | Git commits for the current buffer `Commands` | Commands `Helptags` | Help tags [1] -----------------+--------------------------------------------------------------------- diff --git a/plugin/fzf.vim b/plugin/fzf.vim index c9ecece..1a9e64b 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -45,6 +45,7 @@ command! -bang Marks call fzf#vim#marks(s:w(0)) command! -bang Helptags call fzf#vim#helptags(s:w(0)) command! -bang Windows call fzf#vim#windows(s:w(0)) command! -bang Commits call fzf#vim#commits(s:w(0)) +command! -bang BCommits call fzf#vim#buffer_commits(s:w(0)) function! s:history(arg, bang) let bang = a:bang || a:arg[len(a:arg)-1] == '!'