From 17b9119f999dc1d09e4744d514dd89015e85b707 Mon Sep 17 00:00:00 2001 From: psychhim Date: Sun, 12 Oct 2025 21:29:15 +0530 Subject: [PATCH] Fix: Not updating now if the directory is already up-to-date with origin/master. --- lua/update_kickestend.lua | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lua/update_kickestend.lua b/lua/update_kickestend.lua index 21ffc87..7c4fad9 100644 --- a/lua/update_kickestend.lua +++ b/lua/update_kickestend.lua @@ -10,6 +10,20 @@ vim.api.nvim_create_user_command('UpdateKickestEnd', function() return 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 local status = vim.fn.systemlist { 'git', '-C', config_path, 'status', '--porcelain' } local dirty = #status > 0 @@ -22,20 +36,11 @@ vim.api.nvim_create_user_command('UpdateKickestEnd', function() end 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, 'clean', '-fdx' } end - -- Fetch and update - 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 - + -- Reset to latest commit 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' } if vim.v.shell_error ~= 0 then