3 Commits

Author SHA1 Message Date
Subhaditya Nath
3d06dfaa7d Merge 82ffd4f9ca into d80f495fab 2024-09-05 10:12:23 +02:00
Subhaditya Nath
82ffd4f9ca Added version guard
https://github.com/junegunn/vim-plug/pull/1110#issuecomment-980545280
2021-12-11 17:50:10 +05:30
Subhaditya Nath
2958782ef4 Allow modifiers for on-demand-loading commands
Before this commit, commands like this -
	:tab Git diff HEAD^ HEAD
were interpreted like this -
	:Git diff HEAD^ HEAD
This commit fixes that issue.
2021-07-18 09:59:05 +05:30
2 changed files with 41 additions and 51 deletions

View File

@@ -1,3 +1,21 @@
<div align="center">
<sup>Special thanks to:</sup>
<br>
<br>
<a href="https://warp.dev/?utm_source=github&utm_medium=referral&utm_campaign=vimplug_20240209">
<div>
<img src="https://raw.githubusercontent.com/junegunn/i/master/warp.png" width="300" alt="Warp">
</div>
<b>Warp is a modern, Rust-based terminal with AI built in so you and your team can build great software, faster.</b>
<div>
<sup>Visit warp.dev to learn more.</sup>
</div>
</a>
<br>
<hr>
</div>
<br>
<h1 title="vim-plug">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="./plug-dark.png">

View File

@@ -68,7 +68,6 @@ let s:mac_gui = has('gui_macvim') && has('gui_running')
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'))
@@ -171,7 +170,7 @@ function! s:git_origin_branch(spec)
" 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 s:shell_error ? '' : result[-1]
return v:shell_error ? '' : result[-1]
endfunction
if s:is_win
@@ -1086,19 +1085,15 @@ function! s:hash_match(a, b)
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:disable_credential_helper() ? '-c credential.helper= ' : ''
let credential_helper = s:git_version_requirement(2) ? '-c credential.helper= ' : ''
let output = s:system(
\ 'git '.credential_helper.'fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir)
let error = s:shell_error
let error = v:shell_error
endif
return [output, error]
endfunction
@@ -1304,7 +1299,7 @@ function! s:update_finish()
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 !s:shell_error && !empty(tags)
if !v:shell_error && !empty(tags)
let tag = tags[0]
call s:log4(name, printf('Latest tag for %s -> %s', spec.tag, tag))
call append(3, '')
@@ -1312,7 +1307,7 @@ function! s:update_finish()
endif
call s:log4(name, 'Checking out '.tag)
let out = s:system('git checkout -q '.plug#shellescape(tag).' -- 2>&1', spec.dir)
let error = s:shell_error
let error = v:shell_error
endif
if !error && filereadable(spec.dir.'/.gitmodules') &&
\ (s:update.force || has_key(s:update.new, name) || s:is_updated(spec.dir))
@@ -1320,7 +1315,7 @@ function! s:update_finish()
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(error ? 'x': '-', name, out)
let msg = s:format_message(v:shell_error ? 'x': '-', name, out)
if error
call add(s:update.errors, name)
call s:regress_bar()
@@ -1481,7 +1476,7 @@ function! s:spawn(name, spec, queue, opts)
endif
else
let job.lines = s:lines(call('s:system', has_key(a:opts, 'dir') ? [argv, a:opts.dir] : [argv]))
let job.error = s:shell_error != 0
let job.error = v:shell_error != 0
let job.running = 0
endif
endfunction
@@ -1604,7 +1599,7 @@ while 1 " Without TCO, Vim stack is bound to explode
let [error, _] = s:git_validate(spec, 0)
if empty(error)
if pull
let cmd = s:disable_credential_helper() ? ['git', '-c', 'credential.helper=', 'fetch'] : ['git', 'fetch']
let cmd = s:git_version_requirement(2) ? ['git', '-c', 'credential.helper=', 'fetch'] : ['git', 'fetch']
if has_tag && !empty(globpath(spec.dir, '.git/shallow'))
call extend(cmd, ['--depth', '99999999'])
endif
@@ -2335,22 +2330,6 @@ function! s:with_cd(cmd, dir, ...)
return printf('%s %s %s %s', cd, plug#shellescape(a:dir, {'script': script, 'shell': &shell}), sep, a:cmd)
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, ...)
let batchfile = ''
try
@@ -2360,9 +2339,7 @@ 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
let ret = system(a:cmd)
let s:shell_error = v:shell_error
return ret
return system(a:cmd)
endif
let cmd = join(map(copy(a:cmd), 'plug#shellescape(v:val, {"shell": &shell, "script": 0})'))
if s:is_powershell(&shell)
@@ -2377,12 +2354,7 @@ function! s:system(cmd, ...)
if s:is_win && type(a:cmd) != s:TYPE.list
let [batchfile, cmd] = s:batchfile(cmd)
endif
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
return system(cmd)
finally
let [&shell, &shellcmdflag, &shellredir] = [sh, shellcmdflag, shrd]
if s:is_win && filereadable(batchfile)
@@ -2393,7 +2365,7 @@ endfunction
function! s:system_chomp(...)
let ret = call('s:system', a:000)
return s:shell_error ? '' : substitute(ret, '\n$', '', '')
return v:shell_error ? '' : substitute(ret, '\n$', '', '')
endfunction
function! s:git_validate(spec, check_branch)
@@ -2407,9 +2379,7 @@ function! s:git_validate(spec, check_branch)
let err = join(['Invalid URI: '.remote,
\ 'Expected: '.a:spec.uri,
\ 'PlugClean required.'], "\n")
elseif !a:check_branch
return ['', 0]
elseif has_key(a:spec, 'commit')
elseif a:check_branch && has_key(a:spec, 'commit')
let sha = s:git_revision(a:spec.dir)
if empty(sha)
let err = join(add(result, 'PlugClean required.'), "\n")
@@ -2418,16 +2388,18 @@ function! s:git_validate(spec, check_branch)
\ 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 origin_branch !=# current_branch
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
let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.',
\ current_branch, origin_branch)
endif
@@ -2436,7 +2408,7 @@ function! s:git_validate(spec, check_branch)
\ 'git', 'rev-list', '--count', '--left-right',
\ printf('HEAD...origin/%s', origin_branch)
\ ], a:spec.dir)), '\t')
if s:shell_error || len(ahead_behind) != 2
if v: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
@@ -2586,7 +2558,7 @@ function! s:upgrade()
try
let out = s:system(['git', 'clone', '--depth', '1', s:plug_src, tmp])
if s:shell_error
if v:shell_error
return s:err('Error upgrading vim-plug: '. out)
endif