Skip to content

Commit

Permalink
Ensure dashboard displays even when there's no remote_url (#10)
Browse files Browse the repository at this point in the history
* Return cwd if unable to extract remote_url

When remote `origin` doesn't exist or no remote available. This ensure
dashboard displays instead of showing up blank

* Adjust the remote url pattern matching expression

* Remove a redundant matching pattern

* Fix: nvim_get_option is deprecated

* Revert "Remove a redundant matching pattern"

* Display dashboard even when there is no commit instead of showing blank page
  • Loading branch information
csessh authored Oct 26, 2024
1 parent e44e44e commit 90d262c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lua/git-dashboard-nvim/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Git.get_repo_with_owner = function()
end

Git._parse_repo_and_owner = function(remote_url)
return remote_url:match(".*%..*[:/]([^/]+/[^/.]+)")
or remote_url:match(".*%..*[:/]([^/]+/[^/.]+).git")
return remote_url:match(".*%..*[:/]([^/]+/[^/]+).git")
or remote_url:match(".*%..*[:/]([^/]+/[^/.]+)")
or ""
end

Expand Down
6 changes: 1 addition & 5 deletions lua/git-dashboard-nvim/heatmap/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Heatmap.generate_heatmap = function(config)
local repo_with_owner = Git.get_repo_with_owner() -- owner/repo

if repo_with_owner == "" or not repo_with_owner then
return ""
repo_with_owner = vim.fn.getcwd()
end

local author = config.author
Expand All @@ -25,10 +25,6 @@ Heatmap.generate_heatmap = function(config)

local commits = Git.get_commit_dates(author, config.branch)

if #commits == 0 then
return ""
end

local current_date_info = utils.current_date_info()

local base_heatmap = HeatmapUtils.generate_base_heatmap(commits, current_date_info)
Expand Down
2 changes: 1 addition & 1 deletion lua/git-dashboard-nvim/heatmap/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ HeatmapUtils.generate_ascii_heatmap = function(

-- center vertically ascii heatmap
if config.centered then
local lines = vim.api.nvim_get_option("lines")
local lines = vim.api.nvim_get_option_value("lines", {})
local ascii_heatmap_lines = vim.split(ascii_heatmap, "\n")
local ascii_heatmap_lines_count = #ascii_heatmap_lines
local padding = math.floor((lines - ascii_heatmap_lines_count) / 2)
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/git_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ describe("git", function()
assert(repo_with_owner == "juansalvatore/git-dashboard-nvim")
end)

it("should parse repo with extra dot in name", function()
local git = require("git-dashboard-nvim.git")
local repo_with_owner = git._parse_repo_and_owner("[email protected]:csessh/.dotfiles.git")

assert(repo_with_owner ~= nil)
assert(repo_with_owner == "csessh/.dotfiles")
end)

it("should parse repo with extra dot in name", function()
local git = require("git-dashboard-nvim.git")
local repo_with_owner = git._parse_repo_and_owner("[email protected]:csessh/test.nvim.git")

assert(repo_with_owner ~= nil)
assert(repo_with_owner == "csessh/test.nvim")
end)

it("should parse repo with owner from github ssh url without .git", function()
local git = require("git-dashboard-nvim.git")
local repo_with_owner =
Expand Down

0 comments on commit 90d262c

Please sign in to comment.