Skip to content

Commit 72c0dc9

Browse files
authored
fix(git): local plugin fixes (#1624)
## Description As I described in #1512 (comment), this makes it so that local plugins will only show as needing updates if the local branch is behind the upstream branch. This is done by checking the output of the `git log` command, and only setting `plugin._.updates` if the output is not empty. This seems to solve my issue where local plugins with unpushed changes always show as needing updates, but if there's a easier/better way of doing it then please feel free to edit/close this. Or if you don't agree that the current behaviour is a bug, then that's also fine - it's not a big deal and I can easily just ignore the "updates available" notice. I also came across a minor issue where the plugin diff view (press `d`) compares the wrong commits for local plugins, because [lua/lazy/view/init.lua](https://github.com/folke/lazy.nvim/blob/c771cf4928d1a1428ac7461658ab2916ed48adf5/lua/lazy/view/init.lua#L268) always uses `get_target`. I fixed this by moving `get_local_target` into `get_target` - I think this is simpler and more straightforward than the alternative of adding a ternary everywhere `get_target` is called. This second bugfix is a very small change, so I've just included it here, but I'm happy to make a second PR if you'd like. ## Related Issue(s) Related PR: #1512
1 parent c771cf4 commit 72c0dc9

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

lua/lazy/manage/checker.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ end
3535
function M.fast_check(opts)
3636
opts = opts or {}
3737
for _, plugin in pairs(Config.plugins) do
38-
if not plugin.pin and not plugin.dev and plugin._.installed then
38+
-- don't check local plugins here, since we mark them as needing updates
39+
-- only if local is behind upstream (if the git log task gives no output)
40+
if plugin._.installed and not (plugin.pin or plugin._.is_local) then
3941
plugin._.updates = nil
4042
local info = Git.info(plugin.dir)
4143
local ok, target = pcall(Git.get_target, plugin)

lua/lazy/manage/git.lua

+6-9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ end
116116
---@param plugin LazyPlugin
117117
---@return GitInfo?
118118
function M.get_target(plugin)
119+
if plugin._.is_local then
120+
local info = M.info(plugin.dir)
121+
local branch = assert(info and info.branch or M.get_branch(plugin))
122+
return { branch = branch, commit = M.get_commit(plugin.dir, branch, true) }
123+
end
124+
119125
local branch = assert(M.get_branch(plugin))
120126

121127
if plugin.commit then
@@ -144,15 +150,6 @@ function M.get_target(plugin)
144150
}
145151
end
146152
end
147-
---@diagnostic disable-next-line: return-type-mismatch
148-
return { branch = branch, commit = M.get_commit(plugin.dir, branch, true) }
149-
end
150-
151-
---@param plugin LazyPlugin
152-
---@return GitInfo?
153-
function M.get_local_target(plugin)
154-
local info = M.info(plugin.dir)
155-
local branch = assert(info and info.branch or M.get_branch(plugin))
156153
return { branch = branch, commit = M.get_commit(plugin.dir, branch, true) }
157154
end
158155

lua/lazy/manage/task/git.lua

+21-9
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,31 @@ M.log = {
3232
"--no-show-signature",
3333
}
3434

35+
local info, target
36+
3537
if opts.updated then
3638
table.insert(args, self.plugin._.updated.from .. ".." .. (self.plugin._.updated.to or "HEAD"))
3739
elseif opts.check then
38-
local info = assert(Git.info(self.plugin.dir))
39-
local target = assert(self.plugin._.is_local and Git.get_local_target(self.plugin) or Git.get_target(self.plugin))
40+
info = assert(Git.info(self.plugin.dir))
41+
target = assert(Git.get_target(self.plugin))
4042
if not target.commit then
4143
for k, v in pairs(target) do
4244
error(k .. " '" .. v .. "' not found")
4345
end
4446
error("no target commit found")
4547
end
4648
assert(target.commit, self.plugin.name .. " " .. target.branch)
47-
if Git.eq(info, target) then
48-
if Config.options.checker.check_pinned then
49-
local last_commit = Git.get_commit(self.plugin.dir, target.branch, true)
50-
if not Git.eq(info, { commit = last_commit }) then
51-
self.plugin._.outdated = true
49+
if not self.plugin._.is_local then
50+
if Git.eq(info, target) then
51+
if Config.options.checker.check_pinned then
52+
local last_commit = Git.get_commit(self.plugin.dir, target.branch, true)
53+
if not Git.eq(info, { commit = last_commit }) then
54+
self.plugin._.outdated = true
55+
end
5256
end
57+
else
58+
self.plugin._.updates = { from = info, to = target }
5359
end
54-
else
55-
self.plugin._.updates = { from = info, to = target }
5660
end
5761
table.insert(args, info.commit .. ".." .. target.commit)
5862
else
@@ -63,6 +67,14 @@ M.log = {
6367
args = args,
6468
cwd = self.plugin.dir,
6569
})
70+
71+
-- for local plugins, mark as needing updates only if local is
72+
-- behind upstream, i.e. if git log gave no output
73+
if opts.check and self.plugin._.is_local then
74+
if not vim.tbl_isempty(self:get_log()) then
75+
self.plugin._.updates = { from = info, to = target }
76+
end
77+
end
6678
end,
6779
}
6880

0 commit comments

Comments
 (0)