Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: git repo detection #15

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lua/git-dashboard-nvim/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ 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

print(Git.is_git_repo())

---@return string
Git.get_repo_with_owner = function()
local handle = io.popen("git remote get-url origin 2>" .. null)
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 tre if in git repo", function()
local git = require("git-dashboard-nvim.git")
local is_git_repo = git.is_git_repo()

Expand Down