mirror of
https://github.com/junegunn/vim-plug.git
synced 2024-12-23 20:45:31 -07:00
Report when PlugClean fails to remove a directory (#985)
This commit is contained in:
parent
01aab60ade
commit
3aa3b5a4e8
22
plug.vim
22
plug.vim
@ -2271,7 +2271,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:rm_rf(dir)
|
function! s:rm_rf(dir)
|
||||||
if isdirectory(a:dir)
|
if isdirectory(a:dir)
|
||||||
call s:system(s:is_win
|
return s:system(s:is_win
|
||||||
\ ? 'rmdir /S /Q '.plug#shellescape(a:dir)
|
\ ? 'rmdir /S /Q '.plug#shellescape(a:dir)
|
||||||
\ : ['rm', '-rf', a:dir])
|
\ : ['rm', '-rf', a:dir])
|
||||||
endif
|
endif
|
||||||
@ -2355,6 +2355,7 @@ endfunction
|
|||||||
function! s:delete(range, force)
|
function! s:delete(range, force)
|
||||||
let [l1, l2] = a:range
|
let [l1, l2] = a:range
|
||||||
let force = a:force
|
let force = a:force
|
||||||
|
let err_count = 0
|
||||||
while l1 <= l2
|
while l1 <= l2
|
||||||
let line = getline(l1)
|
let line = getline(l1)
|
||||||
if line =~ '^- ' && isdirectory(line[2:])
|
if line =~ '^- ' && isdirectory(line[2:])
|
||||||
@ -2363,11 +2364,22 @@ function! s:delete(range, force)
|
|||||||
let answer = force ? 1 : s:ask('Delete '.line[2:].'?', 1)
|
let answer = force ? 1 : s:ask('Delete '.line[2:].'?', 1)
|
||||||
let force = force || answer > 1
|
let force = force || answer > 1
|
||||||
if answer
|
if answer
|
||||||
call s:rm_rf(line[2:])
|
let err = s:rm_rf(line[2:])
|
||||||
setlocal modifiable
|
setlocal modifiable
|
||||||
call setline(l1, '~'.line[1:])
|
if empty(err)
|
||||||
let s:clean_count += 1
|
call setline(l1, '~'.line[1:])
|
||||||
call setline(4, printf('Removed %d directories.', s:clean_count))
|
let s:clean_count += 1
|
||||||
|
else
|
||||||
|
delete _
|
||||||
|
call append(l1 - 1, s:format_message('x', line[1:], err))
|
||||||
|
let l2 += len(s:lines(err))
|
||||||
|
let err_count += 1
|
||||||
|
endif
|
||||||
|
let msg = printf('Removed %d directories.', s:clean_count)
|
||||||
|
if err_count > 0
|
||||||
|
let msg .= printf(' Failed to remove %d directories.', err_count)
|
||||||
|
endif
|
||||||
|
call setline(4, msg)
|
||||||
setlocal nomodifiable
|
setlocal nomodifiable
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
5
test/run
5
test/run
@ -91,6 +91,11 @@ DOC
|
|||||||
echo "echomsg 'ftplugin-c'" > "$PLUG_FIXTURES/ftplugin-msg/ftplugin/c.vim"
|
echo "echomsg 'ftplugin-c'" > "$PLUG_FIXTURES/ftplugin-msg/ftplugin/c.vim"
|
||||||
echo "echomsg 'ftplugin-java'" > "$PLUG_FIXTURES/ftplugin-msg/ftplugin/java.vim"
|
echo "echomsg 'ftplugin-java'" > "$PLUG_FIXTURES/ftplugin-msg/ftplugin/java.vim"
|
||||||
|
|
||||||
|
chmod +w "$PLUG_FIXTURES/cant-delete/autoload" || rm -rf "$PLUG_FIXTURES/cant-delete"
|
||||||
|
mkdir -p "$PLUG_FIXTURES/cant-delete/autoload"
|
||||||
|
touch "$PLUG_FIXTURES/cant-delete/autoload/cant-delete.vim"
|
||||||
|
chmod -w "$PLUG_FIXTURES/cant-delete/autoload"
|
||||||
|
|
||||||
rm -rf $TEMP/new-branch
|
rm -rf $TEMP/new-branch
|
||||||
cd $TEMP
|
cd $TEMP
|
||||||
git init new-branch
|
git init new-branch
|
||||||
|
@ -1468,6 +1468,7 @@ Execute (PlugClean should not try to remove unmanaged plugins inside g:plug_home
|
|||||||
Plug '$PLUG_FIXTURES/fzf'
|
Plug '$PLUG_FIXTURES/fzf'
|
||||||
Plug '$PLUG_FIXTURES/xxx'
|
Plug '$PLUG_FIXTURES/xxx'
|
||||||
Plug '$PLUG_FIXTURES/yyy'
|
Plug '$PLUG_FIXTURES/yyy'
|
||||||
|
Plug '$PLUG_FIXTURES/cant-delete'
|
||||||
call plug#end()
|
call plug#end()
|
||||||
|
|
||||||
" Remove z1, z2
|
" Remove z1, z2
|
||||||
@ -1721,3 +1722,25 @@ Execute (#766 - Allow cloning into an empty directory):
|
|||||||
AssertExpect! '[=]', 1
|
AssertExpect! '[=]', 1
|
||||||
q
|
q
|
||||||
unlet d
|
unlet d
|
||||||
|
|
||||||
|
Execute (#982 - PlugClean should report when directories cannot be removed):
|
||||||
|
call plug#begin('$PLUG_FIXTURES')
|
||||||
|
Plug '$PLUG_FIXTURES/ftplugin-msg', { 'for': [] }
|
||||||
|
Plug '$PLUG_FIXTURES/fzf'
|
||||||
|
Plug '$PLUG_FIXTURES/xxx'
|
||||||
|
Plug '$PLUG_FIXTURES/yyy'
|
||||||
|
call plug#end()
|
||||||
|
|
||||||
|
" Fail to remove cant-delete
|
||||||
|
PlugClean!
|
||||||
|
AssertEqual 'Removed 0 directories. Failed to remove 1 directories.', getline(4)
|
||||||
|
AssertExpect '^x ', 1
|
||||||
|
q
|
||||||
|
|
||||||
|
" Delete tmp but fail to remove cant-delete
|
||||||
|
call mkdir(expand('$PLUG_FIXTURES/tmp'))
|
||||||
|
PlugClean!
|
||||||
|
AssertEqual 'Removed 1 directories. Failed to remove 1 directories.', getline(4)
|
||||||
|
AssertExpect '^x ', 1
|
||||||
|
AssertExpect '^\~ ', 1
|
||||||
|
q
|
||||||
|
Loading…
Reference in New Issue
Block a user