commit ef1c6bfeb41e2e6b7798d3463f02aa45ae20c498
parent eab6f78b9771e437322b2c20de6b1a13b0eaf0f6
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Mon,  2 May 2022 19:13:18 +0200

Update paq and fix bug

Diffstat:
M.config/nvim/lua/paq.lua | 31++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/.config/nvim/lua/paq.lua b/.config/nvim/lua/paq.lua @@ -1,6 +1,6 @@ -- This file is a modified version of paq-nvim (https://github.com/savq/paq-nvim), -- which has the following notice. --- Last update: 2022-01-09 (commit 6caab059bc15cc61afc7aa7e0515ee06eb550bcf) +-- Last update: 2022-05-02 (commit c9451521e6e334b3651092f882cfa128d38a99cb) -- MIT License -- @@ -80,14 +80,14 @@ local function new_counter() end) end -local function call_proc(process, args, cwd, cb) +local function call_proc(process, args, cwd, cb, print_stdout) local log = uv.fs_open(LOGFILE, "a+", 0x1A4) local stderr = uv.new_pipe(false) stderr:open(log) local handle, pid handle, pid = uv.spawn( process, - { args = args, cwd = cwd, stdio = { nil, nil, stderr }, env = env }, + { args = args, cwd = cwd, stdio = { nil, print_stdout and stderr, stderr }, env = env }, vim.schedule_wrap(function(code) uv.fs_close(log) stderr:close() @@ -100,6 +100,12 @@ local function call_proc(process, args, cwd, cb) end end +local function log(message) + local log = uv.fs_open(LOGFILE, "a+", 0x1A4) + uv.fs_write(log, message .. '\n') + uv.fs_close(log) +end + local function run_hook(pkg, counter, sync) local t = type(pkg.run) if t == "function" then @@ -157,15 +163,20 @@ local function get_git_hash(dir) end local function pull(pkg, counter, sync) - local hash = get_git_hash(pkg.dir) + local prev_hash = get_git_hash(pkg.dir) call_proc("git", { "pull", "--recurse-submodules", "--update-shallow" }, pkg.dir, function(ok) if not ok then counter(pkg.name, "err", sync) - elseif get_git_hash(pkg.dir) ~= hash then - pkg.status = "updated" - return pkg.run and run_hook(pkg, counter, sync) or counter(pkg.name, "ok", sync) else - counter(pkg.name, "nop", sync) + local cur_hash = get_git_hash(pkg.dir) + if cur_hash ~= prev_hash then + log(pkg.name .. " updating...") + call_proc("git", { "log", "--pretty=format:* %s", prev_hash .. ".." .. cur_hash }, pkg.dir, function(ok) end, true) + pkg.status = "updated" + return pkg.run and run_hook(pkg, counter, sync) or counter(pkg.name, "ok", sync) + else + counter(pkg.name, "nop", sync) + end end end) end @@ -173,7 +184,9 @@ end local function clone_or_pull(pkg, counter) if pkg.exists and not pkg.pin then pull(pkg, counter, "update") - else + -- Oscar: add condition to fix pinned packages bug + elseif not pkg.exists then + -- end clone(pkg, counter, "install") end end