Skip to content
Snippets Groups Projects
Commit 0036bef4 authored by Jerome Reybert's avatar Jerome Reybert
Browse files

plugin/magit.vim: print an understandable message for bad stage selections (fix #30)

parent 3c3baa32
Branches
Tags
No related merge requests found
...@@ -736,7 +736,20 @@ function! magit#stage_file() ...@@ -736,7 +736,20 @@ function! magit#stage_file()
call <SID>mg_stage_closed_file(0) call <SID>mg_stage_closed_file(0)
return return
catch 'out_of_block' catch 'out_of_block'
try
let [start, end] = <SID>mg_select_file_block() let [start, end] = <SID>mg_select_file_block()
catch /^out_of_block$/
echohl ErrorMsg
echomsg "Error while staging."
echohl None
echomsg "Your cursor must be:"
echomsg " - on a file header line"
echomsg " - or on a hunk header line"
echomsg " - or within a hunk"
echomsg "If you repect one of previous points, please open a new issue:"
echomsg "https://github.com/jreybert/vimagit/issues/new"
return
endtry
let selection = getline(start, end) let selection = getline(start, end)
endtry endtry
return magit#stage_block(selection, 0) return magit#stage_block(selection, 0)
...@@ -758,7 +771,20 @@ function! magit#stage_hunk(discard) ...@@ -758,7 +771,20 @@ function! magit#stage_hunk(discard)
try try
let [start,end] = <SID>mg_select_hunk_block() let [start,end] = <SID>mg_select_hunk_block()
catch 'out_of_block' catch 'out_of_block'
try
let [start,end] = <SID>mg_select_file_block() let [start,end] = <SID>mg_select_file_block()
catch /^out_of_block$/
echohl ErrorMsg
echomsg "Error while staging."
echohl None
echomsg "Your cursor must be:"
echomsg " - on a file header line"
echomsg " - or on a hunk header line"
echomsg " - or within a hunk"
echomsg "If you repect one of previous points, please open a new issue:"
echomsg "https://github.com/jreybert/vimagit/issues/new"
return
endtry
endtry endtry
let marked_lines = magit#sign#find_stage_signs(start, end) let marked_lines = magit#sign#find_stage_signs(start, end)
if ( empty(marked_lines) ) if ( empty(marked_lines) )
...@@ -786,7 +812,19 @@ function! magit#stage_vselect() range ...@@ -786,7 +812,19 @@ function! magit#stage_vselect() range
call add(lines, curline) call add(lines, curline)
let curline += 1 let curline += 1
endwhile endwhile
try
let selection = <SID>mg_create_diff_from_select(lines) let selection = <SID>mg_create_diff_from_select(lines)
catch /^out_of_block$/
echohl ErrorMsg
echomsg "Error while staging a visual selection."
echohl None
echomsg "Visual selection staging has currently some limitations:"
echomsg " - selection must be limited within a single hunk"
echomsg " - only work for staging, not for unstaging"
echomsg "If you repect current limitations, please open a new issue:"
echomsg "https://github.com/jreybert/vimagit/issues/new"
return
endtry
return magit#stage_block(selection, 0) return magit#stage_block(selection, 0)
endfunction endfunction
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment