feat(utils): better update function
This commit is contained in:
parent
8ec2a7193a
commit
9353418791
1 changed files with 12 additions and 8 deletions
|
@ -76,27 +76,31 @@ end
|
||||||
function M.update()
|
function M.update()
|
||||||
local Job = require('plenary.job')
|
local Job = require('plenary.job')
|
||||||
local path = M.get_install_dir()
|
local path = M.get_install_dir()
|
||||||
local err = false
|
local errors = {}
|
||||||
|
|
||||||
Job
|
Job
|
||||||
:new({
|
:new({
|
||||||
command = 'git',
|
command = 'git',
|
||||||
args = { 'pull' },
|
args = { 'pull', '--ff-only' },
|
||||||
cwd = path,
|
cwd = path,
|
||||||
on_exit = function()
|
on_exit = function()
|
||||||
if not err then
|
if vim.tbl_isempty(errors) then
|
||||||
vim.notify(
|
vim.notify(
|
||||||
'Please restart CosmicNvim and run `:PackerSync`',
|
'Please restart CosmicNvim and run `:PackerSync`',
|
||||||
vim.log.levels.INFO,
|
vim.log.levels.INFO,
|
||||||
{ title = 'CosmicNvim Updated!', timeout = 30000 }
|
{ title = 'CosmicNvim Updated!', timeout = 30000 }
|
||||||
)
|
)
|
||||||
|
else
|
||||||
|
table.insert(errors, 1, 'Something went wrong! Please pull changes manually.')
|
||||||
|
table.insert(errors, 2, '')
|
||||||
|
vim.notify(errors, vim.log.levels.ERROR, {
|
||||||
|
title = 'CosmicNvim Update Failed!',
|
||||||
|
timeout = 30000,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on_stderr = function(_, return_val)
|
on_stderr = function(_, err)
|
||||||
err = return_val
|
table.insert(errors, err)
|
||||||
vim.notify(err, vim.log.levels.ERROR, {
|
|
||||||
title = 'CosmicNvim Update Failed!',
|
|
||||||
})
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
:sync() -- or start()
|
:sync() -- or start()
|
||||||
|
|
Loading…
Add table
Reference in a new issue