From 1b735122268300a170a79118847f7b3d792a132a Mon Sep 17 00:00:00 2001 From: zolinthecow Date: Wed, 9 Jul 2025 20:19:03 -0700 Subject: [PATCH] claude-baseline-1752117543 --- LICENSE.md | 4 ++++ lua/nvim-claude/diff-review.lua | 34 +++++++++++++++++++-------------- lua/nvim-claude/hooks.lua | 15 ++++++++++++--- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 68f7617b..5c6684bf 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -25,3 +25,7 @@ Now baseline exists - this should work properly! Testing with debug logs to see what's happening in the hooks. After reloading hooks module - this should create debug logs! + +Testing after manual baseline creation - this should work now! + +After manually initializing stash session - test the browsing commands! diff --git a/lua/nvim-claude/diff-review.lua b/lua/nvim-claude/diff-review.lua index 02c4c2f9..d0981a4f 100644 --- a/lua/nvim-claude/diff-review.lua +++ b/lua/nvim-claude/diff-review.lua @@ -130,7 +130,7 @@ end -- Get Claude stashes (only stashes with [claude-edit] messages) function M.get_claude_stashes() local utils = require('nvim-claude.utils') - local cmd = 'git stash list --grep="claude-edit"' + local cmd = 'git stash list' local result = utils.exec(cmd) if not result or result == '' then @@ -139,7 +139,7 @@ function M.get_claude_stashes() local stashes = {} for line in result:gmatch('[^\n]+') do - if line ~= '' then + if line ~= '' and line:match('%[claude%-edit%]') then local stash_ref = line:match('^(stash@{%d+})') if stash_ref then table.insert(stashes, { @@ -174,19 +174,25 @@ function M.open_diffview() -- Try to recover stash-based session from baseline local utils = require('nvim-claude.utils') local baseline_ref = utils.read_file('/tmp/claude-baseline-commit') - if baseline_ref and baseline_ref ~= '' then - baseline_ref = baseline_ref:gsub('%s+', '') - local claude_stashes = M.get_claude_stashes() - if claude_stashes and #claude_stashes > 0 then - M.current_review = { - baseline_ref = baseline_ref, - timestamp = os.time(), - claude_stashes = claude_stashes, - current_stash_index = 0, -- Show cumulative view by default - is_stash_based = true - } - vim.notify('Recovered Claude stash session from baseline', vim.log.levels.INFO) + + -- If no baseline file, but we have Claude stashes, use HEAD as baseline + local claude_stashes = M.get_claude_stashes() + if claude_stashes and #claude_stashes > 0 then + if not baseline_ref or baseline_ref == '' then + baseline_ref = 'HEAD' + vim.notify('No baseline found, using HEAD as baseline', vim.log.levels.INFO) + else + baseline_ref = baseline_ref:gsub('%s+', '') end + + M.current_review = { + baseline_ref = baseline_ref, + timestamp = os.time(), + claude_stashes = claude_stashes, + current_stash_index = 0, -- Show cumulative view by default + is_stash_based = true + } + vim.notify(string.format('Recovered Claude stash session with %d stashes', #claude_stashes), vim.log.levels.INFO) end if not M.current_review then diff --git a/lua/nvim-claude/hooks.lua b/lua/nvim-claude/hooks.lua index 34a2d08b..47e8f674 100644 --- a/lua/nvim-claude/hooks.lua +++ b/lua/nvim-claude/hooks.lua @@ -68,9 +68,18 @@ function M.pre_tool_use_hook() return end - -- Store the baseline commit reference - M.baseline_commit = 'HEAD' - utils.write_file(baseline_file, 'HEAD') + -- Store the actual commit hash instead of 'HEAD' + 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 and commit_hash ~= '' then + commit_hash = commit_hash:gsub('%s+', '') + M.baseline_commit = commit_hash + utils.write_file(baseline_file, commit_hash) + else + M.baseline_commit = 'HEAD' + utils.write_file(baseline_file, 'HEAD') + end vim.notify('New baseline commit created: ' .. commit_msg, vim.log.levels.INFO) end