chore: apply formatting
This commit is contained in:
@@ -548,8 +548,7 @@ t.test("streaming :G fetch (no bang) does not open a window", function()
|
||||
local before = #vim.api.nvim_tabpage_list_wins(0)
|
||||
cmd.run({ "fetch" })
|
||||
t.wait_for(function()
|
||||
return has_status(calls, "failed")
|
||||
or has_status(calls, "success")
|
||||
return has_status(calls, "failed") or has_status(calls, "success")
|
||||
end, "streaming job to terminate", 5000)
|
||||
t.eq(#vim.api.nvim_tabpage_list_wins(0), before, "no new window")
|
||||
t.falsy(find_preview_win(), "no preview window")
|
||||
|
||||
+55
-47
@@ -29,9 +29,11 @@ end
|
||||
local function sign_marks(buf)
|
||||
local ns = vim.api.nvim_get_namespaces()["ow.git.hunks"]
|
||||
local out = {}
|
||||
for _, m in ipairs(vim.api.nvim_buf_get_extmarks(buf, ns, 0, -1, {
|
||||
details = true,
|
||||
})) do
|
||||
for _, m in
|
||||
ipairs(vim.api.nvim_buf_get_extmarks(buf, ns, 0, -1, {
|
||||
details = true,
|
||||
}))
|
||||
do
|
||||
local d = assert(m[4])
|
||||
table.insert(out, {
|
||||
row = m[2],
|
||||
@@ -167,7 +169,10 @@ t.test("overlay: change hunk shows deletion and addition", function()
|
||||
t.eq(add_d.line_hl_group, "GitHunkAddLine")
|
||||
virt_d = assert(virt_d, "the deletion should render as virtual lines")
|
||||
local piece = assert(assert(assert(virt_d.virt_lines)[1])[1])
|
||||
t.truthy(vim.startswith(piece[1], "b"), "deleted line shows the old content")
|
||||
t.truthy(
|
||||
vim.startswith(piece[1], "b"),
|
||||
"deleted line shows the old content"
|
||||
)
|
||||
t.eq(piece[2], "GitHunkDeleteLine")
|
||||
end)
|
||||
|
||||
@@ -197,11 +202,8 @@ t.test("overlay: add hunk highlights the added lines", function()
|
||||
end)
|
||||
|
||||
t.test("overlay: deleted lines are treesitter-highlighted", function()
|
||||
local _, buf = setup(
|
||||
"-- a note\nlocal x = 1\nlocal y = 2\n",
|
||||
"local y = 2\n",
|
||||
"a.lua"
|
||||
)
|
||||
local _, buf =
|
||||
setup("-- a note\nlocal x = 1\nlocal y = 2\n", "local y = 2\n", "a.lua")
|
||||
t.truthy(
|
||||
pcall(vim.treesitter.start, buf, "lua"),
|
||||
"the lua parser should be available"
|
||||
@@ -437,22 +439,25 @@ t.test("toggle_stage unstages one of two adjacent staged hunks", function()
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("toggle_stage refreshes the gutter when status stays modified", function()
|
||||
local _, buf = setup("a\nb\nc\nd\ne\n", "A\nb\nC\nd\nE\n")
|
||||
t.eq(#assert(hunks.state(buf)).hunks, 3)
|
||||
t.test(
|
||||
"toggle_stage refreshes the gutter when status stays modified",
|
||||
function()
|
||||
local _, buf = setup("a\nb\nc\nd\ne\n", "A\nb\nC\nd\nE\n")
|
||||
t.eq(#assert(hunks.state(buf)).hunks, 3)
|
||||
|
||||
vim.api.nvim_win_set_cursor(0, { 1, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 2
|
||||
end, "gutter to drop the first staged hunk")
|
||||
vim.api.nvim_win_set_cursor(0, { 1, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 2
|
||||
end, "gutter to drop the first staged hunk")
|
||||
|
||||
vim.api.nvim_win_set_cursor(0, { 3, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 1
|
||||
end, "gutter to drop the middle staged hunk")
|
||||
end)
|
||||
vim.api.nvim_win_set_cursor(0, { 3, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 1
|
||||
end, "gutter to drop the middle staged hunk")
|
||||
end
|
||||
)
|
||||
|
||||
t.test("staged hunks show with the staged highlight", function()
|
||||
local _, buf = setup("a\nb\nc\n", "a\nB\nc\n")
|
||||
@@ -499,32 +504,35 @@ t.test("toggle_stage toggles a staged hunk back to unstaged", function()
|
||||
})
|
||||
end)
|
||||
|
||||
t.test("toggle_stage unstages correctly when buffer lines are shifted", function()
|
||||
local dir, buf = setup("a\nb\nc\n", "a\nb\nC\n")
|
||||
vim.api.nvim_win_set_cursor(0, { 3, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 1
|
||||
end, "the line-3 change to be staged")
|
||||
t.test(
|
||||
"toggle_stage unstages correctly when buffer lines are shifted",
|
||||
function()
|
||||
local dir, buf = setup("a\nb\nc\n", "a\nb\nC\n")
|
||||
vim.api.nvim_win_set_cursor(0, { 3, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 1
|
||||
end, "the line-3 change to be staged")
|
||||
|
||||
vim.api.nvim_buf_set_lines(buf, 0, 0, false, { "NEW" })
|
||||
vim.api.nvim_exec_autocmds("TextChanged", { buffer = buf })
|
||||
hunks._flush(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 1
|
||||
end, "the unstaged add at the top to register")
|
||||
vim.api.nvim_buf_set_lines(buf, 0, 0, false, { "NEW" })
|
||||
vim.api.nvim_exec_autocmds("TextChanged", { buffer = buf })
|
||||
hunks._flush(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).hunks == 1
|
||||
end, "the unstaged add at the top to register")
|
||||
|
||||
vim.api.nvim_win_set_cursor(0, { 4, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 0
|
||||
end, "the shifted staged hunk to be unstaged")
|
||||
t.eq(
|
||||
h.git(dir, "show", ":0:a.txt").stdout,
|
||||
"a\nb\nc",
|
||||
"the index reverts to HEAD content for the unstaged hunk"
|
||||
)
|
||||
end)
|
||||
vim.api.nvim_win_set_cursor(0, { 4, 0 })
|
||||
hunks.toggle_stage(buf)
|
||||
t.wait_for(function()
|
||||
return #assert(hunks.state(buf)).staged == 0
|
||||
end, "the shifted staged hunk to be unstaged")
|
||||
t.eq(
|
||||
h.git(dir, "show", ":0:a.txt").stdout,
|
||||
"a\nb\nc",
|
||||
"the index reverts to HEAD content for the unstaged hunk"
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
t.test("reset_hunk restores the index content for a change", function()
|
||||
local _, buf, state = setup("a\nb\nc\n", "a\nB\nc\n")
|
||||
|
||||
+17
-17
@@ -80,28 +80,28 @@ t.test("M.open(HEAD:<path>) loads file content at HEAD", function()
|
||||
|
||||
object.open(r, "HEAD:a.txt", { split = false })
|
||||
t.eq(vim.api.nvim_buf_get_name(0), "git://" .. sha .. ":a.txt")
|
||||
t.eq(
|
||||
vim.api.nvim_buf_get_lines(0, 0, -1, false),
|
||||
{ "first", "second" }
|
||||
)
|
||||
t.eq(vim.api.nvim_buf_get_lines(0, 0, -1, false), { "first", "second" })
|
||||
end)
|
||||
|
||||
t.test("M.open on a merge commit diffs against the first parent only", function()
|
||||
local dir = h.make_repo({ ["a.txt"] = "one\n" })
|
||||
t.write(dir, "a.txt", "two\n")
|
||||
h.git(dir, "stash")
|
||||
local stash = h.git(dir, "rev-parse", "stash@{0}").stdout
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
t.test(
|
||||
"M.open on a merge commit diffs against the first parent only",
|
||||
function()
|
||||
local dir = h.make_repo({ ["a.txt"] = "one\n" })
|
||||
t.write(dir, "a.txt", "two\n")
|
||||
h.git(dir, "stash")
|
||||
local stash = h.git(dir, "rev-parse", "stash@{0}").stdout
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
|
||||
object.open(r, stash, { split = false })
|
||||
local count = 0
|
||||
for _, l in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do
|
||||
if l:match("^diff %-%-git ") then
|
||||
count = count + 1
|
||||
object.open(r, stash, { split = false })
|
||||
local count = 0
|
||||
for _, l in ipairs(vim.api.nvim_buf_get_lines(0, 0, -1, false)) do
|
||||
if l:match("^diff %-%-git ") then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
t.eq(count, 1, "the stashed file's diff appears once, not per-parent")
|
||||
end
|
||||
t.eq(count, 1, "the stashed file's diff appears once, not per-parent")
|
||||
end)
|
||||
)
|
||||
|
||||
t.test("M.open errors on a bogus base, no buffer is opened", function()
|
||||
local dir = h.make_repo({ a = "first\n" })
|
||||
|
||||
+117
-91
@@ -235,27 +235,33 @@ t.test("status_entry_for: exact match on case-sensitive repo", function()
|
||||
t.eq(r:status_entry_for("foo"), nil, "case mismatch returns nil")
|
||||
end)
|
||||
|
||||
t.test("status_entry_for: case-insensitive fallback when core.ignorecase=true", function()
|
||||
local dir = h.make_repo({ Foo = "x" })
|
||||
h.git(dir, "config", "core.ignorecase", "true")
|
||||
t.write(dir, "Foo", "modified")
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
wait_initial(r)
|
||||
t.truthy(r:status_entry_for("Foo"), "exact match")
|
||||
t.truthy(r:status_entry_for("foo"), "lowercase finds Foo")
|
||||
t.truthy(r:status_entry_for("FOO"), "uppercase finds Foo")
|
||||
end)
|
||||
t.test(
|
||||
"status_entry_for: case-insensitive fallback when core.ignorecase=true",
|
||||
function()
|
||||
local dir = h.make_repo({ Foo = "x" })
|
||||
h.git(dir, "config", "core.ignorecase", "true")
|
||||
t.write(dir, "Foo", "modified")
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
wait_initial(r)
|
||||
t.truthy(r:status_entry_for("Foo"), "exact match")
|
||||
t.truthy(r:status_entry_for("foo"), "lowercase finds Foo")
|
||||
t.truthy(r:status_entry_for("FOO"), "uppercase finds Foo")
|
||||
end
|
||||
)
|
||||
|
||||
t.test("_invalidate matches stash_refs on refs/stash and logs/refs/stash", function()
|
||||
local dir = h.make_repo({ a = "x" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
r._cache.stash_refs = {}
|
||||
r:_invalidate("refs/stash")
|
||||
t.eq(r._cache.stash_refs, nil)
|
||||
r._cache.stash_refs = {}
|
||||
r:_invalidate("logs/refs/stash")
|
||||
t.eq(r._cache.stash_refs, nil)
|
||||
end)
|
||||
t.test(
|
||||
"_invalidate matches stash_refs on refs/stash and logs/refs/stash",
|
||||
function()
|
||||
local dir = h.make_repo({ a = "x" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
r._cache.stash_refs = {}
|
||||
r:_invalidate("refs/stash")
|
||||
t.eq(r._cache.stash_refs, nil)
|
||||
r._cache.stash_refs = {}
|
||||
r:_invalidate("logs/refs/stash")
|
||||
t.eq(r._cache.stash_refs, nil)
|
||||
end
|
||||
)
|
||||
|
||||
t.test("refresh with invalidate=true wipes cache on next fetch", function()
|
||||
local dir = h.make_repo({ a = "x" })
|
||||
@@ -271,83 +277,103 @@ t.test("refresh with invalidate=true wipes cache on next fetch", function()
|
||||
t.eq(r._cache["resolve:abc"], nil)
|
||||
end)
|
||||
|
||||
t.test("refresh emits change.paths listing structurally-changed paths", function()
|
||||
local dir = h.make_repo({ a = "1", b = "1" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
wait_initial(r)
|
||||
t.write(dir, "a", "2")
|
||||
---@type ow.Git.Repo.Change?
|
||||
local change_seen
|
||||
local unsub = r:on("change", function(change)
|
||||
change_seen = change
|
||||
end)
|
||||
r:refresh()
|
||||
t.wait_for(function()
|
||||
return change_seen ~= nil
|
||||
end, "refresh emit", 2000)
|
||||
unsub()
|
||||
local change = assert(change_seen)
|
||||
t.truthy(change.paths["a"])
|
||||
t.falsy(change.paths["b"], "b is unchanged structurally")
|
||||
end)
|
||||
t.test(
|
||||
"refresh emits change.paths listing structurally-changed paths",
|
||||
function()
|
||||
local dir = h.make_repo({ a = "1", b = "1" })
|
||||
local r = assert(require("git.core.repo").resolve(dir))
|
||||
wait_initial(r)
|
||||
t.write(dir, "a", "2")
|
||||
---@type ow.Git.Repo.Change?
|
||||
local change_seen
|
||||
local unsub = r:on("change", function(change)
|
||||
change_seen = change
|
||||
end)
|
||||
r:refresh()
|
||||
t.wait_for(function()
|
||||
return change_seen ~= nil
|
||||
end, "refresh emit", 2000)
|
||||
unsub()
|
||||
local change = assert(change_seen)
|
||||
t.truthy(change.paths["a"])
|
||||
t.falsy(change.paths["b"], "b is unchanged structurally")
|
||||
end
|
||||
)
|
||||
|
||||
t.test("submodule: parent enumerates initialized submodules by default", function()
|
||||
local outer_path = h.make_submodule_repo()
|
||||
local outer = assert(require("git.core.repo").resolve(outer_path))
|
||||
t.truthy(outer._submodules["sub"], "sub recorded as submodule")
|
||||
end)
|
||||
t.test(
|
||||
"submodule: parent enumerates initialized submodules by default",
|
||||
function()
|
||||
local outer_path = h.make_submodule_repo()
|
||||
local outer = assert(require("git.core.repo").resolve(outer_path))
|
||||
t.truthy(outer._submodules["sub"], "sub recorded as submodule")
|
||||
end
|
||||
)
|
||||
|
||||
t.test("submodule: eagerly creates child Repos and subscribes by default", function()
|
||||
local outer_path = h.make_submodule_repo()
|
||||
local outer = assert(require("git.core.repo").resolve(outer_path))
|
||||
wait_initial(outer)
|
||||
local inner = require("git.core.repo").all()[outer_path .. "/sub"]
|
||||
t.truthy(inner, "inner Repo eagerly created")
|
||||
t.truthy(outer._submodules["sub"] and outer._submodules["sub"].unsub, "inner subscribed by outer")
|
||||
t.test(
|
||||
"submodule: eagerly creates child Repos and subscribes by default",
|
||||
function()
|
||||
local outer_path = h.make_submodule_repo()
|
||||
local outer = assert(require("git.core.repo").resolve(outer_path))
|
||||
wait_initial(outer)
|
||||
local inner = require("git.core.repo").all()[outer_path .. "/sub"]
|
||||
t.truthy(inner, "inner Repo eagerly created")
|
||||
t.truthy(
|
||||
outer._submodules["sub"] and outer._submodules["sub"].unsub,
|
||||
"inner subscribed by outer"
|
||||
)
|
||||
|
||||
t.write(outer_path .. "/sub", "a", "modified\n")
|
||||
---@type ow.Git.Repo.Change?
|
||||
local outer_change
|
||||
local unsub = outer:on("change", function(change)
|
||||
outer_change = change
|
||||
end)
|
||||
inner:refresh()
|
||||
t.wait_for(function()
|
||||
return outer_change ~= nil
|
||||
end, "outer notified by inner refresh", 2000)
|
||||
unsub()
|
||||
t.write(outer_path .. "/sub", "a", "modified\n")
|
||||
---@type ow.Git.Repo.Change?
|
||||
local outer_change
|
||||
local unsub = outer:on("change", function(change)
|
||||
outer_change = change
|
||||
end)
|
||||
inner:refresh()
|
||||
t.wait_for(function()
|
||||
return outer_change ~= nil
|
||||
end, "outer notified by inner refresh", 2000)
|
||||
unsub()
|
||||
|
||||
local entry = outer.status.entries["sub"]
|
||||
t.truthy(entry, "outer sub entry now present")
|
||||
t.eq(entry.kind, "changed")
|
||||
end)
|
||||
local entry = outer.status.entries["sub"]
|
||||
t.truthy(entry, "outer sub entry now present")
|
||||
t.eq(entry.kind, "changed")
|
||||
end
|
||||
)
|
||||
|
||||
t.test("submodule: no eager creation when flag is explicitly disabled", function()
|
||||
vim.g.git_submodule_recursion = false
|
||||
t.defer(function()
|
||||
vim.g.git_submodule_recursion = nil
|
||||
end)
|
||||
local outer_path = h.make_submodule_repo()
|
||||
local outer = assert(require("git.core.repo").resolve(outer_path))
|
||||
wait_initial(outer)
|
||||
t.eq(
|
||||
require("git.core.repo").all()[outer_path .. "/sub"],
|
||||
nil,
|
||||
"inner Repo not created when flag is false"
|
||||
)
|
||||
t.eq(next(outer._submodules), nil)
|
||||
end)
|
||||
t.test(
|
||||
"submodule: no eager creation when flag is explicitly disabled",
|
||||
function()
|
||||
vim.g.git_submodule_recursion = false
|
||||
t.defer(function()
|
||||
vim.g.git_submodule_recursion = nil
|
||||
end)
|
||||
local outer_path = h.make_submodule_repo()
|
||||
local outer = assert(require("git.core.repo").resolve(outer_path))
|
||||
wait_initial(outer)
|
||||
t.eq(
|
||||
require("git.core.repo").all()[outer_path .. "/sub"],
|
||||
nil,
|
||||
"inner Repo not created when flag is false"
|
||||
)
|
||||
t.eq(next(outer._submodules), nil)
|
||||
end
|
||||
)
|
||||
|
||||
t.test("submodule: outer created after inner picks up existing child", function()
|
||||
local outer_path = h.make_submodule_repo()
|
||||
local inner = assert(
|
||||
require("git.core.repo").resolve(outer_path .. "/sub")
|
||||
)
|
||||
wait_initial(inner)
|
||||
local outer = assert(require("git.core.repo").resolve(outer_path))
|
||||
wait_initial(outer)
|
||||
t.truthy(outer._submodules["sub"] and outer._submodules["sub"].unsub, "outer subscribed to pre-existing inner")
|
||||
end)
|
||||
t.test(
|
||||
"submodule: outer created after inner picks up existing child",
|
||||
function()
|
||||
local outer_path = h.make_submodule_repo()
|
||||
local inner =
|
||||
assert(require("git.core.repo").resolve(outer_path .. "/sub"))
|
||||
wait_initial(inner)
|
||||
local outer = assert(require("git.core.repo").resolve(outer_path))
|
||||
wait_initial(outer)
|
||||
t.truthy(
|
||||
outer._submodules["sub"] and outer._submodules["sub"].unsub,
|
||||
"outer subscribed to pre-existing inner"
|
||||
)
|
||||
end
|
||||
)
|
||||
|
||||
t.test("watcher cleans up after a slash-branch dir is removed", function()
|
||||
local dir = h.make_repo({ a = "x" })
|
||||
|
||||
+30
-19
@@ -1,5 +1,5 @@
|
||||
local t = require("test")
|
||||
local status = require("git.core.status")
|
||||
local t = require("test")
|
||||
|
||||
local NUL = "\0"
|
||||
|
||||
@@ -204,7 +204,10 @@ t.test("mark_for: changed staged modified", function()
|
||||
path = "x",
|
||||
staged = "modified",
|
||||
}
|
||||
t.eq(status.mark_for(entry, "staged"), { char = "M", hl = "GitStagedModified" })
|
||||
t.eq(
|
||||
status.mark_for(entry, "staged"),
|
||||
{ char = "M", hl = "GitStagedModified" }
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("mark_for: changed unstaged deleted uses GitUnstagedDeleted", function()
|
||||
@@ -213,7 +216,10 @@ t.test("mark_for: changed unstaged deleted uses GitUnstagedDeleted", function()
|
||||
path = "x",
|
||||
unstaged = "deleted",
|
||||
}
|
||||
t.eq(status.mark_for(entry, "unstaged"), { char = "D", hl = "GitUnstagedDeleted" })
|
||||
t.eq(
|
||||
status.mark_for(entry, "unstaged"),
|
||||
{ char = "D", hl = "GitUnstagedDeleted" }
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("mark_for: changed renamed uses per-side renamed hl", function()
|
||||
@@ -223,7 +229,10 @@ t.test("mark_for: changed renamed uses per-side renamed hl", function()
|
||||
staged = "renamed",
|
||||
orig = "y",
|
||||
}
|
||||
t.eq(status.mark_for(entry, "staged"), { char = "R", hl = "GitStagedRenamed" })
|
||||
t.eq(
|
||||
status.mark_for(entry, "staged"),
|
||||
{ char = "R", hl = "GitStagedRenamed" }
|
||||
)
|
||||
end)
|
||||
|
||||
t.test("mark_for: untracked / ignored / unmerged ignore side", function()
|
||||
@@ -364,24 +373,26 @@ t.test("entry_equal: differing unmerged conflict returns false", function()
|
||||
t.falsy(status.entry_equal(a, b))
|
||||
end)
|
||||
|
||||
t.test("diff_entries: detects additions, removals, and modifications", function()
|
||||
local prior = {
|
||||
a = { kind = "changed", path = "a", staged = "modified" },
|
||||
b = { kind = "untracked", path = "b" },
|
||||
}
|
||||
local next_ = {
|
||||
a = { kind = "changed", path = "a", staged = "added" },
|
||||
c = { kind = "untracked", path = "c" },
|
||||
}
|
||||
local changed = status.diff_entries(prior, next_)
|
||||
t.truthy(changed.a, "a modified")
|
||||
t.truthy(changed.b, "b removed")
|
||||
t.truthy(changed.c, "c added")
|
||||
end)
|
||||
t.test(
|
||||
"diff_entries: detects additions, removals, and modifications",
|
||||
function()
|
||||
local prior = {
|
||||
a = { kind = "changed", path = "a", staged = "modified" },
|
||||
b = { kind = "untracked", path = "b" },
|
||||
}
|
||||
local next_ = {
|
||||
a = { kind = "changed", path = "a", staged = "added" },
|
||||
c = { kind = "untracked", path = "c" },
|
||||
}
|
||||
local changed = status.diff_entries(prior, next_)
|
||||
t.truthy(changed.a, "a modified")
|
||||
t.truthy(changed.b, "b removed")
|
||||
t.truthy(changed.c, "c added")
|
||||
end
|
||||
)
|
||||
|
||||
t.test("diff_entries: empty when entries match", function()
|
||||
local prior = { a = { kind = "untracked", path = "a" } }
|
||||
local next_ = { a = { kind = "untracked", path = "a" } }
|
||||
t.eq(status.diff_entries(prior, next_), {})
|
||||
end)
|
||||
|
||||
|
||||
@@ -406,82 +406,75 @@ t.test("sidebar buffer name does not get written to disk", function()
|
||||
)
|
||||
end)
|
||||
|
||||
t.test(
|
||||
"diffsplit from sidebar resets cursor so panes stay in sync",
|
||||
function()
|
||||
local committed, worktree = {}, {}
|
||||
for i = 1, 100 do
|
||||
committed[i] = "line " .. i
|
||||
worktree[i] = i == 10
|
||||
and "CHANGED " .. i
|
||||
or i == 40 and "CHANGED " .. i
|
||||
or i == 70 and "CHANGED " .. i
|
||||
or i == 90 and "CHANGED " .. i
|
||||
or ("line " .. i)
|
||||
end
|
||||
local repo = h.make_repo({
|
||||
["file.txt"] = table.concat(committed, "\n") .. "\n",
|
||||
})
|
||||
t.write(repo, "file.txt", table.concat(worktree, "\n") .. "\n")
|
||||
vim.cmd("cd " .. repo)
|
||||
|
||||
-- Open the worktree file in a normal window and position cursor in
|
||||
-- what becomes a folded section after diff is set up.
|
||||
vim.cmd("edit file.txt")
|
||||
vim.api.nvim_win_set_cursor(0, { 50, 0 })
|
||||
|
||||
require("git.status_view").open({ placement = "sidebar" })
|
||||
local sidebar_buf, sidebar_win = find_sidebar()
|
||||
assert(sidebar_buf and sidebar_win)
|
||||
local r = assert(require("git.core.repo").find(vim.fn.getcwd()))
|
||||
r:refresh()
|
||||
t.wait_for(function()
|
||||
return r.status and #r.status:rows("unstaged") > 0
|
||||
end, "git status to report unstaged changes")
|
||||
|
||||
local entry_line
|
||||
for i, l in
|
||||
ipairs(vim.api.nvim_buf_get_lines(sidebar_buf, 0, -1, false))
|
||||
do
|
||||
if l:match("file.txt$") then
|
||||
entry_line = i
|
||||
break
|
||||
end
|
||||
end
|
||||
if not entry_line then
|
||||
error("entry line should exist")
|
||||
end
|
||||
|
||||
vim.api.nvim_set_current_win(sidebar_win)
|
||||
vim.api.nvim_win_set_cursor(sidebar_win, { entry_line, 0 })
|
||||
t.press("<Tab>")
|
||||
t.wait_for(function()
|
||||
return find_diff_win("left") ~= nil
|
||||
and find_diff_win("right") ~= nil
|
||||
end, "diff pair to appear")
|
||||
|
||||
local left_win = assert(find_diff_win("left"))
|
||||
local right_win = assert(find_diff_win("right"))
|
||||
local left_top =
|
||||
vim.api.nvim_win_call(left_win, function() return vim.fn.line("w0") end)
|
||||
local right_top = vim.api.nvim_win_call(
|
||||
right_win,
|
||||
function() return vim.fn.line("w0") end
|
||||
)
|
||||
t.eq(
|
||||
left_top,
|
||||
right_top,
|
||||
"left and right panes should have the same topline after diffsplit"
|
||||
)
|
||||
t.eq(
|
||||
vim.api.nvim_win_get_cursor(left_win),
|
||||
{ 1, 0 },
|
||||
"left pane should start at line 1"
|
||||
)
|
||||
t.eq(
|
||||
vim.api.nvim_win_get_cursor(right_win),
|
||||
{ 1, 0 },
|
||||
"right pane should start at line 1"
|
||||
)
|
||||
t.test("diffsplit from sidebar resets cursor so panes stay in sync", function()
|
||||
local committed, worktree = {}, {}
|
||||
for i = 1, 100 do
|
||||
committed[i] = "line " .. i
|
||||
worktree[i] = i == 10 and "CHANGED " .. i
|
||||
or i == 40 and "CHANGED " .. i
|
||||
or i == 70 and "CHANGED " .. i
|
||||
or i == 90 and "CHANGED " .. i
|
||||
or ("line " .. i)
|
||||
end
|
||||
)
|
||||
local repo = h.make_repo({
|
||||
["file.txt"] = table.concat(committed, "\n") .. "\n",
|
||||
})
|
||||
t.write(repo, "file.txt", table.concat(worktree, "\n") .. "\n")
|
||||
vim.cmd("cd " .. repo)
|
||||
|
||||
-- Open the worktree file in a normal window and position cursor in
|
||||
-- what becomes a folded section after diff is set up.
|
||||
vim.cmd("edit file.txt")
|
||||
vim.api.nvim_win_set_cursor(0, { 50, 0 })
|
||||
|
||||
require("git.status_view").open({ placement = "sidebar" })
|
||||
local sidebar_buf, sidebar_win = find_sidebar()
|
||||
assert(sidebar_buf and sidebar_win)
|
||||
local r = assert(require("git.core.repo").find(vim.fn.getcwd()))
|
||||
r:refresh()
|
||||
t.wait_for(function()
|
||||
return r.status and #r.status:rows("unstaged") > 0
|
||||
end, "git status to report unstaged changes")
|
||||
|
||||
local entry_line
|
||||
for i, l in ipairs(vim.api.nvim_buf_get_lines(sidebar_buf, 0, -1, false)) do
|
||||
if l:match("file.txt$") then
|
||||
entry_line = i
|
||||
break
|
||||
end
|
||||
end
|
||||
if not entry_line then
|
||||
error("entry line should exist")
|
||||
end
|
||||
|
||||
vim.api.nvim_set_current_win(sidebar_win)
|
||||
vim.api.nvim_win_set_cursor(sidebar_win, { entry_line, 0 })
|
||||
t.press("<Tab>")
|
||||
t.wait_for(function()
|
||||
return find_diff_win("left") ~= nil and find_diff_win("right") ~= nil
|
||||
end, "diff pair to appear")
|
||||
|
||||
local left_win = assert(find_diff_win("left"))
|
||||
local right_win = assert(find_diff_win("right"))
|
||||
local left_top = vim.api.nvim_win_call(left_win, function()
|
||||
return vim.fn.line("w0")
|
||||
end)
|
||||
local right_top = vim.api.nvim_win_call(right_win, function()
|
||||
return vim.fn.line("w0")
|
||||
end)
|
||||
t.eq(
|
||||
left_top,
|
||||
right_top,
|
||||
"left and right panes should have the same topline after diffsplit"
|
||||
)
|
||||
t.eq(
|
||||
vim.api.nvim_win_get_cursor(left_win),
|
||||
{ 1, 0 },
|
||||
"left pane should start at line 1"
|
||||
)
|
||||
t.eq(
|
||||
vim.api.nvim_win_get_cursor(right_win),
|
||||
{ 1, 0 },
|
||||
"right pane should start at line 1"
|
||||
)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user