Skip to content

Commit

Permalink
fix: fallback to cwd when remote can't be found at file path (#61) (#62)
Browse files Browse the repository at this point in the history
Fixes #61
  • Loading branch information
sportshead authored May 8, 2024
1 parent ea54382 commit cf6ed6b
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lua/gx/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ local function parse_git_output(result)
end
end

function M.get_remote_url(remotes, push, owner, repo)
local notifier = require("gx.notifier")

local function discover_remote(remotes, push, path)
local url = nil
local path = vim.fn.expand("%:p:h")
for _, remote in ipairs(remotes) do
local args = { "-C", path, "remote", "get-url", remote }
if push then
Expand All @@ -30,10 +27,21 @@ function M.get_remote_url(remotes, push, owner, repo)
if exit_code == 0 then
url = parse_git_output(result)
if url then
break
return url
end
end
end
return url
end

function M.get_remote_url(remotes, push, owner, repo)
local notifier = require("gx.notifier")

local path = vim.fn.expand("%:p:h")
local url = discover_remote(remotes, push, path)
if not url then
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
url = "https://github.com/foo/bar"
Expand Down

0 comments on commit cf6ed6b

Please sign in to comment.