refactor(git): rework module around clearer Status and Repo split

This commit is contained in:
2026-05-06 00:45:56 +02:00
parent 1b43fa6a1c
commit 80d6d465cf
17 changed files with 821 additions and 775 deletions
+8 -8
View File
@@ -5,11 +5,11 @@ local util = require("git.util")
local M = {}
---@class ow.Git.SplitHandler
---@class ow.Git.Cmd.SplitHandler
---@field ft string
---@field needs_rev boolean?
---@type table<string, ow.Git.SplitHandler>
---@type table<string, ow.Git.Cmd.SplitHandler>
local SPLIT_HANDLERS = {
log = { ft = "git" },
diff = { ft = "diff" },
@@ -74,7 +74,7 @@ end
---@param r ow.Git.Repo
---@param args string[]
---@param conf ow.Git.SplitHandler
---@param conf ow.Git.Cmd.SplitHandler
local function run_in_split(r, args, conf)
local cmd = { "git" }
vim.list_extend(cmd, args)
@@ -86,7 +86,7 @@ local function run_in_split(r, args, conf)
end
local name = "[git " .. table.concat(args, " ") .. "]"
local buf = place_split(name)
repo.attach(buf, r)
repo.bind(buf, r)
object.attach_dispatch(buf)
local state = r:state(buf) --[[@as -nil]]
state.sha = nil
@@ -178,7 +178,7 @@ end
---@param args string[]
function M.run(args)
local r = repo.find()
local r = repo.resolve()
if not r then
util.warning("not in a git repository")
return
@@ -193,7 +193,7 @@ function M.run(args)
if sub == "show" then
local arg = first_positional(args, 2)
if arg and arg:find(":", 1, true) then
object.open_object(r, arg)
object.open(r, arg)
return
end
run_in_split(r, args, { ft = "git", needs_rev = true })
@@ -204,7 +204,7 @@ function M.run(args)
if vim.list_contains(args, "-p") then
local rev = first_positional(args, 2)
if rev then
object.open_object(r, rev)
object.open(r, rev)
return
end
end
@@ -223,7 +223,7 @@ end
---@param arg_lead string
---@return string[]
function M.complete_rev(arg_lead)
local r = repo.find()
local r = repo.resolve()
if not r then
return {}
end