Skip to content

Commit

Permalink
feat(git): show error for local changes during check/update
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 10, 2023
1 parent 067544c commit 43e9165
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lua/lazy/manage/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function M.update(opts)
"git.origin",
"git.branch",
"git.fetch",
"git.status",
{ "git.checkout", lockfile = opts.lockfile },
"plugin.docs",
"wait",
Expand Down Expand Up @@ -132,6 +133,7 @@ function M.check(opts)
pipeline = {
{ "git.origin", check = true },
"git.fetch",
"git.status",
"wait",
{ "git.log", check = true },
},
Expand Down
27 changes: 27 additions & 0 deletions lua/lazy/manage/task/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,33 @@ M.origin = {
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
M.fetch = {
skip = function(plugin)
Expand Down

0 comments on commit 43e9165

Please sign in to comment.