mirror of
https://github.com/junegunn/vim-plug.git
synced 2024-12-23 20:45:31 -07:00
parent
0f3bd51d44
commit
c6ed41f47e
36
plug.vim
36
plug.vim
@ -1145,7 +1145,7 @@ while 1 " Without TCO, Vim stack is bound to explode
|
|||||||
|
|
||||||
let has_tag = has_key(spec, 'tag')
|
let has_tag = has_key(spec, 'tag')
|
||||||
if !new
|
if !new
|
||||||
let error = s:git_validate(spec, 0)
|
let [error, _] = s:git_validate(spec, 0)
|
||||||
if empty(error)
|
if empty(error)
|
||||||
if pull
|
if pull
|
||||||
let fetch_opt = (has_tag && !empty(globpath(spec.dir, '.git/shallow'))) ? '--depth 99999999' : ''
|
let fetch_opt = (has_tag && !empty(globpath(spec.dir, '.git/shallow'))) ? '--depth 99999999' : ''
|
||||||
@ -1860,11 +1860,18 @@ function! s:git_validate(spec, check_branch)
|
|||||||
let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.',
|
let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.',
|
||||||
\ branch, a:spec.branch)
|
\ branch, a:spec.branch)
|
||||||
endif
|
endif
|
||||||
|
if empty(err)
|
||||||
|
let commits = len(s:lines(s:system(printf('git rev-list origin/%s..HEAD', a:spec.branch), a:spec.dir)))
|
||||||
|
if !v:shell_error && commits
|
||||||
|
let err = join([printf('Diverged from origin/%s by %d commit(s).', a:spec.branch, commits),
|
||||||
|
\ 'Reinstall after PlugClean.'], "\n")
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
let err = 'Not found'
|
let err = 'Not found'
|
||||||
endif
|
endif
|
||||||
return err
|
return [err, err =~# 'PlugClean']
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:rm_rf(dir)
|
function! s:rm_rf(dir)
|
||||||
@ -1875,15 +1882,23 @@ endfunction
|
|||||||
|
|
||||||
function! s:clean(force)
|
function! s:clean(force)
|
||||||
call s:prepare()
|
call s:prepare()
|
||||||
call append(0, 'Searching for unused plugins in '.g:plug_home)
|
call append(0, 'Searching for invalid plugins in '.g:plug_home)
|
||||||
call append(1, '')
|
call append(1, '')
|
||||||
|
|
||||||
" List of valid directories
|
" List of valid directories
|
||||||
let dirs = []
|
let dirs = []
|
||||||
|
let errs = {}
|
||||||
let [cnt, total] = [0, len(g:plugs)]
|
let [cnt, total] = [0, len(g:plugs)]
|
||||||
for [name, spec] in items(g:plugs)
|
for [name, spec] in items(g:plugs)
|
||||||
if !s:is_managed(name) || empty(s:git_validate(spec, 0))
|
if !s:is_managed(name)
|
||||||
call add(dirs, spec.dir)
|
call add(dirs, spec.dir)
|
||||||
|
else
|
||||||
|
let [err, clean] = s:git_validate(spec, 1)
|
||||||
|
if clean
|
||||||
|
let errs[spec.dir] = s:lines(err)[0]
|
||||||
|
else
|
||||||
|
call add(dirs, spec.dir)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
let cnt += 1
|
let cnt += 1
|
||||||
call s:progress_bar(2, repeat('=', cnt), total)
|
call s:progress_bar(2, repeat('=', cnt), total)
|
||||||
@ -1907,11 +1922,14 @@ function! s:clean(force)
|
|||||||
if !has_key(allowed, f) && isdirectory(f)
|
if !has_key(allowed, f) && isdirectory(f)
|
||||||
call add(todo, f)
|
call add(todo, f)
|
||||||
call append(line('$'), '- ' . f)
|
call append(line('$'), '- ' . f)
|
||||||
|
if has_key(errs, f)
|
||||||
|
call append(line('$'), ' ' . errs[f])
|
||||||
|
endif
|
||||||
let found = filter(found, 'stridx(v:val, f) != 0')
|
let found = filter(found, 'stridx(v:val, f) != 0')
|
||||||
end
|
end
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
normal! G
|
4
|
||||||
redraw
|
redraw
|
||||||
if empty(todo)
|
if empty(todo)
|
||||||
call append(line('$'), 'Already clean.')
|
call append(line('$'), 'Already clean.')
|
||||||
@ -1920,12 +1938,12 @@ function! s:clean(force)
|
|||||||
for dir in todo
|
for dir in todo
|
||||||
call s:rm_rf(dir)
|
call s:rm_rf(dir)
|
||||||
endfor
|
endfor
|
||||||
call append(line('$'), 'Removed.')
|
call append(3, ['Removed.', ''])
|
||||||
else
|
else
|
||||||
call append(line('$'), 'Cancelled.')
|
call append(3, ['Cancelled.', ''])
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
normal! G
|
4
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:upgrade()
|
function! s:upgrade()
|
||||||
@ -1972,7 +1990,7 @@ function! s:status()
|
|||||||
for [name, spec] in items(g:plugs)
|
for [name, spec] in items(g:plugs)
|
||||||
if has_key(spec, 'uri')
|
if has_key(spec, 'uri')
|
||||||
if isdirectory(spec.dir)
|
if isdirectory(spec.dir)
|
||||||
let err = s:git_validate(spec, 1)
|
let [err, _] = s:git_validate(spec, 1)
|
||||||
let [valid, msg] = [empty(err), empty(err) ? 'OK' : err]
|
let [valid, msg] = [empty(err), empty(err) ? 'OK' : err]
|
||||||
else
|
else
|
||||||
let [valid, msg] = [0, 'Not found. Try PlugInstall.']
|
let [valid, msg] = [0, 'Not found. Try PlugInstall.']
|
||||||
|
@ -212,6 +212,24 @@ Expect:
|
|||||||
[==]
|
[==]
|
||||||
x seoul256.vim:
|
x seoul256.vim:
|
||||||
|
|
||||||
|
Execute (Corrected the URI but diverged from master):
|
||||||
|
call plug#begin()
|
||||||
|
Plug 'junegunn/seoul256.vim'
|
||||||
|
Plug 'file:///tmp/jg/vim-emoji'
|
||||||
|
call plug#end()
|
||||||
|
for _ in range(3)
|
||||||
|
call system(printf('cd "%s" && git commit --allow-empty -m "dummy"', g:plugs['seoul256.vim'].dir))
|
||||||
|
endfor
|
||||||
|
call PlugStatusSorted()
|
||||||
|
|
||||||
|
Expect:
|
||||||
|
Diverged from origin/master by 3 commit(s).
|
||||||
|
Reinstall after PlugClean.
|
||||||
|
- vim-emoji: OK
|
||||||
|
Finished. 1 error(s).
|
||||||
|
[==]
|
||||||
|
x seoul256.vim:
|
||||||
|
|
||||||
# TODO: does not work due to inputsave()
|
# TODO: does not work due to inputsave()
|
||||||
# Do (PlugClean):
|
# Do (PlugClean):
|
||||||
# :PlugClean\<Enter>y\<Enter>
|
# :PlugClean\<Enter>y\<Enter>
|
||||||
@ -222,8 +240,9 @@ Expect:
|
|||||||
Execute (PlugClean! to remove seoul256.vim):
|
Execute (PlugClean! to remove seoul256.vim):
|
||||||
PlugClean!
|
PlugClean!
|
||||||
" Three removed, emoji left
|
" Three removed, emoji left
|
||||||
|
AssertEqual 'Removed.', getline(4)
|
||||||
AssertExpect '^- ', 3
|
AssertExpect '^- ', 3
|
||||||
AssertExpect 'Removed', 1
|
AssertExpect 'Diverged', 1
|
||||||
Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
|
Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
|
||||||
Assert !empty(globpath(&rtp, 'autoload/emoji.vim'))
|
Assert !empty(globpath(&rtp, 'autoload/emoji.vim'))
|
||||||
q
|
q
|
||||||
@ -250,7 +269,7 @@ Expect:
|
|||||||
Execute (PlugClean! to remove vim-emoji):
|
Execute (PlugClean! to remove vim-emoji):
|
||||||
PlugClean!
|
PlugClean!
|
||||||
AssertExpect '^- ', 1
|
AssertExpect '^- ', 1
|
||||||
AssertExpect 'Removed', 1
|
AssertEqual 'Removed.', getline(4)
|
||||||
Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
|
Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
|
||||||
Assert empty(globpath(&rtp, 'autoload/emoji.vim'))
|
Assert empty(globpath(&rtp, 'autoload/emoji.vim'))
|
||||||
q
|
q
|
||||||
|
Loading…
Reference in New Issue
Block a user