From bae02473055467c2edf672b5323daa09f8325d2e Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Mon, 18 Nov 2019 13:36:08 +0100 Subject: [PATCH] Fix bug in vim git commands Several commands that check out a new version of a file didn't jump to the correct position afterwards. --- git.vim | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/git.vim b/git.vim index 085198e..3183168 100644 --- a/git.vim +++ b/git.vim @@ -73,16 +73,16 @@ endfun function! s:git_info() if !exists("b:git_revision_hash") || !exists("b:git_original_file") - echo "Not a file@revision buffer!" - return + echom "Working copy or not in any repo" + return 0 end echo system("git show --no-patch ".b:git_revision_hash) endfun function! s:git_next() if !exists("b:git_revision_hash") || !exists("b:git_original_file") - echo "Error 01: Not a file@revision buffer!" - return + echom "Error 01: Not a file@revision buffer!" + return 0 end let l:history = s:git_history() let l:idx = index(l:history, b:git_revision_hash) @@ -134,8 +134,6 @@ function! s:file_at_revision(rev) silent exec "file ".l:ftail."@".a:rev exec "r!git show ".a:rev.":".l:fname 1,1del - let l:pos[0] = bufnr('.') - call setpos('.', l:pos) setl nomodifiable setl buftype=nofile setl bufhidden=delete @@ -143,6 +141,8 @@ function! s:file_at_revision(rev) let b:git_original_file = l:fname let b:git_revision_hash = a:rev + + call setpos('.', l:pos) endfun function! s:git_diff(...) @@ -156,7 +156,7 @@ function! s:git_diff(...) exec "normal \\" diffthis exec "normal \\" - cd l:wd + exec "cd ".l:wd else if exists("b:git_revision_hash") call s:git_diff(get(s:git_history(), index(s:git_history(), b:git_revision_hash)+1, "NIL")) @@ -175,10 +175,12 @@ endfun command! -range Blame echom join(uniq(sort(git_blame(, ))), ', ') command! -range DBlame !git blame % -L , command! GitNext try - \| call s:gitroot() | call git_next() - \| GitInfo - \| catch | echo 'Not a git repo!' + \| call gitroot() + \| call git_next() + \| catch + \| echo 'Not a git repo!' \| endtry + \| GitInfo command! GitPrev call git_prev() \| GitInfo command! GitFirst call git_first() | call s:git_info() @@ -187,11 +189,13 @@ command! GitInfo call git_info() command! -nargs=1 GitCheckout call file_at_revision() command! -nargs=? GitCompare try \| call s:gitroot() | call git_diff() - \| catch | echo 'Not a git repo!' + \| catch + \| echo 'Not a git repo!' \| endtry command! Uncommited try \| call git_diff() - \| catch | echo 'Not a git repo!' + \| catch + \| echo 'Not a git repo!' \| endtry command! GitRoot call cd_git_root('.') command! ShowGitRoot try