refactor(git): route every git invocation through util.git
This commit is contained in:
+21
-21
@@ -38,8 +38,7 @@ local global = util.Emitter.new()
|
||||
local Repo = {}
|
||||
Repo.__index = Repo
|
||||
|
||||
local STATUS_CMD = {
|
||||
"git",
|
||||
local STATUS_ARGS = {
|
||||
"--no-optional-locks",
|
||||
"-c",
|
||||
"core.quotePath=false",
|
||||
@@ -52,20 +51,22 @@ local STATUS_CMD = {
|
||||
|
||||
---@private
|
||||
function Repo:_fetch_status()
|
||||
vim.system(
|
||||
STATUS_CMD,
|
||||
{ cwd = self.worktree, text = true },
|
||||
vim.schedule_wrap(function(obj)
|
||||
util.git(STATUS_ARGS, {
|
||||
cwd = self.worktree,
|
||||
on_exit = function(result)
|
||||
self._cache = {}
|
||||
if obj.code ~= 0 then
|
||||
util.error("git status failed: %s", vim.trim(obj.stderr or ""))
|
||||
if result.code ~= 0 then
|
||||
util.error(
|
||||
"git status failed: %s",
|
||||
vim.trim(result.stderr or "")
|
||||
)
|
||||
return
|
||||
end
|
||||
self.status = status.parse(obj.stdout or "")
|
||||
self.status = status.parse(result.stdout or "")
|
||||
self._events:emit("refresh", self.status)
|
||||
global:emit("refresh", self, self.status)
|
||||
end)
|
||||
)
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
function Repo:refresh()
|
||||
@@ -242,8 +243,7 @@ end
|
||||
---@return string[]
|
||||
function Repo:list_refs()
|
||||
return self:get_cached("refs", function(self)
|
||||
local out = util.exec({
|
||||
"git",
|
||||
local out = util.git({
|
||||
"for-each-ref",
|
||||
"--format=%(refname:short)",
|
||||
"refs/heads",
|
||||
@@ -287,8 +287,8 @@ function Repo:list_stash_refs()
|
||||
return {}
|
||||
end
|
||||
local refs = { "stash" }
|
||||
local out = util.exec(
|
||||
{ "git", "stash", "list", "--pretty=format:%gd" },
|
||||
local out = util.git(
|
||||
{ "stash", "list", "--pretty=format:%gd" },
|
||||
{ cwd = self.worktree, silent = true }
|
||||
)
|
||||
if out then
|
||||
@@ -304,12 +304,12 @@ end
|
||||
---@param short boolean
|
||||
---@return string?
|
||||
function Repo:rev_parse(rev, short)
|
||||
local cmd = { "git", "rev-parse", "--verify", "--quiet" }
|
||||
local args = { "rev-parse", "--verify", "--quiet" }
|
||||
if short then
|
||||
table.insert(cmd, "--short")
|
||||
table.insert(args, "--short")
|
||||
end
|
||||
table.insert(cmd, rev)
|
||||
local stdout = util.exec(cmd, { cwd = self.worktree, silent = true })
|
||||
table.insert(args, rev)
|
||||
local stdout = util.git(args, { cwd = self.worktree, silent = true })
|
||||
local trimmed = stdout and vim.trim(stdout) or ""
|
||||
return trimmed ~= "" and trimmed or nil
|
||||
end
|
||||
@@ -321,8 +321,8 @@ end
|
||||
---@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 },
|
||||
local out = util.git(
|
||||
{ "rev-parse", "--disambiguate=" .. prefix },
|
||||
{ cwd = self.worktree, silent = true }
|
||||
)
|
||||
local trimmed = out and vim.trim(out) or ""
|
||||
|
||||
Reference in New Issue
Block a user