-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PlugUpdate fails when there is a forced update to plugin #462
Comments
@phanimahesh Hi, I have seen this once or twice before. Most responsible git devs shouldn't resort to forced updates as they cause such user problems. I'm not sure this happens frequently enough to warrant us putting code in to handle it specifically. Note, we already have ! enabled for PlugInstall/PlugUpdate, it means to force the re running of postinstall hooks. I'm not sure if we want to further add to the bang behaviour. @junegunn Thoughts? Have you had many forced updates? Interested in this being patched? |
@starcraftman Once. Literally once in all these years :) I'm concerned that it might lead to unwanted loss of local changes, little experiments, tweaks, ..., so I'm not leaning towards the idea. But it is true that there is no easy way to resolve the case, one would have to manually remove the plugin. Would it make sense to detect such cases in |
Or just reset the HEAD to before the conflict to make a clean pull. Regarding PlugClean, could work. Perhaps we should also take time to update PlugClean header message, and point out reason each repo being listed, i.e. unused, remote change or conflict. |
I've run into it (many times) for cases where I'm lazy and patch a plugin which is then rebased upstream. A low-risk, low-effort way to avoid data loss would be to simply save the current HEAD as a branch named something like |
Given that tags and branches are extremely lightweight in git (They are just a file named the same as branch and having the sha of commit they point to), I like this idea. Instead of polluting the global namespace (though not many directly use their plugin dirs for development), we can use |
@starcraftman Actually, a package/plugin/dependency manager doing a git pull is unusual IMO. A checkout of newly referenced ref is simpler and more common practice. |
I'm also concerned about uncommitted local changes. Those can't be recovered from reflogs. The idea of backup branches sounds nice but it feels a bit overkill for vim-plug. I tend to think twice before adding anything that requires extra explanation. Anyway, this is a preliminary patch that makes diff --git a/plug.vim b/plug.vim
index a55af87..94c395a 100644
--- a/plug.vim
+++ b/plug.vim
@@ -1860,6 +1860,13 @@ function! s:git_validate(spec, check_branch)
let err = printf('Invalid branch: %s (expected: %s). Try PlugUpdate.',
\ 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 commits
+ let err = join([printf('Diverged from origin/%s by %d commit(s).', a:spec.branch, commits),
+ \ 'PlugClean required.'], "\n")
+ endif
+ endif
endif
else
let err = 'Not found'
@@ -1875,14 +1882,14 @@ endfunction
function! s:clean(force)
call s:prepare()
- call append(0, 'Searching for unused plugins in '.g:plug_home)
+ call append(0, 'Searching for invalid plugins in '.g:plug_home)
call append(1, '')
" List of valid directories
let dirs = []
let [cnt, total] = [0, len(g:plugs)]
for [name, spec] in items(g:plugs)
- if !s:is_managed(name) || empty(s:git_validate(spec, 0))
+ if !s:is_managed(name) || empty(s:git_validate(spec, 1))
call add(dirs, spec.dir)
endif
let cnt += 1 |
@junegunn Looks good to me, follows our usual approach. People who frequently run into this could simply make an alias or binding for |
The backup refs are an overkill, yes. Usually package managers checkout the ref, store the commit hash in a lock file, and on update, they checkout new ref and update the lock. If there are uncommitted changes a common and sensible default is to abort with a message. But @junegunn's change looks good. It provides a solution to my original issue and is relatively simple. 👍 |
Alright, I'll craft a test case for it. Also the output of |
As an alternaive, may be there can be some option or additional parameter for PlugUpdate to do rebasing. I.e. instead of doing simple |
Title says it all. I discovered that when one of my plugins had a force update, nothing short of messing directly with the plugin directory allows me to update the plugin.
Allow PlugUpdate! to do a non-fast-forward update by simply checking out the new HEAD.
I tested only on neovim, but should be the same behaviour for all.
The text was updated successfully, but these errors were encountered: