From 0949a2e639187fa1907391e8ee178ca3549c793a Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 14 Mar 2012 22:02:20 -0400 Subject: [PATCH] Support .git-file repositories This supports the new submodule structure and closes #139. --- plugin/fugitive.vim | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/plugin/fugitive.vim b/plugin/fugitive.vim index 69e4b03..ebfb4de 100644 --- a/plugin/fugitive.vim +++ b/plugin/fugitive.vim @@ -121,8 +121,14 @@ function! s:extract_git_dir(path) abort let ofn = "" let nfn = fn while fn !=# ofn - if s:is_git_dir(s:sub(fn,'[\/]$','') . '/.git') + let embedded = s:sub(fn, '[\/]$', '') . '/.git' + if s:is_git_dir(embedded) return s:sub(simplify(fnamemodify(fn . '/.git',':p')),'\W$','') + elseif filereadable(embedded) + let line = readfile(embedded,1)[0] + if line =~# '^gitdir: ' + return line[8:-1] + endif elseif s:is_git_dir(fn) return s:sub(simplify(fnamemodify(fn,':p')),'\W$','') endif @@ -196,15 +202,28 @@ function! s:repo_dir(...) dict abort endfunction function! s:repo_tree(...) dict abort - if !self.bare() - let dir = fnamemodify(self.git_dir,':h') - return join([dir]+a:000,'/') + if self.dir() =~# '/\.git$' + let dir = self.dir()[0:-6] + else + 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') + endif endif - call s:throw('no work tree') + return join([dir]+a:000,'/') endfunction function! s:repo_bare() dict abort - return self.dir() !~# '/\.git$' + 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) + endtry endfunction function! s:repo_translate(spec) dict abort