refactor(git): extract repo.resolve_cwd helper

This commit is contained in:
2026-04-27 13:41:39 +02:00
parent 4b8d551b0d
commit b4c166e86c
5 changed files with 17 additions and 20 deletions
+13
View File
@@ -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,