Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command for close section for commit #55

Merged
merged 4 commits into from
Dec 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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