diff --git a/plug.vim b/plug.vim index e8ca48b..198aaa0 100644 --- a/plug.vim +++ b/plug.vim @@ -2013,10 +2013,24 @@ function! s:git_validate(spec, check_branch) \ branch, a:spec.branch) endif if empty(err) - let commits = len(s:lines(s:system(printf('git rev-list origin/%s..HEAD', a:spec.branch), a:spec.dir))) - if !v:shell_error && commits - let err = join([printf('Diverged from origin/%s by %d commit(s).', a:spec.branch, commits), - \ 'Reinstall after PlugClean.'], "\n") + let [ahead, behind] = split(s:lastline(s:system(printf( + \ 'git rev-list --count --left-right HEAD...origin/%s', + \ a:spec.branch), a:spec.dir)), '\t') + if !v:shell_error && ahead + if behind + let base_error = printf( + \ 'Diverged from origin/%%s (%%d commit(s) ahead and %d commit(s) behind!', behind) + else + let base_error = 'Ahead of origin/%s by %d commit(s).' + endif + let err = join([printf(base_error, a:spec.branch, ahead), + \ 'Can you push it yourself?', + \ 'Otherwise try reinstalling it after cleaning it manually.'], "\n") + " Only mention PlugClean if diverged, otherwise it's likely to be + " pushable (and probably not that messed up). + if behind + let err .= "\nTry PlugClean after backing it up." + endif endif endif endif