Skip to content

Commit

Permalink
fix: git repo detection (#15)
Browse files Browse the repository at this point in the history
* fix: git repo detection

* fix: spelling and debug
  • Loading branch information
sudo-tee authored Jan 2, 2025
1 parent e178902 commit c54fa2f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions lua/git-dashboard-nvim/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,15 @@ Git = {}

---@return boolean
Git.is_git_repo = function()
local handle = io.popen("git status &>" .. null .. "; echo $?")
local handle = io.popen("git rev-parse --is-inside-work-tree 2>" .. null)
if not handle then
return false
end

local exit_code = handle:read("*a")
local result = vim.trim(handle:read("*a"))
handle:close()

-- git status command returns
-- 0 exit code if it is a git repository,
-- 128 exit code otherwise
return tonumber(exit_code) == 0
return result == "true"
end

---@return string
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/git_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe("git", function()
assert(commits ~= nil)
end)

it("should return git status exit code 0", function()
it("should return true if in a git repo", function()
local git = require("git-dashboard-nvim.git")
local is_git_repo = git.is_git_repo()

Expand Down

0 comments on commit c54fa2f

Please sign in to comment.