mirror of
https://github.com/zoriya/jj.nvim.git
synced 2026-08-05 18:56:13 +00:00
Migrate command execution to structured argv lists across the plugin, replacing shell-string command construction with `vim.system` argv execution. The runner API now exposes argv-based execution as the default path:
- `runner.execute_command` -> `runner.execute`
- `runner.execute_command_async` -> `runner.execute_async`
- `runner.execute_command_raw` -> `runner.execute_raw`
- `runner.execute_command_raw_async` -> `runner.execute_raw_async`
- `runner.execute_command_sync` was removed; use `runner.execute` and handle the result directly
BREAKING CHANGES:
- `cmd.new({ args = ... })` now requires `args` as `string[]` argv tokens, not a single string.
- `cmd.log({ ... })` now uses `raw_flags` as `string[]` for raw passthrough flags; `raw = "..."` is no longer supported.
- Direct users of `jj.core.runner` must migrate from the old `execute_command*` string helpers to the new argv-based `execute*` helpers.
87 lines
2.0 KiB
Lua
87 lines
2.0 KiB
Lua
local M = {}
|
|
|
|
local utils = require("jj.utils")
|
|
local terminal = require("jj.ui.terminal")
|
|
local jj_args = require("jj.core.args")
|
|
|
|
--- Build the jj split command based on the provided options.
|
|
---@param opts jj.cmd.split.opts
|
|
---@return string[] The constructed jj split command.
|
|
local function build_split_command(opts)
|
|
local args = { "jj", "split" }
|
|
|
|
local rev = (opts.rev and opts.rev ~= "") and opts.rev or "@"
|
|
table.insert(args, "-r")
|
|
table.insert(args, rev)
|
|
|
|
if opts.parallel then
|
|
table.insert(args, "--parallel")
|
|
end
|
|
|
|
if opts.message then
|
|
table.insert(args, "--message")
|
|
table.insert(args, opts.message)
|
|
end
|
|
|
|
if opts.ignore_immutable then
|
|
table.insert(args, "--ignore-immutable")
|
|
end
|
|
|
|
if opts.filesets then
|
|
for _, fileset in ipairs(opts.filesets) do
|
|
table.insert(args, jj_args.fileset(fileset))
|
|
end
|
|
end
|
|
|
|
return args
|
|
end
|
|
|
|
--- Split natively
|
|
---@param opts? jj.cmd.split.opts
|
|
function M.split(opts)
|
|
if not utils.ensure_jj() then
|
|
return
|
|
end
|
|
|
|
opts = opts or {} --[[@as jj.cmd.split.opts]]
|
|
|
|
-- If it's empty do nothing
|
|
if utils.is_change_empty(opts.rev or "@") then
|
|
utils.notify(string.format("The change `%s` is empty, nothing to split.", opts.rev or "@"), vim.log.levels.INFO)
|
|
return
|
|
end
|
|
|
|
--- Run the jj split command in a floating terminal
|
|
---@param cmd string[]
|
|
local function run_split(cmd)
|
|
terminal.run_floating(cmd, nil, {
|
|
title = " JJ Split ",
|
|
modifiable = true,
|
|
keep_modifiable = true,
|
|
interactive = true,
|
|
on_exit = opts.on_exit or nil,
|
|
})
|
|
end
|
|
|
|
-- If the change is immutable warn the user and prompt him
|
|
if utils.is_change_immutable(opts.rev or "@") then
|
|
vim.ui.select(
|
|
{ "Yes", "No" },
|
|
{ prompt = string.format("The change `%s` is IMMUTABLE, do you still want to split it?", opts.rev or "@") },
|
|
function(item)
|
|
if item == "Yes" then
|
|
opts.ignore_immutable = true
|
|
local cmd = build_split_command(opts)
|
|
run_split(cmd)
|
|
return
|
|
end
|
|
end
|
|
)
|
|
else
|
|
local cmd = build_split_command(opts)
|
|
run_split(cmd)
|
|
end
|
|
end
|
|
|
|
return M
|