refactor(git): make the git module self-contained under git.util
This commit is contained in:
+8
-9
@@ -1,6 +1,5 @@
|
||||
local diff = require("git.diff")
|
||||
local git = require("git")
|
||||
local log = require("log")
|
||||
local repo = require("git.repo")
|
||||
|
||||
local M = {}
|
||||
@@ -263,7 +262,7 @@ local function enrich_with_log(worktree, branch, groups)
|
||||
end
|
||||
end
|
||||
else
|
||||
log.error(
|
||||
util.error(
|
||||
"git log %s failed: %s",
|
||||
p.f.range,
|
||||
vim.trim(result.stderr or "")
|
||||
@@ -298,7 +297,7 @@ local function fetch_status(worktree, prefetched_stdout, callback)
|
||||
{ cwd = worktree, text = true },
|
||||
vim.schedule_wrap(function(obj)
|
||||
if obj.code ~= 0 then
|
||||
log.error("git status failed: %s", vim.trim(obj.stderr or ""))
|
||||
util.error("git status failed: %s", vim.trim(obj.stderr or ""))
|
||||
local branch = { ahead = 0, behind = 0 }
|
||||
local groups = {
|
||||
Untracked = {},
|
||||
@@ -761,7 +760,7 @@ local function action_stage()
|
||||
{ cwd = s.worktree },
|
||||
vim.schedule_wrap(function(obj)
|
||||
if obj.code ~= 0 then
|
||||
log.error("git add failed: %s", vim.trim(obj.stderr or ""))
|
||||
util.error("git add failed: %s", vim.trim(obj.stderr or ""))
|
||||
end
|
||||
end)
|
||||
)
|
||||
@@ -786,7 +785,7 @@ local function action_unstage()
|
||||
{ cwd = s.worktree },
|
||||
vim.schedule_wrap(function(obj)
|
||||
if obj.code ~= 0 then
|
||||
log.error(
|
||||
util.error(
|
||||
"git restore --staged failed: %s",
|
||||
vim.trim(obj.stderr or "")
|
||||
)
|
||||
@@ -802,7 +801,7 @@ local function action_discard()
|
||||
end
|
||||
---@cast entry ow.Git.FileEntry
|
||||
if entry.section == "Staged" then
|
||||
log.warning("file has staged changes; unstage first with 'u'")
|
||||
util.warning("file has staged changes; unstage first with 'u'")
|
||||
return
|
||||
end
|
||||
|
||||
@@ -821,7 +820,7 @@ local function action_discard()
|
||||
local target = vim.fs.joinpath(s.worktree, entry.path)
|
||||
local rc = vim.fn.delete(target, is_dir and "rf" or "")
|
||||
if rc ~= 0 then
|
||||
log.error("failed to delete %s", entry.path)
|
||||
util.error("failed to delete %s", entry.path)
|
||||
end
|
||||
refresh(vim.api.nvim_get_current_buf())
|
||||
end
|
||||
@@ -833,7 +832,7 @@ local function action_discard()
|
||||
{ cwd = s.worktree },
|
||||
vim.schedule_wrap(function(obj)
|
||||
if obj.code ~= 0 then
|
||||
log.error(
|
||||
util.error(
|
||||
"git checkout failed: %s",
|
||||
vim.trim(obj.stderr or "")
|
||||
)
|
||||
@@ -950,7 +949,7 @@ function M.toggle()
|
||||
end
|
||||
local _, worktree = repo.resolve_cwd()
|
||||
if not worktree then
|
||||
log.warning("not in a git repository")
|
||||
util.warning("not in a git repository")
|
||||
return
|
||||
end
|
||||
open(worktree)
|
||||
|
||||
Reference in New Issue
Block a user