feat(git/statusline): expose status via b:git_status, opt-in via enable()
This commit is contained in:
+21
-19
@@ -220,24 +220,26 @@ end
|
||||
|
||||
---@return string?
|
||||
function Repo:head()
|
||||
local f = io.open(vim.fs.joinpath(self.gitdir, "HEAD"), "r")
|
||||
if not f then
|
||||
return self:get_cached("head", function(self)
|
||||
local f = io.open(vim.fs.joinpath(self.gitdir, "HEAD"), "r")
|
||||
if not f then
|
||||
return nil
|
||||
end
|
||||
local first = f:read("*l")
|
||||
f:close()
|
||||
if not first then
|
||||
return nil
|
||||
end
|
||||
local branch = first:match("^ref:%s*refs/heads/(%S+)")
|
||||
if branch then
|
||||
return branch
|
||||
end
|
||||
local sha = first:match("^(%x+)")
|
||||
if sha then
|
||||
return sha:sub(1, 7)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
local first = f:read("*l")
|
||||
f:close()
|
||||
if not first then
|
||||
return nil
|
||||
end
|
||||
local branch = first:match("^ref:%s*refs/heads/(%S+)")
|
||||
if branch then
|
||||
return branch
|
||||
end
|
||||
local sha = first:match("^(%x+)")
|
||||
if sha then
|
||||
return sha:sub(1, 7)
|
||||
end
|
||||
return nil
|
||||
end)
|
||||
end
|
||||
|
||||
---@return string[]
|
||||
@@ -408,7 +410,7 @@ end
|
||||
---@return string
|
||||
local function path_for_buf(buf)
|
||||
local path = vim.api.nvim_buf_get_name(buf)
|
||||
if path == "" or path:match("^%a+://") then
|
||||
if path == "" or util.is_uri(path) then
|
||||
return vim.fn.getcwd()
|
||||
end
|
||||
return vim.fn.resolve(path)
|
||||
@@ -514,7 +516,7 @@ local function is_worktree_buf(buf)
|
||||
return false
|
||||
end
|
||||
local path = vim.api.nvim_buf_get_name(buf)
|
||||
return path ~= "" and not path:match("^%a+://")
|
||||
return path ~= "" and not util.is_uri(path)
|
||||
end
|
||||
|
||||
---@param buf? integer
|
||||
|
||||
Reference in New Issue
Block a user