Merge branch 'master' into cherry-pick-options

This commit is contained in:
Cameron 2024-07-23 23:39:09 +02:00 committed by GitHub
commit 08ce849b85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 71 additions and 66 deletions

View file

@ -668,13 +668,13 @@ M.n_discard = function(self)
input.get_choice("Discard conflict by taking...", { values = choices, default = #choices })
if choice == "o" then
git.cli.checkout.ours.files(selection.item.absolute_path).call { async = false }
git.cli.checkout.ours.files(selection.item.absolute_path).call { await = true }
git.status.stage { selection.item.name }
elseif choice == "t" then
git.cli.checkout.theirs.files(selection.item.absolute_path).call { async = false }
git.cli.checkout.theirs.files(selection.item.absolute_path).call { await = true }
git.status.stage { selection.item.name }
elseif choice == "c" then
git.cli.checkout.merge.files(selection.item.absolute_path).call { async = false }
git.cli.checkout.merge.files(selection.item.absolute_path).call { await = true }
git.status.stage { selection.item.name }
end
end
@ -699,13 +699,13 @@ M.n_discard = function(self)
input.get_choice("Discard conflict by taking...", { values = choices, default = #choices })
if choice == "o" then
git.cli.checkout.ours.files(selection.item.absolute_path).call { async = false }
git.cli.checkout.ours.files(selection.item.absolute_path).call { await = true }
git.status.stage { selection.item.name }
elseif choice == "t" then
git.cli.checkout.theirs.files(selection.item.absolute_path).call { async = false }
git.cli.checkout.theirs.files(selection.item.absolute_path).call { await = true }
git.status.stage { selection.item.name }
elseif choice == "c" then
git.cli.checkout.merge.files(selection.item.absolute_path).call { async = false }
git.cli.checkout.merge.files(selection.item.absolute_path).call { await = true }
git.status.stage { selection.item.name }
end
end

View file

@ -92,9 +92,9 @@ local function get_local_diff_view(section_name, item_name, opts)
table.insert(args, "HEAD")
end
return git.cli.show.file(unpack(args)).call({ async = false, trim = false }).stdout
return git.cli.show.file(unpack(args)).call({ await = true, trim = false }).stdout
elseif kind == "working" then
local fdata = git.cli.show.file(path).call({ async = false, trim = false }).stdout
local fdata = git.cli.show.file(path).call({ await = true, trim = false }).stdout
return side == "left" and fdata
end
end,

View file

@ -178,6 +178,10 @@ function Buffer:move_top_line(line)
return
end
if vim.o.lines < vim.fn.line("$") then
return
end
local position = { line, 0 }
if type(line) == "table" then

View file

@ -54,7 +54,7 @@ function M.get_recent_local_branches()
end
function M.checkout(name, args)
git.cli.checkout.branch(name).arg_list(args or {}).call { async = false }
git.cli.checkout.branch(name).arg_list(args or {}).call { await = true }
if config.values.fetch_after_checkout then
local pushRemote = M.pushRemote_ref(name)
@ -78,7 +78,7 @@ function M.checkout(name, args)
end
function M.track(name, args)
git.cli.checkout.track(name).arg_list(args or {}).call { async = false }
git.cli.checkout.track(name).arg_list(args or {}).call { await = true }
end
function M.get_local_branches(include_current)
@ -139,7 +139,7 @@ end
---@param name string
---@param base_branch? string
function M.create(name, base_branch)
git.cli.branch.args(name, base_branch).call { async = false }
git.cli.branch.args(name, base_branch).call { await = true }
end
function M.delete(name)
@ -149,10 +149,10 @@ function M.delete(name)
if M.is_unmerged(name) then
local message = ("'%s' contains unmerged commits! Are you sure you want to delete it?"):format(name)
if input.get_permission(message) then
result = git.cli.branch.delete.force.name(name).call { async = false }
result = git.cli.branch.delete.force.name(name).call { await = true }
end
else
result = git.cli.branch.delete.name(name).call { async = false }
result = git.cli.branch.delete.name(name).call { await = true }
end
return result and result.code == 0 or false

View file

@ -17,7 +17,7 @@ function M.pick(commits, args)
if vim.tbl_contains(args, "--edit") then
result = cmd.env(client.get_envs_git_editor()).call { pty = true }
else
result = cmd.call { async = false }
result = cmd.call { await = true }
end
if result.code ~= 0 then
@ -34,7 +34,7 @@ function M.apply(commits, args)
end
end)
local result = git.cli["cherry-pick"].no_commit.arg_list(util.merge(args, commits)).call { async = false }
local result = git.cli["cherry-pick"].no_commit.arg_list(util.merge(args, commits)).call { await = true }
if result.code ~= 0 then
notification.error("Cherry Pick failed. Resolve conflicts before continuing")
else
@ -43,15 +43,15 @@ function M.apply(commits, args)
end
function M.continue()
git.cli["cherry-pick"].continue.call { async = false }
git.cli["cherry-pick"].continue.call { await = true }
end
function M.skip()
git.cli["cherry-pick"].skip.call { async = false }
git.cli["cherry-pick"].skip.call { await = true }
end
function M.abort()
git.cli["cherry-pick"].abort.call { async = false }
git.cli["cherry-pick"].abort.call { await = true }
end
return M

View file

@ -978,13 +978,13 @@ local function new_builder(subcommand)
hidden = false,
trim = true,
remove_ansi = true,
async = true,
await = false,
long = false,
pty = false,
})
if opts.pty then
opts.async = true
opts.await = false
end
return opts
@ -1040,7 +1040,7 @@ local function new_builder(subcommand)
end
end
local function run_sync()
local function run_await()
if not p:spawn() then
error("Failed to run command")
return nil
@ -1049,16 +1049,16 @@ local function new_builder(subcommand)
result = p:wait()
end
if opts.async then
if opts.await then
logger.debug("Running command await: " .. vim.inspect(p.cmd))
run_await()
else
logger.debug("Running command async: " .. vim.inspect(p.cmd))
local ok, _ = pcall(run_async)
if not ok then
logger.debug("Running command async failed - awaiting instead")
run_sync()
run_await()
end
else
logger.debug("Running command sync: " .. vim.inspect(p.cmd))
run_sync()
end
assert(result, "Command did not complete")

View file

@ -100,23 +100,23 @@ function M.apply(patch, opts)
cmd = cmd.index
end
return cmd.ignore_space_change.with_patch(patch).call { async = false }
return cmd.ignore_space_change.with_patch(patch).call { await = true }
end
function M.add(files)
return git.cli.add.files(unpack(files)).call { async = false }
return git.cli.add.files(unpack(files)).call { await = true }
end
function M.checkout(files)
return git.cli.checkout.files(unpack(files)).call { async = false }
return git.cli.checkout.files(unpack(files)).call { await = true }
end
function M.reset(files)
return git.cli.reset.files(unpack(files)).call { async = false }
return git.cli.reset.files(unpack(files)).call { await = true }
end
function M.reset_HEAD(...)
return git.cli.reset.args("HEAD").arg_list({ ... }).call { async = false }
return git.cli.reset.args("HEAD").arg_list({ ... }).call { await = true }
end
function M.checkout_unstaged()
@ -124,7 +124,7 @@ function M.checkout_unstaged()
return item.escaped_path
end)
return git.cli.checkout.files(unpack(items)).call { async = false }
return git.cli.checkout.files(unpack(items)).call { await = true }
end
---Creates a temp index from a revision and calls the provided function with the index path

