mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 08:01:13 +01:00
Fix: Not updating now if the directory is already up-to-date with origin/master.
This commit is contained in:
@@ -10,6 +10,20 @@ vim.api.nvim_create_user_command('UpdateKickestEnd', function()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Fetch latest changes first
|
||||||
|
vim.fn.system { 'git', '-C', config_path, 'fetch', '--all' }
|
||||||
|
if vim.v.shell_error ~= 0 then
|
||||||
|
vim.notify('Git fetch failed.', vim.log.levels.ERROR)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Check if local master is behind origin/master
|
||||||
|
local behind = vim.fn.systemlist { 'git', '-C', config_path, 'rev-list', '--count', 'master..origin/master' }
|
||||||
|
if tonumber(behind[1]) == 0 then
|
||||||
|
vim.notify('KickestEnd.nvim is already up-to-date with origin/master.', vim.log.levels.INFO)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- Check for local modifications or untracked files
|
-- Check for local modifications or untracked files
|
||||||
local status = vim.fn.systemlist { 'git', '-C', config_path, 'status', '--porcelain' }
|
local status = vim.fn.systemlist { 'git', '-C', config_path, 'status', '--porcelain' }
|
||||||
local dirty = #status > 0
|
local dirty = #status > 0
|
||||||
@@ -22,20 +36,11 @@ vim.api.nvim_create_user_command('UpdateKickestEnd', function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
vim.notify('Discarding all local changes and untracked files...', vim.log.levels.WARN)
|
vim.notify('Discarding all local changes and untracked files...', vim.log.levels.WARN)
|
||||||
|
|
||||||
-- Hard reset and clean untracked files/folders
|
|
||||||
vim.fn.system { 'git', '-C', config_path, 'reset', '--hard' }
|
vim.fn.system { 'git', '-C', config_path, 'reset', '--hard' }
|
||||||
vim.fn.system { 'git', '-C', config_path, 'clean', '-fdx' }
|
vim.fn.system { 'git', '-C', config_path, 'clean', '-fdx' }
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Fetch and update
|
-- Reset to latest commit
|
||||||
vim.notify('Fetching latest changes from GitHub...', vim.log.levels.INFO)
|
|
||||||
local fetch = vim.fn.systemlist { 'git', '-C', config_path, 'fetch', '--all' }
|
|
||||||
if vim.v.shell_error ~= 0 then
|
|
||||||
vim.notify('Git fetch failed:\n' .. table.concat(fetch, '\n'), vim.log.levels.ERROR)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.notify('Resetting to latest commit on origin/master...', vim.log.levels.INFO)
|
vim.notify('Resetting to latest commit on origin/master...', vim.log.levels.INFO)
|
||||||
local reset = vim.fn.systemlist { 'git', '-C', config_path, 'reset', '--hard', 'origin/master' }
|
local reset = vim.fn.systemlist { 'git', '-C', config_path, 'reset', '--hard', 'origin/master' }
|
||||||
if vim.v.shell_error ~= 0 then
|
if vim.v.shell_error ~= 0 then
|
||||||
|
|||||||
Reference in New Issue
Block a user