Skip to content

Commit 6a60fdf

Browse files
author
silviu
committed
fix: Reverse hash order for consistent diff logic and update test cases
1 parent 2177e42 commit 6a60fdf

4 files changed

Lines changed: 12 additions & 11 deletions

File tree

lua/gitlogdiff/actions.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ function M.show_selected(hashes)
1111
return
1212
end
1313

14-
local ordered = vim.deepcopy(hashes)
15-
table.sort(ordered, function(a, b)
16-
return a < b
17-
end)
14+
local ordered = {}
15+
for i = #hashes, 1, -1 do
16+
table.insert(ordered, hashes[i])
17+
end
1818

1919
if #ordered == 1 then
2020
diffview_open({ ordered[1] .. "^.." .. ordered[1] })
2121
return
2222
end
2323

24-
diffview_open(ordered)
24+
diffview_open({ ordered[1] .. ".." .. ordered[#ordered] })
2525
end
2626

2727
return M

lua/gitlogdiff/ui.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ end
6969

7070
function M.get_selected_hashes()
7171
local hashes = {}
72-
for i, ok in pairs(M.state.selected) do
73-
if ok then
72+
for i = 1, #M.state.commits do
73+
if M.state.selected[i] then
7474
local h = M.state.commits[i]:match("^(%w+)")
75-
table.insert(hashes, h)
75+
if h then
76+
table.insert(hashes, h)
77+
end
7678
end
7779
end
7880
return hashes

tests/test_init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ T["actions"]["show_selected() diffs two commits correctly"] = function()
3434
table.insert(cmds, cmd)
3535
end
3636

37-
actions.show_selected({ "def5678", "abc1234" })
38-
MiniTest.expect.equality(cmds[1], "DiffviewOpen abc1234 def5678")
37+
actions.show_selected({ "newer123", "older456" })
38+
MiniTest.expect.equality(cmds[1], "DiffviewOpen older456..newer123")
3939
end
4040

4141
T["log"] = MiniTest.new_set()

tests/test_ui.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ T["get_selected_hashes() works"] = function()
4343
ui.state.selected[3] = true
4444

4545
local hashes = ui.get_selected_hashes()
46-
table.sort(hashes)
4746
MiniTest.expect.equality(hashes, { "abc1234", "ghi9012" })
4847
end
4948

0 commit comments

Comments
 (0)