Skip to content

Commit

Permalink
Show HEAD as NeogitBranchHead in Log Graph
Browse files Browse the repository at this point in the history
In the log graph it's non intuitive where the currently checked out
branch is. To make this more customizable for the user, we add the
`NeogitBranchHead` highlight group.
  • Loading branch information
gollth committed Nov 16, 2023
1 parent 55c2d50 commit 9d0a805
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/neogit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ exist, they will be created with sensible defaults based on your colorscheme.

STATUS BUFFER
NeogitBranch Header showing currently checked out branch
NeogitBranchHead Currently checkoued branch (in log graph)
NeogitRemote Header showing current branch's remote (if set)
NeogitObjectId Object's SHA hash
NeogitStash Stash name
Expand Down
9 changes: 6 additions & 3 deletions lua/neogit/buffers/common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,27 @@ M.CommitEntry = Component.new(function(commit, args)
remote_name, local_name = local_name, remote_name
end

local is_head = string.match(commit.ref_name, "HEAD") ~= nil
local branch_highlight = is_head and "NeogitBranchHead" or "NeogitBranch"

if local_name and remote_name and vim.endswith(remote_name, local_name) then
local remote = remote_name:match("^([^/]*)/.*$")
table.insert(ref, text(remote .. "/", { highlight = "NeogitRemote" }))
table.insert(ref, text(local_name, { highlight = "NeogitBranch" }))
table.insert(ref, text(local_name, { highlight = branch_highlight }))
table.insert(ref, text(" "))
else
if local_name then
table.insert(
ref,
text(local_name, { highlight = local_name:match("/") and "NeogitRemote" or "NeogitBranch" })
text(local_name, { highlight = local_name:match("/") and "NeogitRemote" or branch_highlight })
)
table.insert(ref, text(" "))
end

if remote_name then
table.insert(
ref,
text(remote_name, { highlight = remote_name:match("/") and "NeogitRemote" or "NeogitBranch" })
text(remote_name, { highlight = remote_name:match("/") and "NeogitRemote" or branch_highlight })
)
table.insert(ref, text(" "))
end
Expand Down
1 change: 1 addition & 0 deletions lua/neogit/lib/hl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function M.setup()
NeogitCommandCodeNormal = { link = "String" },
NeogitCommandCodeError = { link = "Error" },
NeogitBranch = { fg = palette.blue, bold = true },
NeogitBranchHead = { fg = palette.blue, bold = true, underline = true },
NeogitRemote = { fg = palette.green, bold = true },
NeogitUnmergedInto = { fg = palette.bg_purple, bold = true },
NeogitUnpushedTo = { fg = palette.bg_purple, bold = true },
Expand Down

0 comments on commit 9d0a805

Please sign in to comment.