Skip to content

Commit

Permalink
Error and abort if we'll be overwriting a non-ctags file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludovicchabant committed Aug 27, 2015
1 parent 02a9f07 commit ce4716a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions autoload/gutentags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ function! s:update_tags(module, write_mode, queue_mode) abort
try
call call("gutentags#".a:module."#generate",
\[l:proj_dir, l:tags_file, a:write_mode])
catch /^gutentags\:/
echom "Error while generating ".a:module." file:"
echom v:exception
finally
" Restore the current directory...
execute "chdir " . fnameescape(l:prev_cwd)
Expand Down
14 changes: 13 additions & 1 deletion autoload/gutentags/ctags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort
" these things.
let l:prev_cwd = getcwd()
let l:work_dir = fnamemodify(a:tags_file, ':h')
let l:tags_file_exists = filereadable(a:tags_file)

if l:tags_file_exists
let l:first_lines = readfile(a:tags_file, '', 1)
if len(l:first_lines) == 0 || stridx(l:first_lines[0], '!_TAG_') != 0
call gutentags#throw("File ".a:tags_file." doesn't appear to be ".
\"a ctags file. Please delete it and run ".
\":GutentagsUpdate!.")
return
endif
endif

execute "chdir " . fnameescape(l:work_dir)

try
Expand All @@ -48,7 +60,7 @@ function! gutentags#ctags#generate(proj_dir, tags_file, write_mode) abort
let l:cmd .= ' -e "' . s:get_ctags_executable() . '"'
let l:cmd .= ' -t "' . a:tags_file . '"'
let l:cmd .= ' -p "' . a:proj_dir . '"'
if a:write_mode == 0 && filereadable(a:tags_file)
if a:write_mode == 0 && l:tags_file_exists
let l:full_path = expand('%:p')
let l:cmd .= ' -s "' . l:full_path . '"'
endif
Expand Down

0 comments on commit ce4716a

Please sign in to comment.