From 0036bef40331b6a69c6a8a77e6c73775e5045030 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Wed, 4 Nov 2015 23:52:56 +0100 Subject: [PATCH] plugin/magit.vim: print an understandable message for bad stage selections (fix #30) --- plugin/magit.vim | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index 8607817..31afbf2 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -736,7 +736,20 @@ function! magit#stage_file() call mg_stage_closed_file(0) return catch 'out_of_block' - let [start, end] = mg_select_file_block() + try + let [start, end] = 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) endtry return magit#stage_block(selection, 0) @@ -758,7 +771,20 @@ function! magit#stage_hunk(discard) try let [start,end] = mg_select_hunk_block() catch 'out_of_block' - let [start,end] = mg_select_file_block() + try + let [start,end] = 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 let marked_lines = magit#sign#find_stage_signs(start, end) if ( empty(marked_lines) ) @@ -786,7 +812,19 @@ function! magit#stage_vselect() range call add(lines, curline) let curline += 1 endwhile - let selection = mg_create_diff_from_select(lines) + try + let selection = 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) endfunction