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)