Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
5a395de735 | |||
6d6568ecfd | |||
d6460d53ed |
37
README.md
37
README.md
@ -1,8 +1,14 @@
|
||||
# dep
|
||||
|
||||
[](LICENSE)
|
||||
[][4]
|
||||
[][8]
|
||||
[][9]
|
||||
|
||||
> This readme is a work in progress.
|
||||
|
||||
A versatile, declarative and correct [neovim][1] package manager in [Lua][2].
|
||||
Originally written for personal use by [luaneko][3].
|
||||
A versatile, declarative and correct [neovim][2] package manager in [Lua][3].
|
||||
Originally written for personal use by [luaneko][4].
|
||||
|
||||
What does that mean?
|
||||
|
||||
@ -10,16 +16,20 @@ What does that mean?
|
||||
2. `declarative` - packages are declared using simple Lua tables.
|
||||
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
|
||||
- [Neovim][1] 0.6+
|
||||
- [Git][4]
|
||||
|
||||
- [Neovim][2] 0.6+
|
||||
- [Git][5]
|
||||
|
||||
## Setup
|
||||
|
||||
1. Create `lua/bootstrap.lua` in your neovim config directory.
|
||||
|
||||
```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"
|
||||
|
||||
if vim.fn.empty(vim.fn.glob(path)) > 0 then
|
||||
@ -306,8 +316,13 @@ require "dep" {
|
||||
|
||||
dep is licensed under the [MIT License](LICENSE).
|
||||
|
||||
[1]: https://neovim.io/
|
||||
[2]: https://www.lua.org/
|
||||
[3]: https://github.com/luaneko
|
||||
[4]: https://git-scm.com/
|
||||
[5]: https://git.squi.bid/nvim
|
||||
[1]: https://chiya.dev/posts/2021-11-27-why-package-manager
|
||||
[2]: https://neovim.io/
|
||||
[3]: https://www.lua.org/
|
||||
[4]: https://github.com/luaneko
|
||||
[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
|
||||
|
189
lua/dep.lua
189
lua/dep.lua
@ -479,97 +479,105 @@ local function sync(package, cb)
|
||||
return
|
||||
end
|
||||
|
||||
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)
|
||||
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)
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
local function sync_list(list, on_complete)
|
||||
@ -662,6 +670,7 @@ local function print_list(cb)
|
||||
line = line + 1
|
||||
end
|
||||
|
||||
print("!! Warning you are using the dev branch of dep, expect bugs")
|
||||
print(string.format("Installed packages (%s):", #packages))
|
||||
indent = 1
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user