Skip to content

Commit d544cb9

Browse files
authored
Merge pull request #148 from tmwitczak/fix/windows-git-branch
Support absolute/relative path checks on Windows
2 parents 573bdc8 + a35283e commit d544cb9

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

lua/galaxyline/provider_vcs.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,20 @@ function M.get_git_dir(path)
6161
end
6262
end
6363

64+
-- Check if git directory is absolute path or a relative
65+
local function is_path_absolute(dir)
66+
local patterns = {
67+
'^/', -- unix
68+
'^%a:[/\\]', -- windows
69+
}
70+
for _, pattern in ipairs(patterns) do
71+
if string.find(dir, pattern) then
72+
return true
73+
end
74+
end
75+
return false
76+
end
77+
6478
-- If path nil or '.' get the absolute path to current directory
6579
if not path or path == '.' then
6680
path = vim.fn.getcwd()
@@ -81,8 +95,7 @@ function M.get_git_dir(path)
8195

8296
if not git_dir then return end
8397

84-
-- Check if git directory is absolute path or a relative
85-
if git_dir:sub(1,1) == '/' then
98+
if is_path_absolute(git_dir) then
8699
return git_dir
87100
end
88101
return path .. '/' .. git_dir

0 commit comments

Comments
 (0)