From b01db725a001e4215f363159fc04727f6fde0a1c Mon Sep 17 00:00:00 2001 From: Steven Xu Date: Sat, 30 Nov 2024 21:42:12 +1100 Subject: [PATCH] fix: check `type(owner) == "string"` to avoid `https://github.com/foo/bar`, fixes #71 (#74) --- lua/gx/git.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lua/gx/git.lua b/lua/gx/git.lua index c5af180..7c867a1 100644 --- a/lua/gx/git.lua +++ b/lua/gx/git.lua @@ -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)