From e5afc463375579c046753e1128ce486fcf8900e1 Mon Sep 17 00:00:00 2001 From: psychhim Date: Sun, 12 Oct 2025 21:35:35 +0530 Subject: [PATCH] Fix: Detect untracked files when checking if the branch is already up-to-date. --- lua/update_kickestend.lua | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lua/update_kickestend.lua b/lua/update_kickestend.lua index 7c4fad9..a710d68 100644 --- a/lua/update_kickestend.lua +++ b/lua/update_kickestend.lua @@ -4,30 +4,31 @@ vim.api.nvim_create_user_command('UpdateKickestEnd', function() local config_path = vim.fn.expand '~/.config/nvim' - -- Ensure this is a git repo if vim.fn.isdirectory(config_path .. '/.git') == 0 then vim.notify('Not a git repository: ' .. config_path, vim.log.levels.ERROR) return end - -- Fetch latest changes first + -- Fetch latest changes from remote 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 + -- Check if local master is behind origin/master + local behind = tonumber(vim.fn.systemlist({ 'git', '-C', config_path, 'rev-list', '--count', 'master..origin/master' })[1]) + + if not dirty and behind == 0 then + vim.notify('KickestEnd.nvim is already up-to-date with origin/master.', vim.log.levels.INFO) + return + end + + -- If there are local changes or untracked files, confirm overwrite if dirty then local answer = vim.fn.input 'Local changes or new files detected! Overwrite and delete them? (y/N): ' if answer:lower() ~= 'y' then