Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions lua/neogit/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion tests/specs/neogit/popups/branch_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion tests/specs/neogit/popups/ignore_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion tests/specs/neogit/popups/log_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion tests/specs/neogit/popups/remote_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 18 additions & 1 deletion tests/specs/neogit/status_spec.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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)
)
Expand All @@ -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)
)
Expand All @@ -47,6 +49,7 @@ describe("status buffer", function()
in_prepared_repo(function()
find("Modified a%.txt")
act("<tab>jjs")
operations.wait("stage")
eq("MM a.txt\n", get_git_status("a.txt"))
eq(
[[--- a/a.txt
Expand All @@ -69,6 +72,7 @@ describe("status buffer", function()
in_prepared_repo(function()
find("Modified a%.txt")
act("<tab>8js")
operations.wait("stage")
eq("MM a.txt\n", get_git_status("a.txt"))
eq(
[[--- a/a.txt
Expand All @@ -90,6 +94,7 @@ describe("status buffer", function()
in_prepared_repo(function()
find("Modified a%.txt")
act("<tab>jjjjVs")
operations.wait("stage")
-- eq("M a.txt\n", get_git_status("a.txt"))
eq(
[[--- a/a.txt
Expand Down Expand Up @@ -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
Expand All @@ -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)
)
Expand All @@ -155,6 +162,7 @@ describe("status buffer", function()
in_prepared_repo(function()
find("Modified b%.txt")
act("<tab>jju")
operations.wait("unstage")
eq("MM b.txt\n", get_git_status("b.txt"))
eq(
[[--- a/b.txt
Expand All @@ -175,6 +183,7 @@ describe("status buffer", function()
in_prepared_repo(function()
find("Modified b%.txt")
act("<tab>jjjjVu")
operations.wait("unstage")
eq("MM b.txt\n", get_git_status("b.txt"))
eq(
[[--- a/b.txt
Expand All @@ -196,6 +205,7 @@ describe("status buffer", function()
in_prepared_repo(function()
find("Modified b%.txt")
act("<tab>8ju")
operations.wait("unstage")
eq("MM b.txt\n", get_git_status("b.txt"))
eq(
[[--- a/b.txt
Expand All @@ -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)
)
Expand All @@ -227,6 +238,7 @@ describe("status buffer", function()
in_prepared_repo(function()
find("Modified a%.txt")
act("<tab>jjx")
operations.wait("discard")
eq(" M a.txt\n", get_git_status("a.txt"))
eq(
[[--- a/a.txt
Expand All @@ -248,6 +260,7 @@ describe("status buffer", function()
in_prepared_repo(function()
find("Modified a%.txt")
act("<tab>jjjjVx")
operations.wait("discard")
eq(" M a.txt\n", get_git_status("a.txt"))
eq(
[[--- a/a.txt
Expand Down Expand Up @@ -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)
)
Expand All @@ -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)
)
Expand All @@ -293,6 +308,7 @@ describe("status buffer", function()
in_prepared_repo(function()
find("Modified b%.txt")
act("<tab>jjx")
operations.wait("discard")
eq("M b.txt\n", get_git_status("b.txt"))
eq(
[[--- a/b.txt
Expand All @@ -313,6 +329,7 @@ describe("status buffer", function()
in_prepared_repo(function()
find("Modified b%.txt")
act("<tab>jjjjVx")
operations.wait("discard")
eq("M b.txt\n", get_git_status("b.txt"))
eq(
[[--- a/b.txt
Expand Down