let s:is_win = has('win32')
let s:nvim = has('nvim-0.2') || (has('nvim') && exists('*jobwait') && !s:is_win)
let s:vim8 = has('patch-8.0.0039') && exists('*job_start')
+let s:shell_error = 0
if s:is_win && &shellslash
set noshellslash
let s:me = resolve(expand('<sfile>:p'))
" The command may not return the name of a branch in detached HEAD state
let result = s:lines(s:system('git symbolic-ref --short HEAD', a:spec.dir))
- return v:shell_error ? '' : result[-1]
+ return s:shell_error ? '' : result[-1]
endfunction
if s:is_win
for [cmd, names] in items(lod.cmd)
execute printf(
- \ 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)',
- \ cmd, string(cmd), string(names))
+ \ has('patch-7.4.1898')
+ \ ? 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, <q-mods> ,%s)'
+ \ : 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)'
+ \ , cmd, string(cmd), string(names))
endfor
for [map, names] in items(lod.map)
let s:middle = get(s:, 'middle', &rtp)
let rtps = map(s:loaded_names(), 's:rtp(g:plugs[v:val])')
- let afters = filter(map(copy(rtps), 'globpath(v:val, "after")'), '!empty(v:val)')
+ let afters = map(filter(copy(rtps), 'isdirectory(v:val."/after")'), 's:path(v:val."/after")')
let rtp = join(map(rtps, 'escape(v:val, ",")'), ',')
\ . ','.s:middle.','
\ . join(map(afters, 'escape(v:val, ",")'), ',')
endfunction
function! s:dobufread(names)
+ " Nothing to detect in an unnamed empty buffer, e.g. the one on startup
+ if empty(bufname('%')) && line('$') == 1 && empty(getline(1))
+ return
+ endif
for name in a:names
let path = s:rtp(g:plugs[name])
for dir in ['ftdetect', 'ftplugin', 'after/ftdetect', 'after/ftplugin']
- if len(finddir(dir, path))
+ if isdirectory(path.'/'.dir)
if exists('#BufRead')
doautocmd BufRead
endif
call s:doautocmd('filetypeindent', 'FileType')
endfunction
-function! s:lod_cmd(cmd, bang, l1, l2, args, names)
- call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
- call s:dobufread(a:names)
- execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
-endfunction
+if has('patch-7.4.1898')
+ function! s:lod_cmd(cmd, bang, l1, l2, args, mods, names)
+ call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
+ call s:dobufread(a:names)
+ execute printf('%s %s%s%s %s', a:mods, (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
+ endfunction
+else
+ function! s:lod_cmd(cmd, bang, l1, l2, args, names)
+ call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
+ call s:dobufread(a:names)
+ execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
+ endfunction
+endif
function! s:lod_map(map, names, with_prefix, prefix)
call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
let [sh, shellcmdflag, shrd] = s:chsh(a:0)
" FIXME: Escaping is incomplete. We could use shellescape with eval,
" but it won't work on Windows.
- let cmd = a:0 ? s:with_cd(a:cmd, a:1) : a:cmd
+ let cmd = a:0 ? s:with_cd(a:cmd, a:1, {'shell': s:is_win ? 'cmd.exe' : &shell}) : a:cmd
if s:is_win
let [batchfile, cmd] = s:batchfile(cmd)
endif
return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0
endfunction
+function! s:disable_credential_helper()
+ return s:git_version_requirement(2) && get(g:, 'plug_disable_credential_helper', 1)
+endfunction
+
function! s:checkout(spec)
let sha = a:spec.commit
let output = s:git_revision(a:spec.dir)
let error = 0
if !empty(output) && !s:hash_match(sha, s:lines(output)[0])
- let credential_helper = s:git_version_requirement(2) ? '-c credential.helper= ' : ''
+ let credential_helper = s:disable_credential_helper() ? '-c credential.helper= ' : ''
let output = s:system(
\ 'git '.credential_helper.'fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir)
- let error = v:shell_error
+ let error = s:shell_error
endif
return [output, error]
endfunction
endif
let use_job = s:nvim || s:vim8
- let python = (has('python') || has('python3')) && !use_job
- let ruby = has('ruby') && !use_job && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) && threads > 1 && s:check_ruby()
+ let python = !use_job && (has('python3') || has('python'))
+ let ruby = !use_job && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running')) && threads > 1 && has('ruby') && s:check_ruby()
let s:update = {
\ 'start': reltime(),
let s:submodule_opt = s:git_version_requirement(2, 8) ? ' --jobs='.threads : ''
" Python version requirement (>= 2.7)
- if python && !has('python3') && !ruby && !use_job && s:update.threads > 1
+ if python && !ruby && s:update.threads > 1 && !has('python3')
redir => pyv
silent python import platform; print platform.python_version()
redir END
let tag = spec.tag
if tag =~ '\*'
let tags = s:lines(s:system('git tag --list '.plug#shellescape(tag).' --sort -version:refname 2>&1', spec.dir))
- if !v:shell_error && !empty(tags)
+ if !s:shell_error && !empty(tags)
let tag = tags[0]
call s:log4(name, printf('Latest tag for %s -> %s', spec.tag, tag))
call append(3, '')
endif
call s:log4(name, 'Checking out '.tag)
let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir)
- let error = v:shell_error
+ let error = s:shell_error
endif
if !error && filereadable(spec.dir.'/.gitmodules') &&
\ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir))
let out .= s:bang('git submodule update --init --recursive'.s:submodule_opt.' 2>&1', spec.dir)
let error = v:shell_error
endif
- let msg = s:format_message(v:shell_error ? 'x': '-', name, out)
+ let msg = s:format_message(error ? 'x': '-', name, out)
if error
call add(s:update.errors, name)
call s:regress_bar()
elseif s:vim8
let cmd = join(map(copy(argv), 'plug#shellescape(v:val, {"script": 0})'))
if has_key(a:opts, 'dir')
- let cmd = s:with_cd(cmd, a:opts.dir, 0)
+ let cmd = s:with_cd(cmd, a:opts.dir, {'shell': s:is_win ? 'cmd.exe' : 'sh', 'script': 0})
endif
let argv = s:is_win ? ['cmd', '/s', '/c', '"'.cmd.'"'] : ['sh', '-c', cmd]
let jid = job_start(s:is_win ? join(argv, ' ') : argv, {
endif
else
let job.lines = s:lines(call('s:system', has_key(a:opts, 'dir') ? [argv, a:opts.dir] : [argv]))
- let job.error = v:shell_error != 0
+ let job.error = s:shell_error != 0
let job.running = 0
endif
endfunction
let [error, _] = s:git_validate(spec, 0)
if empty(error)
if pull
- let cmd = s:git_version_requirement(2) ? ['git', '-c', 'credential.helper=', 'fetch'] : ['git', 'fetch']
+ let cmd = s:disable_credential_helper() ? ['git', '-c', 'credential.helper=', 'fetch'] : ['git', 'fetch']
if has_tag && !empty(globpath(spec.dir, '.git/shallow'))
call extend(cmd, ['--depth', '99999999'])
endif
endfunction
function! s:update_python()
-let py_exe = has('python') ? 'python' : 'python3'
+let py_exe = has('python3') ? 'python3' : 'python'
execute py_exe "<< EOF"
import datetime
import functools
endfunction
function! s:with_cd(cmd, dir, ...)
- let script = a:0 > 0 ? a:1 : 1
- let pwsh = s:is_powershell(&shell)
+ let opts = a:0 > 0 && type(a:1) == s:TYPE.dict ? a:1 : {}
+ let opts.shell = get(opts, 'shell', &shell)
+ let opts.script = get(opts, 'script', 1)
+
+ let pwsh = s:is_powershell(opts.shell)
let cd = s:is_win && !pwsh ? 'cd /d' : 'cd'
let sep = pwsh ? ';' : '&&'
- return printf('%s %s %s %s', cd, plug#shellescape(a:dir, {'script': script, 'shell': &shell}), sep, a:cmd)
+ let pwsh_block_required = pwsh && !has('patch-9.2.6')
+ let start = pwsh_block_required ? '& { ' : ''
+ let end = pwsh_block_required ? ' }' : ''
+
+ return printf('%s%s %s %s %s%s', start, cd, plug#shellescape(a:dir, opts), sep, a:cmd, end)
+endfunction
+
+function! s:system_job(cmd) abort
+ let tmp = tempname()
+ let job = job_start(['/bin/sh', '-c', a:cmd], {
+ \ 'out_io': 'file',
+ \ 'out_name': tmp,
+ \ 'err_io': 'out',
+ \})
+ while job_status(job) ==# 'run'
+ sleep 1m
+ endwhile
+ let s:shell_error = job_info(job).exitval
+ let result = filereadable(tmp) ? join(readfile(tmp, 'b'), "\n") : ''
+ silent! call delete(tmp)
+ return result
endfunction
function! s:system(cmd, ...)
" but it cannot set the working directory for the command.
" Assume that the command does not rely on the shell.
if has('nvim') && a:0 == 0
- return system(a:cmd)
+ let ret = system(a:cmd)
+ let s:shell_error = v:shell_error
+ return ret
endif
let cmd = join(map(copy(a:cmd), 'plug#shellescape(v:val, {"shell": &shell, "script": 0})'))
if s:is_powershell(&shell)
let cmd = a:cmd
endif
if a:0 > 0
- let cmd = s:with_cd(cmd, a:1, type(a:cmd) != s:TYPE.list)
+ let cmd = s:with_cd(cmd, a:1, {'script': type(a:cmd) != s:TYPE.list})
endif
- if s:is_win && type(a:cmd) != s:TYPE.list
+ if s:is_win && type(a:cmd) != s:TYPE.list && !s:is_powershell(&shell)
let [batchfile, cmd] = s:batchfile(cmd)
endif
- return system(cmd)
+ if s:vim8 && has('gui_running') && !s:is_win
+ return s:system_job(cmd)
+ endif
+ let ret = system(cmd)
+ let s:shell_error = v:shell_error
+ return ret
finally
let [&shell, &shellcmdflag, &shellredir] = [sh, shellcmdflag, shrd]
if s:is_win && filereadable(batchfile)
function! s:system_chomp(...)
let ret = call('s:system', a:000)
- return v:shell_error ? '' : substitute(ret, '\n$', '', '')
+ return s:shell_error ? '' : substitute(ret, '\n$', '', '')
endfunction
function! s:git_validate(spec, check_branch)
let err = join(['Invalid URI: '.remote,
\ 'Expected: '.a:spec.uri,
\ 'PlugClean required.'], "\n")
- elseif a:check_branch && has_key(a:spec, 'commit')
+ elseif !a:check_branch
+ return ['', 0]
+ elseif has_key(a:spec, 'commit')
let sha = s:git_revision(a:spec.dir)
if empty(sha)
let err = join(add(result, 'PlugClean required.'), "\n")
\ a:spec.commit[:6], sha[:6]),
\ 'PlugUpdate required.'], "\n")
endif
+ elseif has_key(a:spec, 'tag')
+ let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir)
+ if a:spec.tag !=# tag && a:spec.tag !~ '\*'
+ let err = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.',
+ \ (empty(tag) ? 'N/A' : tag), a:spec.tag)
+ endif
elseif a:check_branch
let current_branch = result[0]
- " Check tag
let origin_branch = s:git_origin_branch(a:spec)
- if has_key(a:spec, 'tag')
- let tag = s:system_chomp('git describe --exact-match --tags HEAD 2>&1', a:spec.dir)
- if a:spec.tag !=# tag && a:spec.tag !~ '\*'
- let err = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.',
- \ (empty(tag) ? 'N/A' : tag), a:spec.tag)
- endif
- " Check branch
- elseif origin_branch !=# current_branch
+ if origin_branch !=# current_branch
let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.',
\ current_branch, origin_branch)
endif
\ 'git', 'rev-list', '--count', '--left-right',
\ printf('HEAD...origin/%s', origin_branch)
\ ], a:spec.dir)), '\t')
- if v:shell_error || len(ahead_behind) != 2
+ if s:shell_error || len(ahead_behind) != 2
let err = "Failed to compare with the origin. The default branch might have changed.\nPlugClean required."
else
let [ahead, behind] = ahead_behind
function! s:rm_rf(dir)
if isdirectory(a:dir)
- return s:system(s:is_win
- \ ? 'rmdir /S /Q '.plug#shellescape(a:dir)
- \ : ['rm', '-rf', a:dir])
+ return s:system(!s:is_win
+ \ ? ['rm', '-rf', a:dir]
+ \ : s:is_powershell(&shell)
+ \ ? ['Remove-Item', '-Recurse', '-Force', a:dir]
+ \ : 'rmdir /S /Q '.plug#shellescape(a:dir))
endif
endfunction
try
let out = s:system(['git', 'clone', '--depth', '1', s:plug_src, tmp])
- if v:shell_error
+ if s:shell_error
return s:err('Error upgrading vim-plug: '. out)
endif