forked from NeogitOrg/neogit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.lua
66 lines (50 loc) · 1.32 KB
/
actions.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local git = require("neogit.lib.git")
local operation = require("neogit.operations")
local FuzzyFinderBuffer = require("neogit.buffers.fuzzy_finder")
local StashListBuffer = require("neogit.buffers.stash_list_view")
local M = {}
M.both = operation("stash_both", function(popup)
git.stash.stash_all(popup:get_arguments())
end)
M.index = operation("stash_index", function(popup)
git.stash.stash_index(popup:get_arguments())
end)
function M.push(popup)
local files = FuzzyFinderBuffer.new(git.files.all()):open_async { allow_multi = true }
if not files or not files[1] then
return
end
git.stash.push(popup:get_arguments(), files)
end
local function use(action, stash)
local name
if stash and stash.name then
name = stash.name
else
name = FuzzyFinderBuffer.new(git.stash.list()):open_async()
if not name then
return
end
name = name:match("(stash@{%d+})")
end
if name then
git.stash[action](name)
end
end
function M.pop(popup)
use("pop", popup.state.env.stash)
end
function M.apply(popup)
use("apply", popup.state.env.stash)
end
function M.drop(popup)
use("drop", popup.state.env.stash)
end
--- git stash list
function M.list(popup)
StashListBuffer.new():open()
end
M.rename = operation("stash_rename", function(popup)
use("rename", popup.state.env.stash)
end)
return M