]>
Commit | Line | Data |
---|---|---|
0d23b6e5 BB |
1 | " Vim filetype plugin |
2 | " Language: git commit file | |
3 | " Maintainer: Tim Pope <vimNOSPAM@tpope.org> | |
4 | ||
5 | " Only do this when not done yet for this buffer | |
6 | if (exists("b:did_ftplugin")) | |
7 | finish | |
8 | endif | |
9 | ||
10 | runtime! ftplugin/git.vim | |
11 | let b:did_ftplugin = 1 | |
12 | ||
13 | set nomodeline | |
14 | ||
15 | let b:undo_ftplugin = 'setl modeline<' | |
16 | ||
17 | if &textwidth == 0 | |
18 | " make sure that log messages play nice with git-log on standard terminals | |
19 | setlocal textwidth=72 | |
20 | let b:undo_ftplugin .= "|setl tw<" | |
21 | endif | |
22 | ||
23 | if exists("g:no_gitcommit_commands") || v:version < 700 | |
24 | finish | |
25 | endif | |
26 | ||
27 | if !exists("b:git_dir") | |
28 | let b:git_dir = expand("%:p:h") | |
29 | endif | |
30 | ||
31 | " Automatically diffing can be done with: | |
32 | " autocmd BufRead *.git/COMMIT_EDITMSG DiffGitCached | wincmd p | |
33 | command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>) | |
34 | ||
35 | function! s:diffcomplete(A,L,P) | |
36 | let args = "" | |
37 | if a:P <= match(a:L." -- "," -- ")+3 | |
38 | let args = args . "-p\n--stat\n--shortstat\n--summary\n--patch-with-stat\n--no-renames\n-B\n-M\n-C\n" | |
39 | end | |
40 | if exists("b:git_dir") && a:A !~ '^-' | |
41 | let tree = fnamemodify(b:git_dir,':h') | |
42 | if strpart(getcwd(),0,strlen(tree)) == tree | |
43 | let args = args."\n".system("git diff --cached --name-only") | |
44 | endif | |
45 | endif | |
46 | return args | |
47 | endfunction | |
48 | ||
49 | function! s:gitdiffcached(bang,gitdir,...) | |
50 | let tree = fnamemodify(a:gitdir,':h') | |
51 | let name = tempname() | |
52 | let git = "git" | |
53 | if strpart(getcwd(),0,strlen(tree)) != tree | |
54 | let git .= " --git-dir=".(exists("*shellescape") ? shellescape(a:gitdir) : '"'.a:gitdir.'"') | |
55 | endif | |
56 | if a:0 | |
57 | let extra = join(map(copy(a:000),exists("*shellescape") ? 'shellescape(v:val)' : "'\"'.v:val.'\"'")) | |
58 | else | |
59 | let extra = "-p --stat=".&columns | |
60 | endif | |
61 | call system(git." diff --cached --no-color ".extra." > ".(exists("*shellescape") ? shellescape(name) : name)) | |
62 | exe "pedit ".(exists("*fnameescape") ? fnameescape(name) : name) | |
63 | wincmd P | |
64 | let b:git_dir = a:gitdir | |
65 | command! -bang -bar -buffer -complete=custom,s:diffcomplete -nargs=* DiffGitCached :call s:gitdiffcached(<bang>0,b:git_dir,<f-args>) | |
66 | nnoremap <silent> q :q<CR> | |
67 | setlocal buftype=nowrite nobuflisted noswapfile nomodifiable filetype=git | |
68 | endfunction |