Skip to content

Commit

Permalink
fix: do not show staged signs for different bases
Browse files Browse the repository at this point in the history
Fixes #1118
  • Loading branch information
lewis6991 committed Jan 20, 2025
1 parent 817bd84 commit 0edca9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lua/gitsigns/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ end
--- @field object_name? string
--- @field has_conflicts? true

--- @return boolean
function Obj:from_tree()
return self.revision and not vim.startswith(self.revision, ':')
return self.revision ~= nil and not vim.startswith(self.revision, ':')
end

--- @async
Expand Down
19 changes: 17 additions & 2 deletions lua/gitsigns/manager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,24 @@ M.update = throttle_by_id(function(bufnr)
return
end

if config.signs_staged_enable and not file_mode then
local rev_from_index = not git_obj:from_tree()
local buf_is_editable_file = vim.bo[bufnr].buftype == ''

if
config.signs_staged_enable
and not file_mode
and (rev_from_index or not buf_is_editable_file)
then
if not bcache.compare_text_head or config._refresh_staged_on_update then
local staged_rev = git_obj:from_tree() and git_obj.revision .. '^' or 'HEAD'
-- When the revision is from the index, we compare against HEAD to
-- show the staged changes.
--
-- When showing a revision buffer (a buffer that represents the revision
-- of a specific file and does not have a corresponding file on disk), we
-- utilize the staged signs to represent the changes introduced in that
-- revision. Therefore we compare against the previous commit. Note there
-- should not be any normal signs for these buffers.
local staged_rev = rev_from_index and 'HEAD' or git_obj.revision .. '^'
bcache.compare_text_head = git_obj:get_show_text(staged_rev)
if not M.schedule(bufnr, true) then
return
Expand Down

0 comments on commit 0edca9d

Please sign in to comment.