diff --git a/README.md b/README.md index 73685723c14f195a0cf14b0905730eabc77c9c77..70280bee17b86ce3d21a77abb39ac16809decded 100644 --- a/README.md +++ b/README.md @@ -225,7 +225,7 @@ E means 'edit'. ##### q * Close the magit buffer -##### h +##### ? * Toggle help showing in magit buffer #### Autocommand events diff --git a/autoload/magit/utils.vim b/autoload/magit/utils.vim index fc9d17e8863892d118f12b8634e1aa5cafc7faae..84d26bcb74b61e5bd28c0bfde4e277c58e2844a4 100644 --- a/autoload/magit/utils.vim +++ b/autoload/magit/utils.vim @@ -120,12 +120,13 @@ endfunction " param[in] array: array to strop " return: stripped array function! magit#utils#strip_array(array) + let array_len = len(a:array) let start = 0 - while ( a:array[start] == '' ) + while ( start < array_len && a:array[start] == '' ) let start += 1 endwhile - let end = len(a:array) - 1 - while ( a:array[end] == '' ) + let end = array_len - 1 + while ( end >= 0 && a:array[end] == '' ) let end -= 1 endwhile return a:array[ start : end ] diff --git a/doc/vimagit.txt b/doc/vimagit.txt index f6f6947c4d522b204f393d2771965501963d5b14..a3e35ca903304c1e32edc4b84c0a6407b00b7504 100644 --- a/doc/vimagit.txt +++ b/doc/vimagit.txt @@ -265,9 +265,9 @@ Following mappings are set locally, for magit buffer only, in normal mode. *vimagit-g:magit_close_mapping* q close magit buffer. - *vimagit-h* *magit#toggle_help()* + *vimagit-?* *magit#toggle_help()* *vimagit-g:magit_toggle_help_mapping* - h Toggle help showing in magit buffer + ? Toggle help showing in magit buffer AUTOCMD *vimagit-autocmd* diff --git a/plugin/magit.vim b/plugin/magit.vim index f2d077b4d5d4e9bade7d96b07a9ab1469cb29a25..a930b7575bdcc8f07133636db9d73dc69e0b1d37 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -32,7 +32,7 @@ let g:magit_reload_mapping = get(g:, 'magit_reload_mapping', let g:magit_edit_mapping = get(g:, 'magit_edit_mapping', 'E' ) let g:magit_ignore_mapping = get(g:, 'magit_ignore_mapping', 'I' ) let g:magit_close_mapping = get(g:, 'magit_close_mapping', 'q' ) -let g:magit_toggle_help_mapping = get(g:, 'magit_toggle_help_mapping', 'h' ) +let g:magit_toggle_help_mapping = get(g:, 'magit_toggle_help_mapping', '?' ) let g:magit_folding_toggle_mapping = get(g:, 'magit_folding_toggle_mapping', [ '<CR>' ]) let g:magit_folding_open_mapping = get(g:, 'magit_folding_open_mapping', [ 'zo', 'zO' ]) @@ -372,16 +372,44 @@ function! s:mg_git_commit(mode) abort silent let git_result=magit#utils#system(g:magit_git_cmd . \ " commit --amend -C HEAD") else + let commit_flag="" + if ( empty( magit#get_staged_files() ) ) + let choice = confirm( + \ "Do you really want to commit without any staged files?", + \ "&Yes\n&No", 2) + if ( choice != 1 ) + return + else + let commit_flag.=" --allow-empty " + endif + endif + let commit_msg=s:mg_get_commit_msg() - let amend_flag="" + if ( empty( commit_msg ) ) + let choice = confirm( + \ "Do you really want to commit with an empty message?", + \ "&Yes\n&No", 2) + if ( choice != 1 ) + return + else + let commit_flag.=" --allow-empty-message " + endif + endif + if ( a:mode == 'CA' ) - let amend_flag=" --amend " + let commit_flag.=" --amend " endif - silent! let git_result=magit#utils#system(g:magit_git_cmd . - \ " commit " . amend_flag . " --file - ", commit_msg) + let commit_cmd=g:magit_git_cmd . " commit " . commit_flag . + \ " --file - " + silent! let git_result=magit#utils#system(commit_cmd, commit_msg) + let b:magit_current_commit_mode='' + let b:magit_current_commit_msg=[] endif if ( v:shell_error != 0 ) - echoerr "Git error: " . git_result + echohl ErrorMsg + echom "Git error: " . git_result + echom "Git cmd: " . commit_cmd + echohl None endif endfunction @@ -1048,8 +1076,6 @@ function! magit#commit_command(mode) " when we do commit, it is prefered ot commit the way we prepared it " (.i.e normal or amend), whatever we commit with CC or CA. call <SID>mg_git_commit(b:magit_current_commit_mode) - let b:magit_current_commit_mode='' - let b:magit_current_commit_msg=[] else let b:magit_current_commit_mode=a:mode let b:magit_commit_newly_open=1 @@ -1101,6 +1127,19 @@ function! magit#jump_hunk(dir) endif endfunction +" magit#get_staged_files: function returning an array with staged files names +" return: an array with staged files names +function! magit#get_staged_files() + return keys(b:state.dict.staged) +endfunction + +" magit#get_staged_files: function returning an array with unstaged files +" names +" return: an array with unstaged files names +function! magit#get_unstaged_files() + return keys(b:state.dict.unstaged) +endfunction + " magit#jump_to: function to move cursor to the file location of the current " hunk " if this file is already displayed in a window, jump to the window, if not,