add arbitrary tag selection with *s

This commit is contained in:
2024-12-23 21:46:44 -05:00
parent 6d6568ecfd
commit 5a395de735
2 changed files with 160 additions and 90 deletions

View File

@ -479,16 +479,23 @@ local function sync(package, cb)
return
end
local function log_err(err)
logger:log("error", string.format("failed to update %s; reason: %s", package.id, err))
end
proc.git_resolve_branch(package.url, package.branch, function(err, branch)
if err then
log_err(err)
cb(err)
end
package.branch = branch
if package.exists then
if package.pin then
cb()
return
end
local function log_err(err)
logger:log("error", string.format("failed to update %s; reason: %s", package.id, err))
end
proc.git_rev_parse(package.dir, "HEAD", function(err, before)
if err then
log_err(before)
@ -570,6 +577,7 @@ local function sync(package, cb)
cb(err)
end)
end
end)
end
local function sync_list(list, on_complete)

View File

@ -71,4 +71,66 @@ function proc.git_checkout(dir, branch, commit, cb)
end)
end
function proc.git_resolve_branch(url, branch, cb)
if string.match(branch or "", "*") ~= "*" then
cb(false, branch)
return
end
local buffer = {}
local function cb_output(_, data, _)
if data[1] ~= "" then
buffer = data
end
end
vim.fn.jobstart({
"git",
"ls-remote",
"--tags",
"--sort",
"v:refname",
url
}, {
cwd = nil,
env = { GIT_TERMINAL_PROMPT = 0 },
stdin = nil,
on_stdout = cb_output,
on_stderr = cb_output,
on_exit = function(_, exit_code, _)
if exit_code == 0 then
-- get a list of all versions
local versions = {}
for _, v in pairs(buffer) do
local s, e = string.find(v, "refs/tags/.+")
if not s or not e then
goto continue
end
local tag = string.sub(v, s, e)
tag = string.gsub(tag, "refs/tags/", "")
tag = string.gsub(tag, "%^{}", "")
table.insert(versions, tag)
::continue::
end
-- match the chosen version against all versions
for i = #versions, 1, -1 do
if branch == "*" then
cb(false, versions[i])
return
else
local r = string.match(versions[i], branch)
if r then
cb(false, r)
return
end
end
end
end
end
})
end
return proc