diff --git a/lua/neogit/status.lua b/lua/neogit/status.lua index c9540a6b1..d3c00ea4a 100644 --- a/lua/neogit/status.lua +++ b/lua/neogit/status.lua @@ -14,6 +14,7 @@ local fs = require("neogit.lib.fs") local input = require("neogit.lib.input") local util = require("neogit.lib.util") local watcher = require("neogit.watcher") +local operation = require("neogit.operations") local api = vim.api local fn = vim.fn @@ -22,7 +23,6 @@ local M = {} M.disabled = false -M.current_operation = nil M.prev_autochdir = nil M.status_buffer = nil M.commit_view = nil @@ -826,9 +826,7 @@ function M.get_selection() return setmetatable(res, Selection) end -local stage = function() - M.current_operation = "stage" - +local stage = operation("stage", function() local selection = M.get_selection() local mode = vim.api.nvim_get_mode() @@ -868,19 +866,15 @@ local stage = function() git.index.add(files) end - M.current_operation = nil - refresh({ status = true, diffs = vim.tbl_map(function(v) return "*:" .. v.name end, selection.items), }, "stage_finish") -end - -local unstage = function() - M.current_operation = "unstage" +end) +local unstage = operation("unstage", function() local selection = M.get_selection() local mode = vim.api.nvim_get_mode() @@ -918,15 +912,13 @@ local unstage = function() git.status.unstage(files) end - M.current_operation = nil - refresh({ status = true, diffs = vim.tbl_map(function(v) return "*:" .. v.name end, selection.items), }, "unstage_finish") -end +end) local function discard_message(files, hunk_count) if hunk_count > 0 then @@ -938,9 +930,7 @@ local function discard_message(files, hunk_count) end end -local function discard() - M.current_operation = "discard" - +local discard = operation("discard", function() local selection = M.get_selection() local mode = vim.api.nvim_get_mode() @@ -1013,9 +1003,7 @@ local function discard() a.util.scheduler() vim.cmd("checktime") - - M.current_operation = nil -end +end) local set_folds = function(to) Collection.new(M.locations):each(function(l) @@ -1481,10 +1469,4 @@ function M.get_status() return M.status end -function M.wait_on_current_operation(ms) - vim.wait(ms or 1000, function() - return not M.current_operation - end) -end - return M diff --git a/tests/specs/neogit/popups/branch_spec.lua b/tests/specs/neogit/popups/branch_spec.lua index 599a6d8bf..fb81daace 100644 --- a/tests/specs/neogit/popups/branch_spec.lua +++ b/tests/specs/neogit/popups/branch_spec.lua @@ -16,7 +16,6 @@ local input = require("tests.mocks.input") local function act(normal_cmd) vim.fn.feedkeys(vim.api.nvim_replace_termcodes(normal_cmd, true, true, true)) vim.fn.feedkeys("", "x") -- flush typeahead - status.wait_on_current_operation() end describe("branch popup", function() diff --git a/tests/specs/neogit/popups/ignore_spec.lua b/tests/specs/neogit/popups/ignore_spec.lua index a4328005a..fba041466 100644 --- a/tests/specs/neogit/popups/ignore_spec.lua +++ b/tests/specs/neogit/popups/ignore_spec.lua @@ -9,7 +9,6 @@ local status = require("neogit.status") local function act(normal_cmd) vim.fn.feedkeys(vim.api.nvim_replace_termcodes(normal_cmd, true, true, true)) vim.fn.feedkeys("", "x") -- flush typeahead - status.wait_on_current_operation() end describe("ignore popup", function() diff --git a/tests/specs/neogit/popups/log_spec.lua b/tests/specs/neogit/popups/log_spec.lua index 5516e1980..316dca279 100644 --- a/tests/specs/neogit/popups/log_spec.lua +++ b/tests/specs/neogit/popups/log_spec.lua @@ -12,7 +12,6 @@ local input = require("tests.mocks.input") local function act(normal_cmd) vim.fn.feedkeys(vim.api.nvim_replace_termcodes(normal_cmd, true, true, true)) vim.fn.feedkeys("", "x") -- flush typeahead - status.wait_on_current_operation() end describe("log popup", function() diff --git a/tests/specs/neogit/popups/remote_spec.lua b/tests/specs/neogit/popups/remote_spec.lua index 2996d0b6e..5e4a36bc9 100644 --- a/tests/specs/neogit/popups/remote_spec.lua +++ b/tests/specs/neogit/popups/remote_spec.lua @@ -11,7 +11,6 @@ local lib = require("neogit.lib") local function act(normal_cmd) vim.fn.feedkeys(vim.api.nvim_replace_termcodes(normal_cmd, true, true, true)) vim.fn.feedkeys("", "x") -- flush typeahead - status.wait_on_current_operation() end describe("remote popup", function() diff --git a/tests/specs/neogit/status_spec.lua b/tests/specs/neogit/status_spec.lua index 51870a280..fe0641625 100644 --- a/tests/specs/neogit/status_spec.lua +++ b/tests/specs/neogit/status_spec.lua @@ -1,5 +1,6 @@ local eq = assert.are.same local status = require("neogit.status") +local operations = require("neogit.operations") local harness = require("tests.util.git_harness") local _ = require("tests.mocks.input") local in_prepared_repo = harness.in_prepared_repo @@ -9,7 +10,6 @@ local get_git_diff = harness.get_git_diff local function act(normal_cmd) vim.fn.feedkeys(vim.api.nvim_replace_termcodes(normal_cmd, true, true, true)) vim.fn.feedkeys("", "x") -- flush typeahead - status.wait_on_current_operation() end local function find(text) @@ -28,6 +28,7 @@ describe("status buffer", function() in_prepared_repo(function() find("untracked%.txt") act("s") + operations.wait("stage") eq("A untracked.txt\n", get_git_status("untracked.txt")) end) ) @@ -38,6 +39,7 @@ describe("status buffer", function() find("Modified a%.txt") eq(" M a.txt\n", get_git_status("a.txt")) act("s") + operations.wait("stage") eq("M a.txt\n", get_git_status("a.txt")) end) ) @@ -47,6 +49,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified a%.txt") act("jjs") + operations.wait("stage") eq("MM a.txt\n", get_git_status("a.txt")) eq( [[--- a/a.txt @@ -69,6 +72,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified a%.txt") act("8js") + operations.wait("stage") eq("MM a.txt\n", get_git_status("a.txt")) eq( [[--- a/a.txt @@ -90,6 +94,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified a%.txt") act("jjjjVs") + operations.wait("stage") -- eq("M a.txt\n", get_git_status("a.txt")) eq( [[--- a/a.txt @@ -122,6 +127,7 @@ describe("status buffer", function() --- 6 -It exists... --- 7 +This is a change act("V6js") + operations.wait("stage") eq( [[--- a/a.txt +++ b/a.txt @@ -146,6 +152,7 @@ describe("status buffer", function() find("Modified b%.txt") eq("M b.txt\n", get_git_status("b.txt")) act("u") + operations.wait("unstage") eq(" M b.txt\n", get_git_status("b.txt")) end) ) @@ -155,6 +162,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified b%.txt") act("jju") + operations.wait("unstage") eq("MM b.txt\n", get_git_status("b.txt")) eq( [[--- a/b.txt @@ -175,6 +183,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified b%.txt") act("jjjjVu") + operations.wait("unstage") eq("MM b.txt\n", get_git_status("b.txt")) eq( [[--- a/b.txt @@ -196,6 +205,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified b%.txt") act("8ju") + operations.wait("unstage") eq("MM b.txt\n", get_git_status("b.txt")) eq( [[--- a/b.txt @@ -218,6 +228,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified a%.txt") act("x") + operations.wait("discard") eq("", get_git_status("a.txt")) end) ) @@ -227,6 +238,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified a%.txt") act("jjx") + operations.wait("discard") eq(" M a.txt\n", get_git_status("a.txt")) eq( [[--- a/a.txt @@ -248,6 +260,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified a%.txt") act("jjjjVx") + operations.wait("discard") eq(" M a.txt\n", get_git_status("a.txt")) eq( [[--- a/a.txt @@ -275,6 +288,7 @@ describe("status buffer", function() in_prepared_repo(function() find("untracked%.txt") act("x") + operations.wait("discard") eq("", get_git_status("untracked.txt")) end) ) @@ -284,6 +298,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified b%.txt") act("x") + operations.wait("discard") eq("", get_git_status("b.txt")) end) ) @@ -293,6 +308,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified b%.txt") act("jjx") + operations.wait("discard") eq("M b.txt\n", get_git_status("b.txt")) eq( [[--- a/b.txt @@ -313,6 +329,7 @@ describe("status buffer", function() in_prepared_repo(function() find("Modified b%.txt") act("jjjjVx") + operations.wait("discard") eq("M b.txt\n", get_git_status("b.txt")) eq( [[--- a/b.txt