Skip to content

Commit

Permalink
fix(git): properly compare git commits with short refs
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Jan 3, 2023
1 parent 3ad6d95 commit dc9c92a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lua/lazy/manage/checker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function M.fast_check(opts)
plugin._.updates = nil
local info = Git.info(plugin.dir)
local ok, target = pcall(Git.get_target, plugin)
if ok and info and target and info.commit ~= target.commit then
if ok and info and target and not Git.eq(info, target) then
plugin._.updates = { from = info, to = target }
end
end
Expand Down
8 changes: 8 additions & 0 deletions lua/lazy/manage/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ function M.info(repo, details)
end
end

---@param a GitInfo
---@param b GitInfo
function M.eq(a, b)
local ra = a.commit and a.commit:sub(1, 7)
local rb = b.commit and b.commit:sub(1, 7)
return ra == rb
end

function M.head(repo)
return Util.head(repo .. "/.git/HEAD")
end
Expand Down
4 changes: 2 additions & 2 deletions lua/lazy/manage/task/git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ M.log = {
error("no target commit found")
end
assert(target.commit, self.plugin.name .. " " .. target.branch)
if target.commit ~= info.commit then
if not Git.eq(info, target) then
self.plugin._.updates = { from = info, to = target }
end
table.insert(args, info.commit .. ".." .. target.commit)
Expand Down Expand Up @@ -165,7 +165,7 @@ M.checkout = {

-- dont run checkout if target is already reached.
-- unless we just cloned, since then we won't have any data yet
if info.commit == target.commit and info.branch == target.branch then
if Git.eq(info, target) and info.branch == target.branch then
self.plugin._.updated = {
from = info.commit,
to = info.commit,
Expand Down

0 comments on commit dc9c92a

Please sign in to comment.