commit c5cd0c96f7cff8cabf9733ff5e1cd093a3f2f348 (tree)
parent 6fc37993fe88de4d663fa4a43267c6f4fe1d04b2
Author: Tim Pope <code@tpope.net>
Date: Sun, 18 Mar 2012 22:09:46 -0400
Encapsulate logic for extracting tree from config
Diffstat:
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim
@@ -202,28 +202,35 @@ function! s:repo_dir(...) dict abort
return join([self.git_dir]+a:000,'/')
endfunction
-function! s:repo_tree(...) dict abort
- if self.dir() =~# '/\.git$'
- let dir = self.dir()[0:-6]
- else
+function! s:repo_configured_tree() dict abort
+ if filereadable(self.dir('config'))
let config = readfile(self.dir('config'),10)
call filter(config,'v:val =~# "^\\s*worktree *="')
if len(config) == 1
- let dir = matchstr(config[0], '= *\zs.*')
- else
- call s:throw('no work tree')
+ return matchstr(config[0], '= *\zs.*')
endif
endif
- return join([dir]+a:000,'/')
+ return ''
+endfunction
+
+function! s:repo_tree(...) dict abort
+ if self.dir() =~# '/\.git$'
+ let dir = self.dir()[0:-6]
+ else
+ let dir = self.configured_tree()
+ endif
+ if dir ==# ''
+ call s:throw('no work tree')
+ else
+ return join([dir]+a:000,'/')
+ endif
endfunction
function! s:repo_bare() dict abort
if self.dir() =~# '/\.git$'
return 0
else
- let config = readfile(self.dir('config'),10)
- call filter(config,'v:val =~# "^\\s*worktree *="')
- return (len(config) != 1)
+ return self.configured_tree() ==# ''
endtry
endfunction
@@ -268,7 +275,7 @@ function! s:repo_translate(spec) dict abort
endif
endfunction
-call s:add_methods('repo',['dir','tree','bare','translate'])
+call s:add_methods('repo',['dir','configured_tree','tree','bare','translate'])
function! s:repo_git_command(...) dict abort
let git = g:fugitive_git_executable . ' --git-dir='.s:shellesc(self.git_dir)