Avoid errors

This commit is contained in:
Yasuhiro Matsumoto 2020-02-20 13:45:57 +09:00
parent 33cb99a27c
commit fe0a986c84
No known key found for this signature in database
GPG Key ID: 622DE34DC490584B

View File

@ -2231,8 +2231,7 @@ function! s:git_validate(spec, check_branch)
\ 'Expected: '.a:spec.uri, \ 'Expected: '.a:spec.uri,
\ 'PlugClean required.'], "\n") \ 'PlugClean required.'], "\n")
elseif a:check_branch && has_key(a:spec, 'commit') elseif a:check_branch && has_key(a:spec, 'commit')
let result = [s:git_get_revision(a:spec.dir)] let sha = [s:git_get_revision(a:spec.dir)]
let sha = result[-1]
if !s:hash_match(sha, a:spec.commit) if !s:hash_match(sha, a:spec.commit)
let err = join([printf('Invalid HEAD (expected: %s, actual: %s)', let err = join([printf('Invalid HEAD (expected: %s, actual: %s)',
\ a:spec.commit[:6], sha[:6]), \ a:spec.commit[:6], sha[:6]),
@ -2253,20 +2252,23 @@ function! s:git_validate(spec, check_branch)
\ branch, a:spec.branch) \ branch, a:spec.branch)
endif endif
if empty(err) if empty(err)
let [ahead, behind] = split(s:lastline(s:system(printf( let result = split(s:lastline(s:system(printf(
\ 'git rev-list --count --left-right HEAD...origin/%s', \ 'git rev-list --count --left-right HEAD...origin/%s',
\ a:spec.branch), a:spec.dir)), '\t') \ a:spec.branch), a:spec.dir)), '\t')
if !v:shell_error && ahead if !v:shell_error && len(result) == 2
if behind let [ahead, behind] = result
" Only mention PlugClean if diverged, otherwise it's likely to be if ahead
" pushable (and probably not that messed up). if behind
let err = printf( " Only mention PlugClean if diverged, otherwise it's likely to be
\ "Diverged from origin/%s (%d commit(s) ahead and %d commit(s) behind!\n" " pushable (and probably not that messed up).
\ .'Backup local changes and run PlugClean and PlugUpdate to reinstall it.', a:spec.branch, ahead, behind) let err = printf(
else \ "Diverged from origin/%s (%d commit(s) ahead and %d commit(s) behind!\n"
let err = printf("Ahead of origin/%s by %d commit(s).\n" \ .'Backup local changes and run PlugClean and PlugUpdate to reinstall it.', a:spec.branch, ahead, behind)
\ .'Cannot update until local changes are pushed.', else
\ a:spec.branch, ahead) let err = printf("Ahead of origin/%s by %d commit(s).\n"
\ .'Cannot update until local changes are pushed.',
\ a:spec.branch, ahead)
endif
endif endif
endif endif
endif endif