refactor(git): drive :G dispatch from buffer content
This commit is contained in:
+24
-3
@@ -15,9 +15,6 @@ end
|
||||
---@class ow.Git.Repo.BufState
|
||||
---@field repo ow.Git.Repo
|
||||
---@field sha string?
|
||||
---@field parent_sha string?
|
||||
---@field left_ref string?
|
||||
---@field right_ref string?
|
||||
---@field initialized boolean?
|
||||
---@field immutable boolean?
|
||||
---@field index_writer boolean?
|
||||
@@ -318,6 +315,30 @@ function Repo:rev_parse(rev, short)
|
||||
return trimmed ~= "" and trimmed or nil
|
||||
end
|
||||
|
||||
---@alias ow.Git.Repo.ResolveStatus "ok"|"ambiguous"|"missing"
|
||||
|
||||
---@param prefix string
|
||||
---@return string? full_sha
|
||||
---@return ow.Git.Repo.ResolveStatus
|
||||
function Repo:resolve_sha(prefix)
|
||||
local result = self:get_cached("resolve:" .. prefix, function(self)
|
||||
local out = util.exec(
|
||||
{ "git", "rev-parse", "--disambiguate=" .. prefix },
|
||||
{ cwd = self.worktree, silent = true }
|
||||
)
|
||||
local trimmed = out and vim.trim(out) or ""
|
||||
if trimmed == "" then
|
||||
return { nil, "missing" }
|
||||
end
|
||||
local lines = util.split_lines(trimmed)
|
||||
if #lines == 1 then
|
||||
return { lines[1], "ok" }
|
||||
end
|
||||
return { nil, "ambiguous" }
|
||||
end)
|
||||
return result[1], result[2]
|
||||
end
|
||||
|
||||
---@type table<string, ow.Git.Repo> keyed by worktree
|
||||
local repos = {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user