diff --git a/plug.vim b/plug.vim index 8f2680e..0909d28 100644 --- a/plug.vim +++ b/plug.vim @@ -438,7 +438,7 @@ function! s:parse_options(arg) elseif type == s:TYPE.dict call extend(opts, a:arg) if has_key(opts, 'tag') - let opts.branch = remove(opts, 'tag') + let opts.tag = remove(opts, 'tag') endif if has_key(opts, 'dir') let opts.dir = s:dirpath(expand(opts.dir)) @@ -950,13 +950,16 @@ while 1 " Without TCO, Vim stack is bound to explode call s:log(new ? '+' : '*', name, pull ? 'Updating ...' : 'Installing ...') redraw + let checkout = s:shellesc(has_key(spec, 'tag') ? spec.tag : spec.branch) + let merge = s:shellesc(has_key(spec, 'tag') ? spec.tag : 'origin/'.spec.branch) + if !new let [valid, msg] = s:git_valid(spec, 0) if valid if pull call s:spawn(name, - \ printf('(git fetch %s 2>&1 && git checkout -q %s 2>&1 && git merge --ff-only origin/%s 2>&1 && git submodule update --init --recursive 2>&1)', - \ prog, s:shellesc(spec.branch), s:shellesc(spec.branch)), { 'dir': spec.dir }) + \ printf('(git fetch %s 2>&1 && git checkout -q %s 2>&1 && git merge --ff-only %s 2>&1 && git submodule update --init --recursive 2>&1)', + \ prog, checkout, merge), { 'dir': spec.dir }) else let s:jobs[name] = { 'running': 0, 'result': 'Already installed', 'error': 0 } endif @@ -968,7 +971,7 @@ while 1 " Without TCO, Vim stack is bound to explode \ printf('git clone %s --recursive %s -b %s %s 2>&1', \ prog, \ s:shellesc(spec.uri), - \ s:shellesc(spec.branch), + \ checkout, \ s:shellesc(s:trim(spec.dir))), { 'new': 1 }) endif @@ -1145,8 +1148,9 @@ function! s:update_ruby() threads << Thread.new { while pair = take1.call name = pair.first - dir, uri, branch = pair.last.values_at *%w[dir uri branch] - branch = esc branch + dir, uri, branch, tag = pair.last.values_at *%w[dir uri branch tag] + checkout = esc(tag ? tag : branch) + merge = esc(tag ? tag : "origin/#{branch}") subm = "git submodule update --init --recursive 2>&1" exists = File.directory? dir ok, result = @@ -1167,7 +1171,7 @@ function! s:update_ruby() else if pull log.call name, 'Updating ...', :update - bt.call "#{cd} #{dir} && (git fetch #{progress} 2>&1 && git checkout -q #{branch} 2>&1 && git merge --ff-only origin/#{branch} 2>&1 && #{subm})", name, :update, nil + bt.call "#{cd} #{dir} && (git fetch #{progress} 2>&1 && git checkout -q #{checkout} 2>&1 && git merge --ff-only #{merge} 2>&1 && #{subm})", name, :update, nil else [true, skip] end @@ -1175,7 +1179,7 @@ function! s:update_ruby() else d = esc dir.sub(%r{[\\/]+$}, '') log.call name, 'Installing ...', :install - bt.call "git clone #{progress} --recursive #{uri} -b #{branch} #{d} 2>&1", name, :install, proc { + bt.call "git clone #{progress} --recursive #{uri} -b #{checkout} #{d} 2>&1", name, :install, proc { FileUtils.rm_rf dir } end @@ -1257,13 +1261,19 @@ function! s:git_valid(spec, check_branch) let ret = 0 elseif a:check_branch let branch = result[0] - if a:spec.branch !=# branch + " Check tag + 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.branch !=# tag - let msg = printf('Invalid branch/tag: %s (expected: %s). Try PlugUpdate.', - \ (empty(tag) ? branch : tag), a:spec.branch) + if a:spec.tag !=# tag + let msg = printf('Invalid tag: %s (expected: %s). Try PlugUpdate.', + \ (empty(tag) ? 'N/A' : tag), a:spec.tag) let ret = 0 endif + " Check branch + elseif a:spec.branch !=# branch + let msg = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.', + \ branch, a:spec.branch) + let ret = 0 endif endif else diff --git a/test/workflow.vader b/test/workflow.vader index cd2b09e..21ec7e7 100644 --- a/test/workflow.vader +++ b/test/workflow.vader @@ -32,7 +32,7 @@ Execute (Subsequent plug#begin() calls will reuse g:plug_home): AssertEqual temp_plugged, g:plug_home Execute (Test Plug command): - " Git repo with branch +^ Git repo with branch (DEPRECATED. USE BRANCH OPTION) Plug 'junegunn/seoul256.vim', 'yes-t_co' AssertEqual 'file:///tmp/junegunn/seoul256.vim', g:plugs['seoul256.vim'].uri AssertEqual join([temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir @@ -41,14 +41,14 @@ Execute (Test Plug command): Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co' } " Using branch option AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch - " Git repo with tag +^ Git repo with tag (DEPRECATED. USE TAG OPTION) Plug 'junegunn/goyo.vim', '1.5.2' AssertEqual 'file:///tmp/junegunn/goyo.vim', g:plugs['goyo.vim'].uri AssertEqual join([temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir AssertEqual '1.5.2', g:plugs['goyo.vim'].branch Plug 'junegunn/goyo.vim', { 'tag': '1.5.3' } " Using tag option - AssertEqual '1.5.3', g:plugs['goyo.vim'].branch + AssertEqual '1.5.3', g:plugs['goyo.vim'].tag " Git URI Plug 'file:///tmp/jg/vim-emoji' @@ -109,7 +109,27 @@ Execute (PlugStatus after installation): AssertExpect 'OK', 4 q +Execute (PlugUpdate - tagged plugin should not fail (#174)): + PlugUpdate goyo.vim + Log getline(1, '$') + AssertExpect '^- goyo.vim', 1 + q + Execute (Change tag of goyo.vim): + call plug#begin() + Plug 'junegunn/goyo.vim', { 'tag': '9.9.9' } + call plug#end() + +Execute (PlugStatus): + call PlugStatusSorted() + +Expect: + Invalid tag: 1.5.3 (expected: 9.9.9). Try PlugUpdate. + Finished. 1 error(s). + [=] + x goyo.vim: + +Execute (Remove tag of goyo.vim): call plug#begin() Plug 'junegunn/goyo.vim' call plug#end() @@ -118,7 +138,7 @@ Execute (PlugStatus): call PlugStatusSorted() Expect: - Invalid branch/tag: 1.5.3 (expected: master). Try PlugUpdate. + Invalid branch: HEAD (expected: master). Try PlugUpdate. Finished. 1 error(s). [=] x goyo.vim: @@ -142,12 +162,34 @@ Execute (PlugStatus): call PlugStatusSorted() Expect: - Invalid branch/tag: no-t_co (expected: master). Try PlugUpdate. + Invalid branch: no-t_co (expected: master). Try PlugUpdate. - vim-emoji: OK Finished. 1 error(s). [==] x seoul256.vim: +Execute (PlugUpdate to switch branch, then PlugStatus): + PlugUpdate + call PlugStatusSorted() + +Expect: + - seoul256.vim: OK + - vim-emoji: OK + Finished. 0 error(s). + [==] + +Execute (Change tag of seoul256.vim): + call plug#begin() + Plug 'junegunn/seoul256.vim', { 'tag': 'no-such-tag' } + call plug#end() + call PlugStatusSorted() + +Expect: + Invalid tag: N/A (expected: no-such-tag). Try PlugUpdate. + Finished. 1 error(s). + [=] + x seoul256.vim: + Execute (Change URI of seoul256.vim): call plug#begin() Plug 'junegunn.choi/seoul256.vim'