|
|
|
@ -355,11 +355,53 @@ function M.reject_current_hunk(bufnr)
|
|
|
|
|
-- Revert the hunk by applying original content
|
|
|
|
|
M.revert_hunk_changes(bufnr, hunk)
|
|
|
|
|
|
|
|
|
|
-- Update baseline to the state after rejection
|
|
|
|
|
local current_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
|
|
|
|
local current_content = table.concat(current_lines, '\n')
|
|
|
|
|
M.original_content[bufnr] = current_content
|
|
|
|
|
vim.notify('Baseline updated after rejection', vim.log.levels.INFO)
|
|
|
|
|
-- Create a new baseline commit with the rejected changes reverted
|
|
|
|
|
local utils = require('nvim-claude.utils')
|
|
|
|
|
local git_root = utils.get_project_root()
|
|
|
|
|
|
|
|
|
|
if git_root then
|
|
|
|
|
-- Save the buffer to ensure changes are on disk
|
|
|
|
|
vim.api.nvim_buf_call(bufnr, function()
|
|
|
|
|
if vim.bo.modified then
|
|
|
|
|
vim.cmd('write')
|
|
|
|
|
vim.notify('Buffer saved', vim.log.levels.INFO)
|
|
|
|
|
else
|
|
|
|
|
vim.notify('Buffer already saved', vim.log.levels.INFO)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- Stage only the current file (now with hunk reverted)
|
|
|
|
|
local file_path = vim.api.nvim_buf_get_name(bufnr)
|
|
|
|
|
local relative_path = file_path:gsub('^' .. git_root .. '/', '')
|
|
|
|
|
|
|
|
|
|
-- Create a new baseline commit with only this file
|
|
|
|
|
local timestamp = os.time()
|
|
|
|
|
local commit_msg = string.format('claude-baseline-%d (rejected changes)', timestamp)
|
|
|
|
|
|
|
|
|
|
-- Use git commit with only the specific file
|
|
|
|
|
local commit_cmd = string.format('cd "%s" && git add "%s" && git commit -m "%s" -- "%s"',
|
|
|
|
|
git_root, relative_path, commit_msg, relative_path)
|
|
|
|
|
local commit_result, commit_err = utils.exec(commit_cmd)
|
|
|
|
|
|
|
|
|
|
if not commit_err or commit_err:match('nothing to commit') then
|
|
|
|
|
-- Get the new commit hash
|
|
|
|
|
local hash_cmd = string.format('cd "%s" && git rev-parse HEAD', git_root)
|
|
|
|
|
local commit_hash, hash_err = utils.exec(hash_cmd)
|
|
|
|
|
|
|
|
|
|
if not hash_err and commit_hash then
|
|
|
|
|
commit_hash = commit_hash:gsub('%s+', '')
|
|
|
|
|
-- Update the baseline file
|
|
|
|
|
utils.write_file('/tmp/claude-baseline-commit', commit_hash)
|
|
|
|
|
|
|
|
|
|
-- Update in-memory baseline
|
|
|
|
|
local current_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
|
|
|
|
local current_content = table.concat(current_lines, '\n')
|
|
|
|
|
M.original_content[bufnr] = current_content
|
|
|
|
|
|
|
|
|
|
vim.notify('Baseline commit created after rejection: ' .. commit_hash:sub(1, 7), vim.log.levels.INFO)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Remove this hunk from the diff data since it's rejected
|
|
|
|
|
table.remove(diff_data.hunks, diff_data.current_hunk)
|
|
|
|
@ -525,18 +567,65 @@ end
|
|
|
|
|
|
|
|
|
|
-- Update baseline content after accepting a hunk
|
|
|
|
|
function M.update_baseline_after_accept(bufnr, hunk)
|
|
|
|
|
-- Get current content (which now includes the accepted change)
|
|
|
|
|
local current_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
|
|
|
|
local current_content = table.concat(current_lines, '\n')
|
|
|
|
|
local utils = require('nvim-claude.utils')
|
|
|
|
|
local git_root = utils.get_project_root()
|
|
|
|
|
|
|
|
|
|
if not git_root then
|
|
|
|
|
vim.notify('Not in a git repository', vim.log.levels.ERROR)
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Save the buffer to ensure changes are on disk
|
|
|
|
|
vim.api.nvim_buf_call(bufnr, function()
|
|
|
|
|
if vim.bo.modified then
|
|
|
|
|
vim.cmd('write')
|
|
|
|
|
vim.notify('Buffer saved', vim.log.levels.INFO)
|
|
|
|
|
else
|
|
|
|
|
vim.notify('Buffer already saved', vim.log.levels.INFO)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- Stage only the current file
|
|
|
|
|
local file_path = vim.api.nvim_buf_get_name(bufnr)
|
|
|
|
|
local relative_path = file_path:gsub('^' .. git_root .. '/', '')
|
|
|
|
|
|
|
|
|
|
vim.notify('DEBUG: Updating baseline for buffer ' .. bufnr, vim.log.levels.INFO)
|
|
|
|
|
vim.notify('DEBUG: New baseline content length: ' .. #current_content, vim.log.levels.INFO)
|
|
|
|
|
-- Create a new baseline commit with only this file
|
|
|
|
|
local timestamp = os.time()
|
|
|
|
|
local commit_msg = string.format('claude-baseline-%d (accepted changes)', timestamp)
|
|
|
|
|
|
|
|
|
|
-- Update the stored original content to match current content
|
|
|
|
|
-- This way, future diffs will compare against this new baseline
|
|
|
|
|
M.original_content[bufnr] = current_content
|
|
|
|
|
-- Use git commit with only the specific file
|
|
|
|
|
local commit_cmd = string.format('cd "%s" && git add "%s" && git commit -m "%s" -- "%s"',
|
|
|
|
|
git_root, relative_path, commit_msg, relative_path)
|
|
|
|
|
local commit_result, commit_err = utils.exec(commit_cmd)
|
|
|
|
|
|
|
|
|
|
vim.notify('Baseline updated to include accepted changes', vim.log.levels.INFO)
|
|
|
|
|
vim.notify('Commit command: ' .. commit_cmd, vim.log.levels.INFO)
|
|
|
|
|
vim.notify('Commit result: ' .. (commit_result or 'nil'), vim.log.levels.INFO)
|
|
|
|
|
|
|
|
|
|
if commit_result and (commit_result:match('1 file changed') or commit_result:match('create mode')) then
|
|
|
|
|
-- Commit was successful
|
|
|
|
|
local hash_cmd = string.format('cd "%s" && git rev-parse HEAD', git_root)
|
|
|
|
|
local commit_hash, hash_err = utils.exec(hash_cmd)
|
|
|
|
|
|
|
|
|
|
if not hash_err and commit_hash then
|
|
|
|
|
commit_hash = commit_hash:gsub('%s+', '')
|
|
|
|
|
-- Update the baseline file
|
|
|
|
|
utils.write_file('/tmp/claude-baseline-commit', commit_hash)
|
|
|
|
|
|
|
|
|
|
-- Update in-memory baseline
|
|
|
|
|
local current_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
|
|
|
|
local current_content = table.concat(current_lines, '\n')
|
|
|
|
|
M.original_content[bufnr] = current_content
|
|
|
|
|
|
|
|
|
|
vim.notify('Baseline commit created: ' .. commit_hash:sub(1, 7), vim.log.levels.INFO)
|
|
|
|
|
else
|
|
|
|
|
vim.notify('Failed to get commit hash: ' .. (hash_err or 'unknown'), vim.log.levels.ERROR)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
vim.notify('Failed to create baseline commit', vim.log.levels.ERROR)
|
|
|
|
|
if commit_err then
|
|
|
|
|
vim.notify('Error: ' .. commit_err, vim.log.levels.ERROR)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- Test keymap functionality
|
|
|
|
|