View file

@ -22,11 +22,11 @@ local function cleanup_push_variables(remote, new_name)
end
function M.add(name, url, args)
return git.cli.remote.add.arg_list(args).args(name, url).call().code == 0
return git.cli.remote.add.arg_list(args).args(name, url).call({ await = true }).code == 0
end
function M.rename(from, to)
local result = git.cli.remote.rename.arg_list({ from, to }).call()
local result = git.cli.remote.rename.arg_list({ from, to }).call { await = true }
if result.code == 0 then
cleanup_push_variables(from, to)
end
@ -35,7 +35,7 @@ function M.rename(from, to)
end
function M.remove(name)
local result = git.cli.remote.rm.args(name).call()
local result = git.cli.remote.rm.args(name).call { await = true }
if result.code == 0 then
cleanup_push_variables(name)
end

View file

@ -9,7 +9,7 @@ local function fire_reset_event(data)
end
function M.mixed(commit)
local result = git.cli.reset.mixed.args(commit).call { async = false }
local result = git.cli.reset.mixed.args(commit).call { await = true }
if result.code ~= 0 then
notification.error("Reset Failed")
else
@ -19,7 +19,7 @@ function M.mixed(commit)
end
function M.soft(commit)
local result = git.cli.reset.soft.args(commit).call { async = false }
local result = git.cli.reset.soft.args(commit).call { await = true }
if result.code ~= 0 then
notification.error("Reset Failed")
else
@ -29,7 +29,7 @@ function M.soft(commit)
end
function M.hard(commit)
local result = git.cli.reset.hard.args(commit).call { async = false }
local result = git.cli.reset.hard.args(commit).call { await = true }
if result.code ~= 0 then
notification.error("Reset Failed")
else
@ -39,7 +39,7 @@ function M.hard(commit)
end
function M.keep(commit)
local result = git.cli.reset.keep.args(commit).call { async = false }
local result = git.cli.reset.keep.args(commit).call { await = true }
if result.code ~= 0 then
notification.error("Reset Failed")
else
@ -49,7 +49,7 @@ function M.keep(commit)
end
function M.index(commit)
local result = git.cli.reset.args(commit).files(".").call { async = false }
local result = git.cli.reset.args(commit).files(".").call { await = true }
if result.code ~= 0 then
notification.error("Reset Failed")
else
@ -69,7 +69,7 @@ end
-- end
function M.file(commit, files)
local result = git.cli.checkout.rev(commit).files(unpack(files)).call { async = false }
local result = git.cli.checkout.rev(commit).files(unpack(files)).call { await = true }
if result.code ~= 0 then
notification.error("Reset Failed")
else

