1
1
" Vim filetype plugin
2
2
" Language: git config file
3
3
" Maintainer: Tim Pope <vimNOSPAM@tpope.info>
4
" Last Change: 2007 Dec 16
4
" Last Change: 2008 Jun 04
6
6
" Only do this when not done yet for this buffer
7
7
if (exists("b:did_ftplugin"))
11
runtime! ftplugin/git.vim
10
12
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
15
" make sure that log messages play nice with git-log on standard terminals
19
16
setlocal textwidth=72
20
let b:undo_ftplugin = b:undo_ftplugin . " tw<"
17
if !exists("b:undo_ftplugin")
18
let b:undo_ftplugin = ""
20
let b:undo_ftplugin = b:undo_ftplugin . "|setl tw<"
23
if exists("g:no_gitcommit_commands")
23
if exists("g:no_gitcommit_commands") || v:version < 700
27
if !exists("b:git_dir")
28
let b:git_dir = expand("%:p:h")
27
31
" Automatically diffing can be done with:
28
32
" autocmd FileType gitcommit DiffGitCached | wincmd p
29
33
command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>)
45
49
function! s:gitdiffcached(bang,gitdir,...)
46
50
let tree = fnamemodify(a:gitdir,':h')
47
51
let name = tempname()
49
53
if strpart(getcwd(),0,strlen(tree)) != tree
52
let $GIT_DIR = a:gitdir
54
" Can't unset an env var, so use shell syntax instead
55
let prefix = 'GIT_DIR='.shellescape(a:gitdir).' '
54
let git .= " --git-dir=".(exists("*shellescape") ? shellescape(a:gitdir) : '"'.a:gitdir.'"')
59
let extra = join(map(copy(a:000),has("*shellescape") ? 'shellescape(v:val)' : "'\"'.v:val.'\"'"))
57
let extra = join(map(copy(a:000),exists("*shellescape") ? 'shellescape(v:val)' : "'\"'.v:val.'\"'"))
61
59
let extra = "-p --stat=".&columns
63
call system(prefix."git diff --cached --no-color ".extra." > ".name)
61
call system(git." diff --cached --no-color ".extra." > ".(exists("*shellescape") ? shellescape(name) : name))
62
exe "pedit ".(exists("*fnameescape") ? fnameescape(name) : name)
69
64
let b:git_dir = a:gitdir
70
65
command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>)
71
66
nnoremap <silent> q :q<CR>
72
setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=diff
73
setlocal keywordprg=git\ show includeexpr=substitute(v:fname,'^[ab]/','','')
74
if strpart(&l:path,0,strlen(tree)) != tree
75
let &l:path = tree.','.&l:path
67
setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=git