Support .git-file repositories

This supports the new submodule structure and closes #139.
This commit is contained in:
Tim Pope
2012-03-14 22:02:20 -04:00
parent 85639a20fb
commit 0949a2e639

View File

@@ -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