View file

@ -5,7 +5,7 @@ local util = require("neogit.lib.util")
local M = {}
function M.commits(commits, args)
return git.cli.revert.no_commit.arg_list(util.merge(args, commits)).call({ async = false }).code == 0
return git.cli.revert.no_commit.arg_list(util.merge(args, commits)).call({ await = true }).code == 0
end
function M.continue()

View file

@ -20,14 +20,14 @@ function M.list_refs()
end
function M.stash_all(args)
git.cli.stash.arg_list(args).call { async = false }
git.cli.stash.arg_list(args).call { await = true }
fire_stash_event("NeogitStash")
-- this should work, but for some reason doesn't.
--return perform_stash({ worktree = true, index = true })
end
function M.stash_index()
git.cli.stash.staged.call { async = false }
git.cli.stash.staged.call { await = true }
fire_stash_event("NeogitStash")
end
@ -38,38 +38,38 @@ function M.stash_keep_index()
-- git --literal-pathspecs stash --keep-index
-- fails with a bizarre error:
-- error: pathspec ':/' did not match any file(s) known to git
git.cli.stash.keep_index.files(unpack(files)).call { async = false }
git.cli.stash.keep_index.files(unpack(files)).call { await = true }
fire_stash_event("NeogitStash")
end
function M.push(args, files)
git.cli.stash.push.arg_list(args).files(unpack(files)).call { async = false }
git.cli.stash.push.arg_list(args).files(unpack(files)).call { await = true }
end
function M.pop(stash)
local result = git.cli.stash.apply.index.args(stash).call { async = false }
local result = git.cli.stash.apply.index.args(stash).call { await = true }
if result.code == 0 then
git.cli.stash.drop.args(stash).call { async = false }
git.cli.stash.drop.args(stash).call { await = true }
else
git.cli.stash.apply.args(stash).call { async = false }
git.cli.stash.apply.args(stash).call { await = true }
end
fire_stash_event("NeogitStash")
end
function M.apply(stash)
local result = git.cli.stash.apply.index.args(stash).call { async = false }
local result = git.cli.stash.apply.index.args(stash).call { await = true }
if result.code ~= 0 then
git.cli.stash.apply.args(stash).call { async = false }
git.cli.stash.apply.args(stash).call { await = true }
end
fire_stash_event("NeogitStash")
end
function M.drop(stash)
git.cli.stash.drop.args(stash).call { async = false }
git.cli.stash.drop.args(stash).call { await = true }
fire_stash_event("NeogitStash")
end
@ -81,8 +81,8 @@ function M.rename(stash)
local message = input.get_user_input("New name")
if message then
local oid = git.rev_parse.abbreviate_commit(stash)
git.cli.stash.drop.args(stash).call { async = false }
git.cli.stash.store.message(message).args(oid).call { async = false }
git.cli.stash.drop.args(stash).call { await = true }
git.cli.stash.store.message(message).args(oid).call { await = true }
end
end

