Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: change_base with empty base #1230

Merged
merged 1 commit into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lua/gitsigns/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ end
--- @param fileformat string
--- @return Gitsigns.LineSpec
local function linespec_for_hunk(hunk, fileformat)
local hls = {} --- @type Gitsigns.LineSpec
local hls = {} --- @type [string, Gitsigns.HlMark[]][][]

local removed, added = hunk.removed.lines, hunk.added.lines

Expand Down Expand Up @@ -863,7 +863,7 @@ M.preview_hunk = noautocmd(function()
return
end

--- @type Gitsigns.LineSpec
--- @type {[1]: string, [2]: string|Gitsigns.HlMark[]}[][]
local preview_linespec = {
{ { 'Hunk <hunk_no> of <num_hunks>', 'Title' } },
unpack(linespec_for_hunk(hunk, vim.bo[bufnr].fileformat)),
Expand Down Expand Up @@ -1149,7 +1149,7 @@ end)
local function update_buf_base(bcache, base)
bcache.file_mode = base == 'FILE'
if not bcache.file_mode then
bcache.git_obj:update(base)
bcache.git_obj:change_revision(base)
end
bcache:invalidate(true)
update(bcache.bufnr)
Expand Down
17 changes: 11 additions & 6 deletions lua/gitsigns/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ local function in_git_dir(file)
end

--- @async
--- @return string? err
--- @param revision? string
function Obj:update(revision)
revision = revision and util.norm_base(revision) or self.revision
local info, err = self.repo:file_info(self.file, revision)
--- @return string? err
function Obj:change_revision(revision)
self.revision = util.norm_base(revision)
return self:refresh()
end

--- @async
--- @return string? err
function Obj:refresh()
local info, err = self.repo:file_info(self.file, self.revision)

if err then
log.eprint(err)
Expand All @@ -62,7 +68,6 @@ function Obj:update(revision)
return err
end

self.revision = revision
self.relpath = info.relpath
self.object_name = info.object_name
self.mode_bits = info.mode_bits
Expand Down Expand Up @@ -150,7 +155,7 @@ function Obj:ensure_file_in_index()
self.repo:update_index(self.mode_bits, self.object_name, self.relpath, true)
end

self:update()
self:refresh()
self.lock = nil
end

Expand Down
4 changes: 2 additions & 2 deletions lua/gitsigns/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ end
--- @field end_col? integer

--- Each element represents a multi-line segment
--- @alias Gitsigns.LineSpec { [1]: string, [2]: Gitsigns.HlMark[]}[][]
--- @alias Gitsigns.LineSpec [string, string|Gitsigns.HlMark[]][][]

--- @param hlmarks Gitsigns.HlMark[]
--- @param row_offset integer
Expand Down Expand Up @@ -250,7 +250,7 @@ local function create_win(bufnr, opts, id)
return winid
end

--- @param lines_spec {[1]: string, [2]: string|Gitsigns.HlMark[]}[][]
--- @param lines_spec Gitsigns.LineSpec
--- @param opts table
--- @param id? string
--- @return integer winid, integer bufnr
Expand Down
4 changes: 2 additions & 2 deletions lua/gitsigns/watcher.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ local function handle_moved(bufnr, old_relpath)

git_obj.file = git_obj.repo.toplevel .. util.path_sep .. git_obj.relpath
bcache.file = git_obj.file
git_obj:update()
git_obj:refresh()
if not manager.schedule(bufnr) then
return
end
Expand Down Expand Up @@ -90,7 +90,7 @@ local function watcher_handler0(bufnr)
local was_tracked = git_obj.object_name ~= nil
local old_relpath = git_obj.relpath

git_obj:update()
git_obj:refresh()
if not manager.schedule(bufnr) then
dprint('buffer invalid (3)')
return
Expand Down
Loading