From a8c96b6020182ca648c76e4ed83320958100218d Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Wed, 2 Oct 2013 10:18:33 -0400 Subject: [PATCH] parse out submodule path when not in a .git directory (#273). --- autoload/airline/extensions/branch.vim | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/autoload/airline/extensions/branch.vim b/autoload/airline/extensions/branch.vim index 9705d7e5..254ce7b9 100644 --- a/autoload/airline/extensions/branch.vim +++ b/autoload/airline/extensions/branch.vim @@ -41,10 +41,18 @@ function! s:check_in_path() let root = get(b:, 'git_dir', get(b:, 'mercurial_dir', '')) let bufferpath = resolve(fnamemodify(expand('%'), ':p:h')) - " .git may be a repo or a file depending on the version of git for submodules - if !filereadable(root) - let root = expand(fnamemodify(root, ':h')) + if !filereadable(root) "not a file + " if .git is a directory, it's the old submodule format + if match(root, '\.git$') >= 0 + let root = expand(fnamemodify(root, ':h')) + else + " else it's the newer format, and we need to guesstimate + let pattern = '\.git\(\\\|\/\)modules\(\\\|\/\)' + if match(root, pattern) >= 0 + let root = substitute(root, pattern, '', '') + endif endif + let b:airline_file_in_root = stridx(bufferpath, root) > -1 endif return b:airline_file_in_root