From 0f951681724677fa7ac87388181fe6009ee20aff Mon Sep 17 00:00:00 2001 From: rootiest Date: Tue, 5 Nov 2024 05:55:25 -0500 Subject: [PATCH] feat: add function to check if the current directory is a git repository --- lua/data/func.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lua/data/func.lua b/lua/data/func.lua index 3440335..5206a6a 100644 --- a/lua/data/func.lua +++ b/lua/data/func.lua @@ -218,6 +218,19 @@ function M.get_os(format) end end +---@function Function to check if CWD is a git repo +---@param dir? string The directory to check, defaults to CWD +---@return boolean is_git_repo true if working directory is a git repository, false otherwise +function M.dir_is_git_repo(dir) + -- Default to the current working directory if no directory is specified + dir = dir or vim.fn.getcwd() + + local result = vim + .system({ "git", "-C", dir, "rev-parse", "--is-inside-work-tree" }) + :wait() + return result.code == 0 -- returns true if the command succeeded +end + ---@function Function to send a notification ---@param message string The message to send ---@param level string|nil The level of the notification (default: "info")