From bfd888137494db1677c274278a51b95e8d9b447b Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 28 Oct 2016 00:19:14 +0200 Subject: [PATCH] git_validate: better error with checkout being ahead/diverged The `--count` and `--left-right` options seem to be in Git since before 1.7 already. The error message is improved, and distinguishes between only being ahead (which is the case if you could push), or being diverged (ahead and defined). I think it could be bad to accidentally clean/delete a local checkout which is ahead, and therefore PlugClean is not mentioned then, which appears to trigger it to show up in :PlugClean. --- plug.vim | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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