Просмотр исходного кода

Fix #28: False alarm from PlugStatus when tag used

Junegunn Choi 11 лет назад
Родитель
Сommit
8863a3a53c
2 измененных файлов с 13 добавлено и 4 удалено
  1. 12 3
      plug.vim
  2. 1 1
      test/workflow.vader

+ 12 - 3
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

+ 1 - 1
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).
   [==]