Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lua/gitlab/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,18 @@ M.get_ahead_behind = function(current_branch, remote_branch)
return tonumber(ahead), tonumber(behind)
end

---Return the name of the current branch or nil if it can't be retrieved
---Return the name of the current branch, or nil (detached HEAD or git failure).
---@return string|nil
M.get_current_branch = function()
local current_branch, err = run_system({ "git", "branch", "--show-current" })
if err or current_branch == "" then
if err then
require("gitlab.utils").notify("Could not get current branch: " .. err, vim.log.levels.ERROR)
return nil
end
if current_branch == "" then
-- detached HEAD: `git branch --show-current` returns empty + exit 0
Comment thread
jakubbortlik marked this conversation as resolved.
return nil
end
return current_branch
end

Expand Down
Loading