summaryrefslogtreecommitdiff
path: root/lua/utility/git.lua
blob: b43ccc52b88f74c4af0891c0fb4c38f6b954e586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require("utility.misc")

function RepositoryRoot()
	local current_file = GetCurrentFile()

    if current_file == "fzf" then
        return ""
    end

    local super_project_path = vim.fn.system("git -C " .. Dirname(current_file)
		.. " rev-parse --show-superproject-working-tree")

    if vim.v.shell_error ~= 0 then
        return ""
    end

    if super_project_path then
        return super_project_path
    end

    local toplevel_path = vim.fn.system("git -C " .. Dirname(current_file)
		.. " rev-parse --show-toplevel | tr -d '\n'")

    if vim.v.shell_error ~= 0 then
        return ""
    end

    return toplevel_path
end