diff --git a/lua/git/repo.lua b/lua/git/repo.lua index 5302ebd..25abd07 100644 --- a/lua/git/repo.lua +++ b/lua/git/repo.lua @@ -2,45 +2,6 @@ local util = require("git.util") local M = {} -M.UNMERGED = { - DD = true, - AU = true, - UD = true, - UA = true, - DU = true, - AA = true, - UU = true, -} - ----@param code string ----@return string? char ----@return string? hl_group -function M.indicator(code) - if code == "" then - return nil - end - if code == "??" then - return "?", "GitUntracked" - end - if code == "!!" then - return "!", "GitIgnored" - end - if M.UNMERGED[code] then - return "U", "GitUnmerged" - end - local x, y = code:sub(1, 1), code:sub(2, 2) - if x == "R" or y == "R" then - return "R", "GitRenamed" - end - if y == " " and x ~= " " then - return x, "GitStaged" - end - if y == "D" then - return "D", "GitDeleted" - end - return "M", "GitUnstaged" -end - ---@param path string ---@return string? gitdir ---@return string? worktree diff --git a/lua/git/sidebar.lua b/lua/git/sidebar.lua index 44ab973..d8be7ce 100644 --- a/lua/git/sidebar.lua +++ b/lua/git/sidebar.lua @@ -2,6 +2,7 @@ local Revision = require("git.revision") local diff = require("git.diff") local object = require("git.object") local repo = require("git.repo") +local status = require("git.status") local util = require("git.util") local M = {} @@ -99,7 +100,7 @@ local function format_entry(entry) if not code then return nil end - local char, hl = repo.indicator(code) + local char, hl = status.indicator(code) if not char then return nil end @@ -177,7 +178,7 @@ local function parse_porcelain(stdout) if x == "?" and y == "?" then entry.section = "Untracked" table.insert(groups.Untracked, entry) - elseif repo.UNMERGED[x .. y] then + elseif status.UNMERGED[x .. y] then entry.section = "Unmerged" table.insert(groups.Unmerged, entry) else diff --git a/lua/git/status.lua b/lua/git/status.lua new file mode 100644 index 0000000..9826624 --- /dev/null +++ b/lua/git/status.lua @@ -0,0 +1,52 @@ +local M = {} + +M.UNMERGED = { + DD = true, + AU = true, + UD = true, + UA = true, + DU = true, + AA = true, + UU = true, +} + +---@param code string +---@return string? char +---@return string? hl_group +function M.indicator(code) + if code == "" then + return nil + end + if code == "??" then + return "?", "GitUntracked" + end + if code == "!!" then + return "!", "GitIgnored" + end + if M.UNMERGED[code] then + return "U", "GitUnmerged" + end + local x, y = code:sub(1, 1), code:sub(2, 2) + if x == "R" or y == "R" then + return "R", "GitRenamed" + end + if y == " " and x ~= " " then + return x, "GitStaged" + end + if y == "D" then + return "D", "GitDeleted" + end + return "M", "GitUnstaged" +end + +---@param code string +---@return string? +function M.format(code) + local char, hl = M.indicator(code) + if not char then + return nil + end + return string.format("%%#%s#%s%%*", hl, char) +end + +return M diff --git a/lua/git/watcher.lua b/lua/git/watcher.lua index 03d7892..8df1027 100644 --- a/lua/git/watcher.lua +++ b/lua/git/watcher.lua @@ -1,18 +1,9 @@ local repo = require("git.repo") +local status = require("git.status") local util = require("git.util") local M = {} ----@param code string ----@return string? -local function format(code) - local char, hl = repo.indicator(code) - if not char then - return nil - end - return string.format("%%#%s#%s%%*", hl, char) -end - ---@class ow.Git.Repo ---@field gitdir string ---@field worktree string @@ -89,7 +80,7 @@ local function do_refresh(r) end end statuses[vim.fs.joinpath(r.worktree, path_part)] = - format(code) + status.format(code) end end else