Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
92d8f8b9ee |
37
README.md
37
README.md
@ -1,14 +1,8 @@
|
|||||||
# dep
|
# dep
|
||||||
|
|
||||||
[](LICENSE)
|
|
||||||
[][4]
|
|
||||||
[][8]
|
|
||||||
[][9]
|
|
||||||
|
|
||||||
> This readme is a work in progress.
|
> This readme is a work in progress.
|
||||||
|
|
||||||
A versatile, declarative and correct [neovim][2] package manager in [Lua][3].
|
A versatile, declarative and correct [neovim][1] package manager in [Lua][2].
|
||||||
Originally written for personal use by [luaneko][4].
|
Originally written for personal use by [luaneko][3].
|
||||||
|
|
||||||
What does that mean?
|
What does that mean?
|
||||||
|
|
||||||
@ -16,20 +10,16 @@ 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 luaneko's [neovim-configs][10] for an example of how dep can be used in practice.
|
See also squibid's [neovim-configs][5] for an example of how dep can be used in practice.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
- [Neovim][1] 0.6+
|
||||||
- [Neovim][2] 0.6+
|
- [Git][4]
|
||||||
- [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 `chiyadev/dep` on startup
|
-- automatically install `squibid/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
|
||||||
@ -316,13 +306,8 @@ require "dep" {
|
|||||||
|
|
||||||
dep is licensed under the [MIT License](LICENSE).
|
dep is licensed under the [MIT License](LICENSE).
|
||||||
|
|
||||||
[1]: https://chiya.dev/posts/2021-11-27-why-package-manager
|
[1]: https://neovim.io/
|
||||||
[2]: https://neovim.io/
|
[2]: https://www.lua.org/
|
||||||
[3]: https://www.lua.org/
|
[3]: https://github.com/luaneko
|
||||||
[4]: https://github.com/luaneko
|
[4]: https://git-scm.com/
|
||||||
[5]: https://git-scm.com/
|
[5]: https://git.squi.bid/nvim
|
||||||
[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
|
|
||||||
|
183
lua/dep.lua
183
lua/dep.lua
@ -479,105 +479,97 @@ local function sync(package, cb)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local function log_err(err)
|
if package.exists then
|
||||||
logger:log("error", string.format("failed to update %s; reason: %s", package.id, err))
|
if package.pin then
|
||||||
end
|
cb()
|
||||||
|
return
|
||||||
proc.git_resolve_branch(package.url, package.branch, function(err, branch)
|
|
||||||
if err then
|
|
||||||
log_err(err)
|
|
||||||
cb(err)
|
|
||||||
end
|
end
|
||||||
package.branch = branch
|
|
||||||
|
|
||||||
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()
|
end
|
||||||
return
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
proc.git_rev_parse(package.dir, "HEAD", function(err, before)
|
cb(err)
|
||||||
if err then
|
end)
|
||||||
log_err(before)
|
end
|
||||||
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)
|
||||||
@ -670,7 +662,6 @@ 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
|
||||||
|
|
||||||
|
@ -71,66 +71,4 @@ 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
|
||||||
|
Reference in New Issue
Block a user