comparison plugin/lawrencium.vim @ 18:4f04d5e052eb

Abort commit if the commit message is empty. Slightly better error reporting.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 13 Dec 2011 17:30:14 -0800
parents 5c6c605d0660
children d0acefc1ec9a
comparison
equal deleted inserted replaced
17:5c6c605d0660 18:4f04d5e052eb
58 function! s:trace(message, ...) 58 function! s:trace(message, ...)
59 if g:lawrencium_trace || (a:0 && a:1) 59 if g:lawrencium_trace || (a:0 && a:1)
60 let l:message = "lawrencium: " . a:message 60 let l:message = "lawrencium: " . a:message
61 echom l:message 61 echom l:message
62 endif 62 endif
63 endfunction
64
65 " Prints an error message with 'lawrencium error' prefixed to it.
66 function! s:error(message)
67 echom "lawrencium error: " . a:message
63 endfunction 68 endfunction
64 69
65 " Throw a Lawrencium exception message. 70 " Throw a Lawrencium exception message.
66 function! s:throw(message) 71 function! s:throw(message)
67 let v:errmsg = "lawrencium: " . a:message 72 let v:errmsg = "lawrencium: " . a:message
258 " Include the generated HG usage file. 263 " Include the generated HG usage file.
259 let s:usage_file = expand("<sfile>:h:h") . "/resources/hg_usage.vim" 264 let s:usage_file = expand("<sfile>:h:h") . "/resources/hg_usage.vim"
260 if filereadable(s:usage_file) 265 if filereadable(s:usage_file)
261 execute "source " . s:usage_file 266 execute "source " . s:usage_file
262 else 267 else
263 echoerr "Can't find the Mercurial usage file. Auto-completion will be disabled in Lawrencium." 268 call s:error("Can't find the Mercurial usage file. Auto-completion will be disabled in Lawrencium.")
264 endif 269 endif
265 270
266 function! s:CompleteHg(ArgLead, CmdLine, CursorPos) 271 function! s:CompleteHg(ArgLead, CmdLine, CursorPos)
267 " Don't do anything if the usage file was not sourced. 272 " Don't do anything if the usage file was not sourced.
268 if !exists('g:lawrencium_hg_commands') || !exists('g:lawrencium_hg_options') 273 if !exists('g:lawrencium_hg_commands') || !exists('g:lawrencium_hg_options')
399 function! s:HgStatus_FileAdd() abort 404 function! s:HgStatus_FileAdd() abort
400 " Get the path of the file the cursor is on, and its status. 405 " Get the path of the file the cursor is on, and its status.
401 let l:filename = s:HgStatus_GetSelectedPath() 406 let l:filename = s:HgStatus_GetSelectedPath()
402 let l:status = s:HgStatus_GetSelectedStatus() 407 let l:status = s:HgStatus_GetSelectedStatus()
403 if l:status !=# '?' 408 if l:status !=# '?'
404 echoerr "Not an untracked file: " . l:filename 409 call s:error("Not an untracked file: " . l:filename)
405 endif 410 endif
406 411
407 " Add the file. 412 " Add the file.
408 let l:repo = s:hg_repo() 413 let l:repo = s:hg_repo()
409 call l:repo.RunCommand('add', l:filename) 414 call l:repo.RunCommand('add', l:filename)
580 endfunction 585 endfunction
581 586
582 function! s:HgCommit_Execute(log_file, show_output) abort 587 function! s:HgCommit_Execute(log_file, show_output) abort
583 " Check if the user actually saved a commit message. 588 " Check if the user actually saved a commit message.
584 if !filereadable(a:log_file) 589 if !filereadable(a:log_file)
585 call s:trace("Commit message was not saved... abort commit.", 1) 590 call s:error("abort: Commit message not saved")
586 return 591 return
587 endif 592 endif
588 593
589 call s:trace("Committing with log file: " . a:log_file) 594 call s:trace("Committing with log file: " . a:log_file)
590 595
591 " Clean up all the 'HG:' lines from the commit message. 596 " Clean up all the 'HG:' lines from the commit message, and see if there's
597 " any message left (Mercurial does this automatically, usually, but
598 " apparently not when you feed it a log file...).
592 let l:lines = readfile(a:log_file) 599 let l:lines = readfile(a:log_file)
593 call filter(l:lines, "v:val !~# '\\v^HG:'") 600 call filter(l:lines, "v:val !~# '\\v^HG:'")
601 if len(filter(copy(l:lines), "v:val !~# '\\v^\\s*$'")) == 0
602 call s:error("abort: Empty commit message")
603 return
604 endif
594 call writefile(l:lines, a:log_file) 605 call writefile(l:lines, a:log_file)
595 606
596 " Get the repo and commit with the given message. 607 " Get the repo and commit with the given message.
597 let l:repo = s:hg_repo() 608 let l:repo = s:hg_repo()
598 let l:output = l:repo.RunCommand('commit', '-l', a:log_file) 609 let l:output = l:repo.RunCommand('commit', '-l', a:log_file)