refactor(git): drop :Ghistory buffer in favor of :G! for full output
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
local commit = require("git.commit")
|
local commit = require("git.commit")
|
||||||
local history = require("git.history")
|
|
||||||
local object = require("git.object")
|
local object = require("git.object")
|
||||||
local repo = require("git.repo")
|
local repo = require("git.repo")
|
||||||
local util = require("git.util")
|
local util = require("git.util")
|
||||||
@@ -386,13 +385,11 @@ local function run_streaming(r, args)
|
|||||||
last_progress ~= "" and last_progress or "done",
|
last_progress ~= "" and last_progress or "done",
|
||||||
"success"
|
"success"
|
||||||
)
|
)
|
||||||
history.append(args, accum)
|
|
||||||
else
|
else
|
||||||
emit_progress(("exit %d"):format(code), "failed")
|
emit_progress(("exit %d"):format(code), "failed")
|
||||||
local body = #accum > 0 and table.concat(accum, "\n")
|
local body = #accum > 0 and table.concat(accum, "\n")
|
||||||
or ("%s failed: exit %d"):format(title, code)
|
or ("%s failed: exit %d"):format(title, code)
|
||||||
vim.api.nvim_echo({ { body, "ErrorMsg" } }, true, {})
|
vim.api.nvim_echo({ { body, "ErrorMsg" } }, true, {})
|
||||||
history.append(args, accum)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
local util = require("git.util")
|
|
||||||
|
|
||||||
local M = {}
|
|
||||||
|
|
||||||
local BUF_NAME = "githistory://log"
|
|
||||||
|
|
||||||
---@type integer?
|
|
||||||
local cached_buf
|
|
||||||
|
|
||||||
---@return integer
|
|
||||||
local function get_buf()
|
|
||||||
if cached_buf and vim.api.nvim_buf_is_valid(cached_buf) then
|
|
||||||
return cached_buf
|
|
||||||
end
|
|
||||||
local buf = vim.api.nvim_create_buf(false, true)
|
|
||||||
pcall(vim.api.nvim_buf_set_name, buf, BUF_NAME)
|
|
||||||
util.setup_scratch(buf, { bufhidden = "hide" })
|
|
||||||
cached_buf = buf
|
|
||||||
return buf
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param args string[]
|
|
||||||
---@param lines string[]
|
|
||||||
function M.append(args, lines)
|
|
||||||
if #lines == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local buf = get_buf()
|
|
||||||
local count = vim.api.nvim_buf_line_count(buf)
|
|
||||||
local first = vim.api.nvim_buf_get_lines(buf, 0, 1, false)[1] or ""
|
|
||||||
local empty = count == 1 and first == ""
|
|
||||||
local payload = { "$ git " .. table.concat(args, " ") }
|
|
||||||
vim.list_extend(payload, lines)
|
|
||||||
vim.bo[buf].modifiable = true
|
|
||||||
if empty then
|
|
||||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, payload)
|
|
||||||
else
|
|
||||||
table.insert(payload, 1, "")
|
|
||||||
vim.api.nvim_buf_set_lines(buf, count, count, false, payload)
|
|
||||||
end
|
|
||||||
vim.bo[buf].modifiable = false
|
|
||||||
vim.bo[buf].modified = false
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.open()
|
|
||||||
local buf = get_buf()
|
|
||||||
local win = vim.fn.bufwinid(buf)
|
|
||||||
if win ~= -1 then
|
|
||||||
vim.api.nvim_set_current_win(win)
|
|
||||||
else
|
|
||||||
util.place_buf(buf, nil)
|
|
||||||
win = vim.api.nvim_get_current_win()
|
|
||||||
end
|
|
||||||
local last = vim.api.nvim_buf_line_count(buf)
|
|
||||||
vim.api.nvim_win_set_cursor(win, { last, 0 })
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
||||||
@@ -151,10 +151,6 @@ function M.init()
|
|||||||
require("git.repo").refresh_all()
|
require("git.repo").refresh_all()
|
||||||
end, { desc = "Refresh git status for all repos" })
|
end, { desc = "Refresh git status for all repos" })
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("Ghistory", function()
|
|
||||||
require("git.history").open()
|
|
||||||
end, { desc = "Open the git streaming output history" })
|
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("Gstatus", function(opts)
|
vim.api.nvim_create_user_command("Gstatus", function(opts)
|
||||||
require("git.status_view").open({
|
require("git.status_view").open({
|
||||||
placement = opts.fargs[1] --[[@as ow.Git.StatusView.Placement]] or "split",
|
placement = opts.fargs[1] --[[@as ow.Git.StatusView.Placement]] or "split",
|
||||||
|
|||||||
@@ -610,30 +610,6 @@ t.test(
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
t.test("streaming output buffer collects runs (failure path)", function()
|
|
||||||
make_repo({ a = "x" })
|
|
||||||
with_echo_stub(function(calls)
|
|
||||||
cmd.run({ "fetch", "nonexistent" })
|
|
||||||
t.wait_for(function()
|
|
||||||
return has_status(calls, "failed")
|
|
||||||
end, "failed progress notification", 5000)
|
|
||||||
end)
|
|
||||||
require("git.history").open()
|
|
||||||
local buf = vim.api.nvim_get_current_buf()
|
|
||||||
local lines = vim.api.nvim_buf_get_lines(buf, 0, -1, false)
|
|
||||||
local found_header, found_fatal = false, false
|
|
||||||
for _, l in ipairs(lines) do
|
|
||||||
if l:match("^%$ git fetch nonexistent$") then
|
|
||||||
found_header = true
|
|
||||||
end
|
|
||||||
if l:match("fatal:") then
|
|
||||||
found_fatal = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
t.truthy(found_header, "expected '$ git fetch nonexistent' header")
|
|
||||||
t.truthy(found_fatal, "expected fatal: line in output buffer")
|
|
||||||
end)
|
|
||||||
|
|
||||||
t.test(
|
t.test(
|
||||||
"streaming :G! fetch (bang) opens preview window with terminal buffer",
|
"streaming :G! fetch (bang) opens preview window with terminal buffer",
|
||||||
function()
|
function()
|
||||||
|
|||||||
Reference in New Issue
Block a user