From bb3c4802bfe43cc5673d44aa7dd16714e3df5828 Mon Sep 17 00:00:00 2001
From: iaia <iaia72160@gmail.com>
Date: Wed, 1 Nov 2017 00:14:49 +0900
Subject: [PATCH] Handle commit set at the end of magit_default_sections

ref #149
---
 plugin/magit.vim | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/plugin/magit.vim b/plugin/magit.vim
index 0f1a975..879dca3 100644
--- a/plugin/magit.vim
+++ b/plugin/magit.vim
@@ -293,7 +293,13 @@ endfunction
 function! s:mg_get_commit_msg(...)
 	let commit_section_pat_start='^'.g:magit_sections.commit.'$'
 	" Get next section pattern with g:magit_default_sections order
-	let commit_section_pat_end='^'.g:magit_sections[g:magit_default_sections[match(g:magit_default_sections, 'commit')+1]].'$'
+	let commit_position = match(g:magit_default_sections, 'commit')
+	if ( commit_position + 1 == len(g:magit_default_sections) )
+	  let commit_section_pat_end='\%$'
+	else
+	  let commit_section_pat_end='^'.g:magit_sections[g:magit_default_sections[commit_position+1]].'$'
+	endif
+
 	let commit_jump_line = 2
 	let out_of_block = a:0 == 1 ? a:1 : 0
 	if ( out_of_block )
-- 
GitLab