packer.nvim icon indicating copy to clipboard operation
packer.nvim copied to clipboard

Add Last Known Good Configuration or PackerSyncUndo

Open cseickel opened this issue 3 years ago • 5 comments

Describe the feature

I'd like the ability to revert updates from a PackerSync that breaks plugins.

On occasion, a plugin author will introduce a breaking change without warning and a PackerSync will break things. When that happens, I would like to be able to just quickly undo those changes and go about my day rather than finding and fixing it right then and there. The manual way of doing this is to play detective, find the offending plugin, and pin it to a prior commit or a fork that fixes the issue. Most of the time, I'd rather just be able to type :PackerSyncUndo and revert everything to the state it was at prior to the last PackerSync.

Solutions that pop into my mind are:

  1. Just record the commit hash of every plugin prior to the sync, and forcefully apply those in an "undo" operation
  2. Clone the entire directory where plugins are actually installed, and restore it on an "undo" operation

For the "Last Known Good" part, the commits or directory would not be saved if running the setup or run functions resulted in any errors.

If this sounds like a good idea to others, I would be willing to work on this and submit a PR. I'm not yet familiar with the code base so a few hints/suggestions would be appreciated.

cseickel avatar Jan 22 '22 15:01 cseickel

Thank you for suggesting this! Came here to see if packer has a dry-run mode for updating plugins. A bit surprised that it did not.

chunyunma avatar Jan 22 '22 18:01 chunyunma

PackerSnapshot feature from #370 implements this . Though the snapshot taking is directed by user .But nothing shoping you from auto taking snapshots before PackerSync/Update.

shadmansaleh avatar Jan 22 '22 19:01 shadmansaleh

That looks great. I would say that this request is blocked by #370. Once that is merged and has had some time in the wild to be fully tested, I think it would be a good idea to add an option to automatically take snapshots to enable the unanticipated undo. I would say keep the last 2 or three rolling snapshots.

In the meantime, once it is released I will probably override the built-in PackerSync in my own config with a custom function that runs PackerSnapshot <timestamp> and then PackerSync.

cseickel avatar Jan 22 '22 20:01 cseickel

@cseickel did you come up with that custom function you were referring to? Any way you could share it here?

macintacos avatar Aug 07 '22 00:08 macintacos

@macintacos No, I actually just forgot about this. At the time I had frequent problems with broken configs, but I haven't had many problems since the snapshot feature was added so I lost interest.

I have been on a mission to reduce plugins this year, and replace the ones that push breaking changes with more reliable ones where possible. That has worked well enough for me. I still think this is a good idea, but I no longer need it enough to actually do the work.

cseickel avatar Aug 07 '22 02:08 cseickel