feat: add warning message when using PackerSync on snapshot branches
This commit is contained in:
		
							parent
							
								
									46590c3772
								
							
						
					
					
						commit
						7bb3afbb96
					
				
					 2 changed files with 44 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -4,9 +4,17 @@ vim.cmd "silent! command! NvChadSnapshotCreate lua require('nvchad').snap_create
 | 
			
		|||
vim.cmd "silent! command! NvChadSnapshotDelete lua require('nvchad').snap_delete()"
 | 
			
		||||
vim.cmd "silent! command! NvChadSnapshotCheckout lua require('nvchad').snap_checkout()"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
-- autocmds
 | 
			
		||||
local autocmd = vim.api.nvim_create_autocmd
 | 
			
		||||
 | 
			
		||||
-- wrap the PackerSync command to warn people before using it in NvChadSnapshots
 | 
			
		||||
autocmd("VimEnter", {
 | 
			
		||||
   callback = function()
 | 
			
		||||
      vim.cmd "command! -nargs=* -complete=customlist,v:lua.require'packer'.plugin_complete PackerSync lua require('core.utils').packer_sync(<f-args>)"
 | 
			
		||||
   end,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
-- Disable statusline in dashboard
 | 
			
		||||
autocmd("FileType", {
 | 
			
		||||
   pattern = "alpha",
 | 
			
		||||
| 
						 | 
				
			
			@ -30,9 +38,8 @@ autocmd("BufEnter", {
 | 
			
		|||
 | 
			
		||||
autocmd("InsertLeave", {
 | 
			
		||||
   callback = function()
 | 
			
		||||
      if
 | 
			
		||||
         require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()]
 | 
			
		||||
         and not require("luasnip").session.jump_active
 | 
			
		||||
      if require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()]
 | 
			
		||||
          and not require("luasnip").session.jump_active
 | 
			
		||||
      then
 | 
			
		||||
         require("luasnip").unlink_current()
 | 
			
		||||
      end
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -160,4 +160,38 @@ M.load_override = function(default_table, plugin_name)
 | 
			
		|||
   return default_table
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
M.packer_sync = function(...)
 | 
			
		||||
   local git_exists, git = pcall(require, "nvchad.utils.git")
 | 
			
		||||
   local defaults_exists, defaults = pcall(require, "nvchad.utils.config")
 | 
			
		||||
   local packer_exists, packer = pcall(require, "packer")
 | 
			
		||||
 | 
			
		||||
   if git_exists and defaults_exists then
 | 
			
		||||
      local current_branch_name = git.get_current_branch_name()
 | 
			
		||||
 | 
			
		||||
      -- warn the user if we are on a snapshot branch
 | 
			
		||||
      if current_branch_name:match(defaults.snaps.base_snap_branch_name .. "(.+)" .. "$") then
 | 
			
		||||
         vim.api.nvim_echo({
 | 
			
		||||
            { "WARNING: You are trying to use ", "WarningMsg" },
 | 
			
		||||
            { "PackerSync" },
 | 
			
		||||
            { " on a NvChadSnapshot. This will cause issues if NvChad dependencies contain "
 | 
			
		||||
                .. "any breaking changes! Plugin updates will not be included in this "
 | 
			
		||||
                .. "snapshot, so they will be lost after switching between snapshots! Would "
 | 
			
		||||
                .. "you still like to continue? [y/N]\n", "WarningMsg" }
 | 
			
		||||
         }, false, {})
 | 
			
		||||
 | 
			
		||||
         local ans = vim.trim(string.lower(vim.fn.input("-> ")))
 | 
			
		||||
 | 
			
		||||
         if ans ~= "y" then
 | 
			
		||||
            return
 | 
			
		||||
         end
 | 
			
		||||
      end
 | 
			
		||||
   end
 | 
			
		||||
 | 
			
		||||
   if packer_exists then
 | 
			
		||||
      packer.sync(...)
 | 
			
		||||
   else
 | 
			
		||||
      error("Packer could not be loaded!")
 | 
			
		||||
   end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
return M
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue