2 " Language: git config file
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.info>
4 " Last Change: 2007 Dec 16
6 " Only do this when not done yet for this buffer
7 if (exists("b:did_ftplugin"))
10 let b:did_ftplugin = 1
12 " allow gf to work even if in a subdirectory
13 let b:git_dir = expand("%:p:h")
14 let &l:path = fnamemodify(b:git_dir,':h').",".&l:path
15 let b:undo_ftplugin = "setl path<"
18 " make sure that log messages play nice with git-log on standard terminals
20 let b:undo_ftplugin = b:undo_ftplugin . " tw<"
23 if exists("g:no_gitcommit_commands")
27 " Automatically diffing can be done with:
28 " autocmd FileType gitcommit DiffGitCached | wincmd p
29 command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>)
31 function! s:diffcomplete(A,L,P)
35 if a:P <= match(a:L." -- "," -- ")+3
36 let args = args . "-p\n--stat\n--shortstat\n--summary\n--patch-with-stat\n--no-renames\n-B\n-M\n-C\n"
38 if exists("b:git_dir") && a:A !~ '^-'
39 let tree = fnamemodify(b:git_dir,':h')
40 if strpart(getcwd(),0,strlen(tree)) == tree
41 let args = args."\n".system("git diff --cached --name-only")
47 function! s:gitdiffcached(bang,gitdir,...)
48 let tree = fnamemodify(a:gitdir,':h')
51 if strpart(getcwd(),0,strlen(tree)) != tree
54 let $GIT_DIR = a:gitdir
56 " Can't unset an env var, so use shell syntax instead
57 let prefix = 'GIT_DIR='.shellescape(a:gitdir).' '
61 let extra = join(map(copy(a:000),has("*shellescape") ? 'shellescape(v:val)' : "'\"'.v:val.'\"'"))
63 let extra = "-p --stat=".&columns
65 call system(prefix."git diff --cached --no-color ".extra." > ".name)
71 let b:git_dir = a:gitdir
72 command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>)
73 nnoremap <silent> q :q<CR>
74 set buftype=nowrite nobuflisted noswapfile nomodifiable
75 set filetype=diff includeexpr=substitute(v:fname,'^[ab]/','','')
76 if strpart(&l:path,0,strlen(tree)) != tree
77 let &l:path = tree.','.&l:path