3 Commits
master ... dev

Author SHA1 Message Date
5a395de735 add arbitrary tag selection with *s 2024-12-23 21:46:44 -05:00
6d6568ecfd Merge branch 'master' into dev 2024-12-23 21:42:38 -05:00
d6460d53ed notify user that this is a development version 2023-04-29 12:18:06 -04:00
3 changed files with 187 additions and 101 deletions

View File

@ -1,8 +1,14 @@
# dep # dep
[![License](https://img.shields.io/github/license/chiyadev/dep)](LICENSE)
[![Maintainer](https://img.shields.io/badge/maintainer-luaneko-pink)][4]
[![Issues](https://img.shields.io/github/issues/chiyadev/dep.svg)][8]
[![Contributors](https://img.shields.io/github/contributors/chiyadev/dep.svg)][9]
> This readme is a work in progress. > This readme is a work in progress.
A versatile, declarative and correct [neovim][1] package manager in [Lua][2]. A versatile, declarative and correct [neovim][2] package manager in [Lua][3].
Originally written for personal use by [luaneko][3]. Originally written for personal use by [luaneko][4].
What does that mean? What does that mean?
@ -10,16 +16,20 @@ What does that mean?
2. `declarative` - packages are declared using simple Lua tables. 2. `declarative` - packages are declared using simple Lua tables.
3. `correct` - packages are always loaded in a correct and consistent order. 3. `correct` - packages are always loaded in a correct and consistent order.
See also squibid's [neovim-configs][5] for an example of how dep can be used in practice. See also luaneko's [neovim-configs][10] for an example of how dep can be used in practice.
## Requirements ## Requirements
- [Neovim][1] 0.6+
- [Git][4] - [Neovim][2] 0.6+
- [Git][5]
## Setup ## Setup
1. Create `lua/bootstrap.lua` in your neovim config directory. 1. Create `lua/bootstrap.lua` in your neovim config directory.
```lua ```lua
-- ~/.config/nvim/lua/bootstrap.lua: -- ~/.config/nvim/lua/bootstrap.lua:
-- automatically install `squibid/dep` on startup -- automatically install `chiyadev/dep` on startup
local path = vim.fn.stdpath("data") .. "/site/pack/deps/opt/dep" local path = vim.fn.stdpath("data") .. "/site/pack/deps/opt/dep"
if vim.fn.empty(vim.fn.glob(path)) > 0 then if vim.fn.empty(vim.fn.glob(path)) > 0 then
@ -306,8 +316,13 @@ require "dep" {
dep is licensed under the [MIT License](LICENSE). dep is licensed under the [MIT License](LICENSE).
[1]: https://neovim.io/ [1]: https://chiya.dev/posts/2021-11-27-why-package-manager
[2]: https://www.lua.org/ [2]: https://neovim.io/
[3]: https://github.com/luaneko [3]: https://www.lua.org/
[4]: https://git-scm.com/ [4]: https://github.com/luaneko
[5]: https://git.squi.bid/nvim [5]: https://git-scm.com/
[6]: https://github.com/nvim-telescope/telescope.nvim
[7]: https://github.com/tpope/vim-fugitive
[8]: https://GitHub.com/chiyadev/dep/issues
[9]: https://github.com/chiyadev/dep/graphs/contributors
[10]: https://github.com/luaneko/neovim-config

View File

@ -479,97 +479,105 @@ local function sync(package, cb)
return return
end end
if package.exists then local function log_err(err)
if package.pin then logger:log("error", string.format("failed to update %s; reason: %s", package.id, err))
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)
cb(err)
else
if package.commit then
proc.git_checkout(package.dir, package.branch, package.commit, function(err, message)
if err then
log_err(message)
cb(err)
else
proc.git_rev_parse(package.dir, package.commit, function(err, after)
if err then
log_err(after)
cb(err)
elseif before == after then
logger:log("skip", string.format("skipped %s", package.id))
cb(err)
else
mark_reconfigure(package)
logger:log("update", string.format("updated %s; %s -> %s", package.id, before, after))
end
end)
end
end)
else
proc.git_fetch(package.dir, "origin", package.branch or "HEAD", function(err, message)
if err then
log_err(message)
cb(err)
else
proc.git_rev_parse(package.dir, "FETCH_HEAD", function(err, after)
if err then
log_err(after)
cb(err)
elseif before == after then
logger:log("skip", string.format("skipped %s", package.id))
cb(err)
else
proc.git_reset(package.dir, after, function(err, message)
if err then
log_err(message)
else
mark_reconfigure(package)
logger:log("update", string.format("updated %s; %s -> %s", package.id, before, after))
end
cb(err)
end)
end
end)
end
end)
end
end
end)
else
proc.git_clone(package.dir, package.url, package.branch, function(err, message)
if err then
logger:log("error", string.format("failed to install %s; reason: %s", package.id, message))
else
if package.commit then
proc.git_checkout(package.dir, package.branch, package.commit, function(err, message)
if err then
logger:log("error", string.format("failed to checkout %s; reason: %s", package.id, message))
else
package.exists = true
mark_reconfigure(package)
logger:log("install", string.format("installed %s", package.id))
end
end)
else
package.exists = true
mark_reconfigure(package)
logger:log("install", string.format("installed %s", package.id))
end
end
cb(err)
end)
end 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
proc.git_rev_parse(package.dir, "HEAD", function(err, before)
if err then
log_err(before)
cb(err)
else
if package.commit then
proc.git_checkout(package.dir, package.branch, package.commit, function(err, message)
if err then
log_err(message)
cb(err)
else
proc.git_rev_parse(package.dir, package.commit, function(err, after)
if err then
log_err(after)
cb(err)
elseif before == after then
logger:log("skip", string.format("skipped %s", package.id))
cb(err)
else
mark_reconfigure(package)
logger:log("update", string.format("updated %s; %s -> %s", package.id, before, after))
end
end)
end
end)
else
proc.git_fetch(package.dir, "origin", package.branch or "HEAD", function(err, message)
if err then
log_err(message)
cb(err)
else
proc.git_rev_parse(package.dir, "FETCH_HEAD", function(err, after)
if err then
log_err(after)
cb(err)
elseif before == after then
logger:log("skip", string.format("skipped %s", package.id))
cb(err)
else
proc.git_reset(package.dir, after, function(err, message)
if err then
log_err(message)
else
mark_reconfigure(package)
logger:log("update", string.format("updated %s; %s -> %s", package.id, before, after))
end
cb(err)
end)
end
end)
end
end)
end
end
end)
else
proc.git_clone(package.dir, package.url, package.branch, function(err, message)
if err then
logger:log("error", string.format("failed to install %s; reason: %s", package.id, message))
else
if package.commit then
proc.git_checkout(package.dir, package.branch, package.commit, function(err, message)
if err then
logger:log("error", string.format("failed to checkout %s; reason: %s", package.id, message))
else
package.exists = true
mark_reconfigure(package)
logger:log("install", string.format("installed %s", package.id))
end
end)
else
package.exists = true
mark_reconfigure(package)
logger:log("install", string.format("installed %s", package.id))
end
end
cb(err)
end)
end
end)
end end
local function sync_list(list, on_complete) local function sync_list(list, on_complete)
@ -662,6 +670,7 @@ local function print_list(cb)
line = line + 1 line = line + 1
end end
print("!! Warning you are using the dev branch of dep, expect bugs")
print(string.format("Installed packages (%s):", #packages)) print(string.format("Installed packages (%s):", #packages))
indent = 1 indent = 1

View File

@ -71,4 +71,66 @@ function proc.git_checkout(dir, branch, commit, cb)
end) end)
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 return proc