Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fallback to cwd when remote can't be found at file path (#61) #62

Merged
merged 1 commit into from
May 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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