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.
This commit is contained in:
parent
6ad18f5fb8
commit
bfd8881374
22
plug.vim
22
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user