feat(hunks): stage selected hunks
This commit is contained in:
@@ -359,6 +359,49 @@ t.test("toggle_stage stages only the hunk under the cursor", function()
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("toggle_stage_range stages every hunk in the selected lines", function()
|
||||
local dir, buf = setup("a\nb\nc\nd\ne\n", "A\nb\nC\nd\nE\n")
|
||||
hunks.toggle_stage_range(1, 3, buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 2
|
||||
end, "the selected hunks to land in the index")
|
||||
t.eq(
|
||||
h.git(dir, "show", ":0:a.txt").stdout,
|
||||
"A\nb\nC\nd\ne",
|
||||
"only the hunks touched by the selection are staged"
|
||||
)
|
||||
end)
|
||||
|
||||
t.test(
|
||||
"toggle_stage_range stages a hunk when selection starts inside it",
|
||||
function()
|
||||
local dir, buf = setup("a\nb\nc\n", "A\nB\nc\n")
|
||||
hunks.toggle_stage_range(2, 2, buf)
|
||||
t.wait_for(function()
|
||||
return h.git(dir, "diff", "--cached", "--name-only").stdout ~= ""
|
||||
end, "the touched hunk to land in the index")
|
||||
t.eq(h.git(dir, "show", ":0:a.txt").stdout, "A\nB\nc")
|
||||
end
|
||||
)
|
||||
|
||||
t.test("toggle_stage_range unstages selected staged hunks", function()
|
||||
local dir, buf = setup("a\nb\nc\nd\ne\n", "A\nb\nC\nd\nE\n")
|
||||
hunks.toggle_stage_range(1, 5, buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 3
|
||||
end, "all hunks to land in the index")
|
||||
|
||||
hunks.toggle_stage_range(1, 3, buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 1
|
||||
end, "the selected staged hunks to be unstaged")
|
||||
t.eq(
|
||||
h.git(dir, "show", ":0:a.txt").stdout,
|
||||
"a\nb\nc\nd\nE",
|
||||
"only the unselected staged hunk remains in the index"
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("toggle_stage stages a whole-file change with no context", function()
|
||||
local dir, buf = setup("a\nb\nc\n", "x\ny\nz\n")
|
||||
vim.api.nvim_win_set_cursor(0, { 2, 0 })
|
||||
|
||||
Reference in New Issue
Block a user