Skip to content

Commit

Permalink
fix: check type(owner) == "string" to avoid https://github.com/foo…
Browse files Browse the repository at this point in the history
…/bar`, fixes #71
  • Loading branch information
stevenxxiu committed Nov 30, 2024
1 parent cc70d11 commit a12588e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lua/gx/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,19 @@ function M.get_remote_url(remotes, push, owner, repo)
url = discover_remote(remotes, push, vim.loop.cwd())
end

if not url and (owner ~= "" and repo ~= "") then -- fallback to github if owner and repo are present
local has_owner = type(owner) == "string" and owner ~= ""
local has_repo = type(repo) == "string" and repo ~= ""
if not url and has_owner and has_repo then
-- fallback to github if owner and repo are present
url = "https://github.com/foo/bar"
end
if not url then
notifier.warn("No remote git repository found!")
return
end
if type(owner) == "string" and owner ~= "" then
if has_owner then
local domain, repository = url:match("^https?://([^/]+)/[^/]+/([^/]*)")
if repo ~= "" then
if has_repo then
repository = repo
end
url = string.format("https://%s/%s/%s", domain, owner, repository)
Expand Down

0 comments on commit a12588e

Please sign in to comment.