Skip to content

Commit

Permalink
Merge pull request #55 from bakunyo/close-commit-for-next
Browse files Browse the repository at this point in the history
Commit 'Write commit message to .git/COMMIT_EDITMSG' must be completed.
  • Loading branch information
jreybert committed Dec 14, 2015
2 parents 1003381 + d8adf2d commit 35570fa
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ Following mappings are set locally, for magit buffer only, in normal mode.
##### CF
* Amend the staged changes into the previous commit, without modifying previous commit message.

##### CU
* Close a commit section (If you need soon after open or editing commit message, pressing 'u' is good enough).

##### I
* Add the file under the cursor in .gitgnore

Expand Down
5 changes: 5 additions & 0 deletions doc/vimagit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ Following mappings are set locally, for magit buffer only, in normal mode.
CF Amend the staged changes into the previous commit, without
modifying previous commit message

*vimagit-CU* *magit#close_commit()*
*vimagit-g:magit_close_commit_mapping*
CU Close a commit section (If you need soon after open or editing
Ucommit message, pressing 'u' is good enough).

*vimagit-I* *magit#ignore_file()*
*vimagit-g:magit_ignore_mapping*
I Add the file under the cursor in .gitgnore
Expand Down
20 changes: 20 additions & 0 deletions plugin/magit.vim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let g:magit_discard_hunk_mapping = get(g:, 'magit_discard_hunk_mapping',
let g:magit_commit_mapping = get(g:, 'magit_commit_mapping', 'CC' )
let g:magit_commit_amend_mapping = get(g:, 'magit_commit_amend_mapping', 'CA' )
let g:magit_commit_fixup_mapping = get(g:, 'magit_commit_fixup_mapping', 'CF' )
let g:magit_close_commit_mapping = get(g:, 'magit_close_commit_mapping', 'CU' )
let g:magit_reload_mapping = get(g:, 'magit_reload_mapping', 'R' )
let g:magit_ignore_mapping = get(g:, 'magit_ignore_mapping', 'I' )
let g:magit_close_mapping = get(g:, 'magit_close_mapping', 'q' )
Expand Down Expand Up @@ -661,6 +662,7 @@ function! magit#show_magit(display, ...)
execute "nnoremap <buffer> <silent> " . g:magit_commit_mapping . " :call magit#commit_command('CC')<cr>"
execute "nnoremap <buffer> <silent> " . g:magit_commit_amend_mapping . " :call magit#commit_command('CA')<cr>"
execute "nnoremap <buffer> <silent> " . g:magit_commit_fixup_mapping . " :call magit#commit_command('CF')<cr>"
execute "nnoremap <buffer> <silent> " . g:magit_close_commit_mapping . " :call magit#close_commit()<cr>"
execute "nnoremap <buffer> <silent> " . g:magit_ignore_mapping . " :call magit#ignore_file()<cr>"
execute "nnoremap <buffer> <silent> " . g:magit_close_mapping . " :call magit#close_magit()<cr>"
execute "nnoremap <buffer> <silent> " . g:magit_toggle_help_mapping . " :call magit#toggle_help()<cr>"
Expand Down Expand Up @@ -926,6 +928,24 @@ function! magit#commit_command(mode)
call magit#update_buffer()
endfunction

" magit#close_commit: cancel for commit mode
" close commit section if opened
function! magit#close_commit()
if ( b:magit_current_commit_mode == '' )
return
endif

let git_dir=magit#git#git_dir()
let commit_editmsg=git_dir . 'COMMIT_EDITMSG'
if ( filereadable(commit_editmsg) )
let commit_msg=s:mg_get_commit_msg()
call writefile(commit_msg, commit_editmsg)
endif

let b:magit_current_commit_mode=''
call magit#update_buffer()
endfunction

" magit#jump_hunk: function to jump among hunks
" it closes the current fold (if any), jump to next hunk and unfold it
" param[in] dir: can be 'N' (for next) or 'P' (for previous)
Expand Down

0 comments on commit 35570fa

Please sign in to comment.