Permalink
Browse files

fix git commit.

add svn commit.
  • Loading branch information...
1 parent ac45d34 commit 8dff80500c9f0c6657a35871db7f9abdaabca974 @hrsh7th committed Oct 5, 2012
Showing with 95 additions and 26 deletions.
  1. +30 −16 autoload/vcs/git/commit.vim
  2. +2 −0 autoload/vcs/svn.vim
  3. +63 −10 autoload/vcs/svn/commit.vim
@@ -1,9 +1,16 @@
let s:save_cpo = &cpo
set cpo&vim
+" TODO: refactor.
+
let s:files = []
function! vcs#git#commit#do(args)
+ if !empty(s:files)
+ echomsg 'you should finish previous commitment.'
+ return
+ endif
+
let s:files = type(a:args) == type([]) ? a:args : [a:args]
call system(join(['git', 'commit', '--include', join(vcs#escape(s:files), ' ')], ' '))
call vcs#execute(['tabedit', '.git/COMMIT_EDITMSG'])
@@ -21,22 +28,29 @@ function! s:commit()
let root = vcs#vcs('root', s:files)
let save = getcwd()
- call vcs#execute(['cd', root])
- try
- let lines = substitute(vcs#system([
- \ 'git',
- \ 'commit',
- \ '--include',
- \ '-F',
- \ '.git/COMMIT_EDITMSG',
- \ join(vcs#escape(s:files), ' ')
- \ ]), '\r', '', 'g')
- for line in split(lines, "\n")
- echomsg line . "\n"
- endfor
- catch
- endtry
- call vcs#execute(['cd', save])
+ let yesno = input('commit? (y/n): ')
+ if yesno == 'y'
+ call vcs#execute(['cd', root])
+ try
+ let lines = substitute(vcs#system([
+ \ 'git',
+ \ 'commit',
+ \ '--include',
+ \ '-F',
+ \ '.git/COMMIT_EDITMSG',
+ \ join(vcs#escape(s:files), ' ')
+ \ ]), '\r', '', 'g')
+
+ echomsg ' '
+ for line in split(lines, "\n")
+ echomsg line
+ endfor
+ catch
+ endtry
+ call vcs#execute(['cd', save])
+ endif
+
+ let s:files = []
endfunction
let &cpo = s:save_cpo
View
@@ -2,6 +2,8 @@ let s:save_cpo = &cpo
set cpo&vim
let g:vcs#svn#log_separator = '------------------------------------------------------------------------'
+let g:vcs#svn#commit_msgfile= 'svn-commit.tmp'
+let g:vcs#svn#commit_ignore = '--This line, and those below, will be ignored--'
let &cpo = s:save_cpo
unlet s:save_cpo
@@ -1,17 +1,70 @@
let s:save_cpo = &cpo
set cpo&vim
+" TODO: refactor.
+
+let s:files = []
+
function! vcs#svn#commit#do(args)
- let files = type(a:args) == type([]) ? a:args : [a:args]
- " TODO: collect windows.
- call vcs#execute([
- \ '!',
- \ 'svn',
- \ '--editor-cmd',
- \ 'vim',
- \ 'commit',
- \ join(vcs#escape(files), ' ')
- \])
+ if !empty(s:files)
+ echomsg 'you should finish previous commitment.'
+ return
+ endif
+
+ let s:files = type(a:args) == type([]) ? a:args : [a:args]
+ call s:make_msgfile()
+ call vcs#execute(['tabedit', g:vcs#svn#commit_msgfile])
+
+ augroup VimUniteVcsSvnCommit
+ autocmd!
+ autocmd! BufWinEnter <buffer> setlocal bufhidden=delete nobuflisted noswapfile
+ autocmd! BufWritePre <buffer> g/^#\|^\s*$/d
+ autocmd! BufWinLeave <buffer> call s:commit()
+ augroup END
+endfunction
+
+function! s:commit()
+ let root = vcs#vcs('root', s:files)
+ let save = getcwd()
+ call vcs#execute(['cd', root])
+
+ let yesno = input('commit? (y/n): ')
+ if yesno == 'y'
+ try
+ let lines = substitute(vcs#system([
+ \ 'svn',
+ \ 'commit',
+ \ '-F',
+ \ g:vcs#svn#commit_msgfile,
+ \ join(vcs#escape(s:files), ' ')
+ \ ]), '\r', '', 'g')
+
+ echomsg ' '
+ for line in split(lines, "\n")
+ echomsg line
+ endfor
+ catch
+ endtry
+ endif
+ if filereadable(g:vcs#svn#commit_msgfile)
+ call delete(g:vcs#svn#commit_msgfile)
+ endif
+ call vcs#execute(['cd', save])
+
+ let s:files = []
+endfunction
+
+function! s:make_msgfile()
+ let root = vcs#vcs('root', s:files)
+ let save = getcwd()
+
+ call vcs#execute(['cd', root])
+ try
+ let status = map(vcs#vcs('status', s:files), "v:val.status . v:val.path[len(root) + 1:-1]")
+ call writefile(['', g:vcs#svn#commit_ignore, ''] + status, g:vcs#svn#commit_msgfile)
+ catch
+ endtry
+ call vcs#execute(['cd', save])
endfunction
let &cpo = s:save_cpo

0 comments on commit 8dff805

Please sign in to comment.