refactor(git): extract repo.resolve_cwd helper
This commit is contained in:
@@ -83,6 +83,18 @@ local function resolve(path)
|
||||
return vim.fs.normalize(gitdir), worktree
|
||||
end
|
||||
|
||||
---Resolve the gitdir/worktree from the current buffer's file path, falling
|
||||
---back to `vim.fn.getcwd()` when the buffer is unnamed. Returns nil for
|
||||
---both when not inside a git repo.
|
||||
---@return string?, string? gitdir, worktree
|
||||
local function resolve_cwd()
|
||||
local path = vim.api.nvim_buf_get_name(0)
|
||||
if path == "" then
|
||||
path = vim.fn.getcwd()
|
||||
end
|
||||
return resolve(path)
|
||||
end
|
||||
|
||||
---@class ow.Git.Repo
|
||||
---@field gitdir string
|
||||
---@field worktree string
|
||||
@@ -312,6 +324,7 @@ return {
|
||||
indicator = indicator,
|
||||
refresh_buf = refresh_buf,
|
||||
resolve = resolve,
|
||||
resolve_cwd = resolve_cwd,
|
||||
rev_parse = rev_parse,
|
||||
stop_all = stop_all,
|
||||
unregister = unregister,
|
||||
|
||||
Reference in New Issue
Block a user