From 8863a3a53c4c774d49e42abc366a61dd960d7ca6 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Mon, 23 Jun 2014 04:02:49 +0900 Subject: [PATCH] Fix #28: False alarm from PlugStatus when tag used --- plug.vim | 15 ++++++++++++--- test/workflow.vader | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plug.vim b/plug.vim index c877c7c..8b14265 100644 --- a/plug.vim +++ b/plug.vim @@ -691,6 +691,11 @@ function! s:system(cmd) return system(s:is_win ? '('.a:cmd.')' : a:cmd) endfunction +function! s:system_chomp(str) + let ret = s:system(a:str) + return v:shell_error ? '' : substitute(ret, '\n$', '', '') +endfunction + function! s:git_valid(spec, check_branch, cd) let ret = 1 let msg = 'OK' @@ -698,7 +703,7 @@ function! s:git_valid(spec, check_branch, cd) if a:cd | execute "cd " . s:esc(a:spec.dir) | endif let result = split(s:system("git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url"), '\n') let remote = result[-1] - if v:shell_error != 0 + if v:shell_error let msg = join([remote, "PlugClean required."], "\n") let ret = 0 elseif !s:compare_git_uri(remote, a:spec.uri) @@ -708,8 +713,12 @@ function! s:git_valid(spec, check_branch, cd) let ret = 0 elseif a:check_branch let branch = result[0] - if a:spec.branch != branch - let msg = 'Invalid branch: '.branch.'. Try PlugUpdate.' + let tag = a:spec.branch == 'master' ? '' : + \ s:system_chomp('git describe --exact-match --tags HEAD 2>&1') + if a:spec.branch != branch && a:spec.branch != tag + let msg = 'Invalid branch/tag: ' . + \ ((empty(tag) || tag ==# 'HEAD') ? branch : tag) . + \ '. Try PlugUpdate.' let ret = 0 endif endif diff --git a/test/workflow.vader b/test/workflow.vader index 937526f..05c8db5 100644 --- a/test/workflow.vader +++ b/test/workflow.vader @@ -134,7 +134,7 @@ Execute (PlugStatus): g/^$/d Expect: - Invalid branch: no-t_co. Try PlugUpdate. + Invalid branch/tag: no-t_co. Try PlugUpdate. - vim-emoji: OK Finished. 1 error(s). [==]