fix conflict

This commit is contained in:
arthur 2024-07-10 23:51:28 +08:00
parent 0cb11e07da
commit ed8e73b4aa

View file

@ -179,20 +179,15 @@ function M.get_url(remote)
for _, pattern in ipairs(M.remote_patterns) do for _, pattern in ipairs(M.remote_patterns) do
ret = ret:gsub(pattern[1], pattern[2]) ret = ret:gsub(pattern[1], pattern[2])
end end
return ret:find("https://") == 1 and ret or ("https://%s"):format(ret)
end
function M.browse()
local lines = require("lazy.manage.process").exec({ "git", "remote", "-v" })
local remotes = {} ---@type {name:string, url:string}[]
--- @param url string --- @param url string
local function getRemoteURLFromSSH(url) local function getRemoteURLFromSSH(url)
local transformedUrl = ""
local SSHConfigPath = vim.env.HOME .. "/.ssh/config" local SSHConfigPath = vim.env.HOME .. "/.ssh/config"
-- Return the original URL if SSH config is not found or not readable -- Return the original URL if SSH config is not found or not readable
if not vim.uv.fs_access(SSHConfigPath, "R") then if not vim.uv.fs_access(SSHConfigPath, "R") then
return url return
end end
-- Handle SSH config remotes -- Handle SSH config remotes
@ -200,7 +195,7 @@ function M.browse()
-- Return the original URL if unable to read SSH config file -- Return the original URL if unable to read SSH config file
if not file then if not file then
return url return
end end
local currentHost, hostGroup = "", {} local currentHost, hostGroup = "", {}
@ -216,7 +211,7 @@ function M.browse()
-- If the username is specified, we do not need to replace it; otherwise, replace the username with "git". -- If the username is specified, we do not need to replace it; otherwise, replace the username with "git".
local searchString = hostGroup[currentHost].User and currentHost .. ":" or "git@" .. currentHost .. ":" local searchString = hostGroup[currentHost].User and currentHost .. ":" or "git@" .. currentHost .. ":"
local destinationURL = string.format("https://%s/", hostGroup[currentHost].HostName) local destinationURL = string.format("https://%s/", hostGroup[currentHost].HostName)
url = url:gsub(searchString, destinationURL):gsub("%.git$", "") transformedUrl = url:gsub(searchString, destinationURL):gsub("%.git$", "")
break break
end end
-- Setup group of host -- Setup group of host
@ -229,17 +224,22 @@ function M.browse()
end end
file:close() file:close()
return url return transformedUrl
end end
return ret:find("https://") == 1 and ret or getRemoteURLFromSSH(ret) or ("https://%s"):format(ret)
end
function M.browse()
local lines = require("lazy.manage.process").exec({ "git", "remote", "-v" })
local remotes = {} ---@type {name:string, url:string}[]
for _, line in ipairs(lines) do for _, line in ipairs(lines) do
local name, remote = line:match("(%S+)%s+(%S+)%s+%(fetch%)") local name, remote = line:match("(%S+)%s+(%S+)%s+%(fetch%)")
if name and remote then if name and remote then
local url = M.get_url(remote) local url = M.get_url(remote)
if url then if url then
table.insert(remotes, { name = name, url = url }) table.insert(remotes, { name = name, url = url })
else
table.insert(remotes, { name = name, url = getRemoteURLFromSSH(remote) })
end end
end end
end end