feat(git): show error for local changes during check/update

This commit is contained in:
Folke Lemaitre 2023-10-10 11:41:32 +02:00
parent 067544c74a
commit 43e9165994
No known key found for this signature in database
GPG Key ID: 41F8B1FBACAE2040
2 changed files with 29 additions and 0 deletions

View File

@ -103,6 +103,7 @@ function M.update(opts)
"git.origin", "git.origin",
"git.branch", "git.branch",
"git.fetch", "git.fetch",
"git.status",
{ "git.checkout", lockfile = opts.lockfile }, { "git.checkout", lockfile = opts.lockfile },
"plugin.docs", "plugin.docs",
"wait", "wait",
@ -132,6 +133,7 @@ function M.check(opts)
pipeline = { pipeline = {
{ "git.origin", check = true }, { "git.origin", check = true },
"git.fetch", "git.fetch",
"git.status",
"wait", "wait",
{ "git.log", check = true }, { "git.log", check = true },
}, },

View File

@ -156,6 +156,33 @@ M.origin = {
end, end,
} }
M.status = {
skip = function(plugin)
return not plugin._.installed or plugin._.is_local
end,
run = function(self)
self:spawn("git", {
args = { "ls-files", "-d", "-m" },
cwd = self.plugin.dir,
on_exit = function(ok, output)
if ok then
local lines = vim.split(output, "\n")
lines = vim.tbl_filter(function(line)
return line ~= ""
end, lines)
if #lines > 0 then
self.error = "You have local changes in `" .. self.plugin.dir .. "`:\n"
for _, line in ipairs(lines) do
self.error = self.error .. " * " .. line .. "\n"
end
self.error = self.error .. "Please remove them to update."
end
end
end,
})
end,
}
-- fetches all needed origin branches -- fetches all needed origin branches
M.fetch = { M.fetch = {
skip = function(plugin) skip = function(plugin)