Skip to content

Commit

Permalink
Look for SCM directories based on path of file in current buffer, not…
Browse files Browse the repository at this point in the history
… on getcwd() (nice catch Greg)
  • Loading branch information
Brian Shire committed Aug 18, 2008
1 parent f0d9b81 commit fdef919
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
1 change: 0 additions & 1 deletion TODO
Expand Up @@ -3,7 +3,6 @@ Bugs
* After exiting (:q) a buffer that has diff enabled, subsequent diffs appear to fail.
* Should restore options like 'wrap' to their original state when turning diff off
* winsaveview() and winrestview() require Vim 7.x. Autodetect and degrade gracefully.
* Look for SCM directories based on path of file in current buffer, not on getcwd()

Features

Expand Down
18 changes: 9 additions & 9 deletions scmdiff.vim
Expand Up @@ -40,30 +40,30 @@ endfunction
function! s:detectSCM()

" Cache the results we find here to save time
if exists("g:scmCWD") && g:scmCWD == getcwd() && exists("g:scmDiffCommand")
if exists("g:scmBufPath") && g:scmBufPath == expand("%:p:h") && exists("g:scmDiffCommand")
return
endif
let g:scmCWD = getcwd()
let g:scmBufPath = expand("%:p:h")

" Detect CVS or .svn directories in current path
if !exists("g:scmDiffCommand") && isdirectory(g:scmCWD."/.svn")
if !exists("g:scmDiffCommand") && isdirectory(g:scmBufPath."/.svn")
let g:scmDiffCommand = "svn"
return
endif

if !exists("g:scmDiffCommand") && isdirectory(g:scmCWD."/CVS")
if !exists("g:scmDiffCommand") && isdirectory(g:scmBufPath."/CVS")
let g:scmDiffCommand = "cvs"
return
endif

" Detect .git directories recursively in reverse
let my_cwd = g:scmCWD
while my_cwd != "/"
if !exists("g:scmDiffCommand") && isdirectory(my_cwd."/.git")
let my_path = g:scmBufPath
while my_path != "/"
if !exists("g:scmDiffCommand") && isdirectory(my_path."/.git")
let g:scmDiffCommand = "git"
return
endif
let my_cwd = simplify(my_cwd."/../")
let my_path = simplify(my_path."/../")
endwhile

endfunction
Expand Down Expand Up @@ -98,7 +98,7 @@ function! s:scmDiff(...)
let cmd = 'cat ' . bufname('%') . ' > ' . b:scmDiffTmpfile
let cmdOutput = system(cmd)
let tmpdiff = tempname()
let cmd = g:scmDiffCommand . ' diff ' . g:scmDiffRev . ' ' . bufname('%') . ' > ' . tmpdiff
let cmd = 'cd ' . g:scmBufPath . ' && ' . g:scmDiffCommand . ' diff ' . g:scmDiffRev . ' ' . expand('%:p') . ' > ' . tmpdiff
let cmdOutput = system(cmd)

if v:shell_error && cmdOutput != ''
Expand Down

0 comments on commit fdef919

Please sign in to comment.