View file

@ -145,26 +145,26 @@ end
---@class NeogitGitStatus
local status = {
stage = function(files)
git.cli.add.files(unpack(files)).call { async = false }
git.cli.add.files(unpack(files)).call { await = true }
end,
stage_modified = function()
git.cli.add.update.call { async = false }
git.cli.add.update.call { await = true }
end,
stage_untracked = function()
local paths = util.map(git.repo.state.untracked.items, function(item)
return item.escaped_path
end)
git.cli.add.files(unpack(paths)).call { async = false }
git.cli.add.files(unpack(paths)).call { await = true }
end,
stage_all = function()
git.cli.add.all.call { async = false }
git.cli.add.all.call { await = true }
end,
unstage = function(files)
git.cli.reset.files(unpack(files)).call { async = false }
git.cli.reset.files(unpack(files)).call { await = true }
end,
unstage_all = function()
git.cli.reset.call { async = false }
git.cli.reset.call { await = true }
end,
is_dirty = function()
return #git.repo.state.staged.items > 0 or #git.repo.state.unstaged.items > 0

View file

@ -13,7 +13,7 @@ end
---@param tags table List of tags
---@return boolean Successfully deleted
function M.delete(tags)
local result = git.cli.tag.delete.arg_list(tags).call()
local result = git.cli.tag.delete.arg_list(tags).call { await = true }
return result.code == 0
end

View file

@ -10,7 +10,7 @@ local M = {}
---@param path string absolute path
---@return boolean
function M.add(ref, path, params)
local result = git.cli.worktree.add.arg_list(params or {}).args(path, ref).call { async = false }
local result = git.cli.worktree.add.arg_list(params or {}).args(path, ref).call { await = true }
return result.code == 0
end
@ -19,7 +19,7 @@ end
---@param destination string absolute path for where to move worktree
---@return boolean
function M.move(worktree, destination)
local result = git.cli.worktree.move.args(worktree, destination).call()
local result = git.cli.worktree.move.args(worktree, destination).call { await = true }
return result.code == 0
end
@ -28,7 +28,8 @@ end
---@param args? table
---@return boolean
function M.remove(worktree, args)
local result = git.cli.worktree.remove.args(worktree).arg_list(args or {}).call { ignore_error = true }
local result =
git.cli.worktree.remove.args(worktree).arg_list(args or {}).call { ignore_error = true, await = true }
return result.code == 0
end

View file

@ -107,7 +107,7 @@ function M.checkout_branch_revision(popup)
return
end
git.cli.checkout.branch(selected_branch).arg_list(popup:get_arguments()).call { async = false }
git.cli.checkout.branch(selected_branch).arg_list(popup:get_arguments()).call { await = true }
fire_branch_event("NeogitBranchCheckout", { branch_name = selected_branch })
end
@ -176,7 +176,7 @@ function M.rename_branch()
return
end
git.cli.branch.move.args(selected_branch, new_name).call { async = false }
git.cli.branch.move.args(selected_branch, new_name).call { await = true }
notification.info(string.format("Renamed '%s' to '%s'", selected_branch, new_name))
fire_branch_event("NeogitBranchRename", { branch_name = selected_branch, new_name = new_name })