refactor(git): scratch buffers wipe by default, consolidate factories in util

This commit is contained in:
2026-04-29 10:39:48 +02:00
parent 0766c7f11e
commit 18b198f293
6 changed files with 48 additions and 54 deletions
+2 -9
View File
@@ -229,10 +229,7 @@ end
local function blob_buf(worktree, blob, path, ref)
local revspec = ref .. ":" .. path
if is_zero(blob) then
return diff.empty_buf({
name = util.uri(revspec),
bufhidden = "hide",
})
return util.empty_buf({ name = util.uri(revspec) })
end
return M.buf_for(worktree, revspec)
end
@@ -269,10 +266,7 @@ end
---@field split (false|"above"|"below"|"left"|"right")? forwarded to `util.new_scratch`. Default opens a new horizontal split.
---Place a `git://<revspec>` URI buffer in a window per `opts.split`.
---`bufadd` dedups against existing buffers, so re-opening the same URI
---reuses the buffer (and `bufload` no-ops). `read_uri` defaults to
---`bufhidden=wipe` (right for diff sides), but navigation buffers
---should persist across window closes, so override to `hide`.
---`bufadd` dedups against existing buffers; `bufload` no-ops if loaded.
---@param worktree string
---@param uri string
---@param sha string written to `b:git_ref` so `<CR>` navigation in the buffer can resolve relative paths
@@ -283,7 +277,6 @@ local function open_uri(worktree, uri, sha, opts, default_ft)
vim.b[buf].git_worktree = worktree
vim.b[buf].git_ref = sha
vim.fn.bufload(buf)
vim.bo[buf].bufhidden = "hide"
if default_ft and vim.bo[buf].filetype == "" then
vim.bo[buf].filetype = default_ft
end