From 4461a65b90e95492208d570337b4c4c0f240991d Mon Sep 17 00:00:00 2001 From: Oscar Wallberg Date: Tue, 19 May 2026 15:48:09 +0200 Subject: [PATCH] refactor(git): rework status_view header --- lua/git/status_view.lua | 49 +++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/lua/git/status_view.lua b/lua/git/status_view.lua index 059ba47..af991d2 100644 --- a/lua/git/status_view.lua +++ b/lua/git/status_view.lua @@ -103,8 +103,9 @@ local function display_name(section) end ---@param bufnr integer ----@param status ow.Git.Status -local function render(bufnr, status) +---@param r ow.Git.Repo +local function render(bufnr, r) + local status = r.status local branch = status.branch local lines = {} local marks = {} @@ -114,34 +115,48 @@ local function render(bufnr, status) table.insert(marks, { row = row, col = 0, end_col = len, hl = "Label" }) end - table.insert(lines, "Head: " .. (branch.head or "?")) - label(#lines - 1, 4) + local repo_line = vim.fn.fnamemodify(r.worktree, ":t") + table.insert(lines, repo_line) + table.insert(marks, { + row = #lines - 1, + col = 0, + end_col = #repo_line, + hl = "Directory", + }) + + table.insert(lines, "Branch: " .. (branch.head or "?")) + label(#lines - 1, 6) if branch.upstream then - local push = "Push: " .. branch.upstream + local up = "Upstream: " .. branch.upstream local extras = {} if branch.ahead > 0 then - local col = #push + 1 - push = push .. " +" .. branch.ahead - table.insert(extras, { col = col, end_col = #push, hl = "GitUnpushed" }) + local col = #up + 1 + up = up .. " +" .. branch.ahead + table.insert(extras, { + col = col, + end_col = #up, + hl = "GitUnpushed", + }) end if branch.behind > 0 then - local col = #push + 1 - push = push .. " -" .. branch.behind - table.insert(extras, { col = col, end_col = #push, hl = "GitUnpulled" }) + local col = #up + 1 + up = up .. " -" .. branch.behind + table.insert(extras, { + col = col, + end_col = #up, + hl = "GitUnpulled", + }) end - table.insert(lines, push) + table.insert(lines, up) local row = #lines - 1 - label(row, 4) + label(row, 8) for _, e in ipairs(extras) do e.row = row table.insert(marks, e) end end - table.insert(lines, "Help: g?") - label(#lines - 1, 4) - table.insert(lines, "") for _, section in ipairs(SECTIONS) do @@ -191,7 +206,7 @@ local function refresh(bufnr) if not s or not vim.api.nvim_buf_is_valid(bufnr) then return end - render(bufnr, s.repo.status) + render(bufnr, s.repo) end ---@param bufnr integer