mirror of
https://github.com/hyzendust/KickestEnd.nvim.git
synced 2026-02-15 03:41:14 +01:00
Fix: Detect untracked files when checking if the branch is already up-to-date.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user