@@ -5,6 +5,8 @@ local fs_actions = require("neo-tree.sources.filesystem.lib.fs_actions")
5
5
local utils = require (" neo-tree.utils" )
6
6
local renderer = require (" neo-tree.ui.renderer" )
7
7
local events = require (" neo-tree.events" )
8
+ local inputs = require (" neo-tree.ui.inputs" )
9
+ local popups = require (" neo-tree.ui.popups" )
8
10
local log = require (" neo-tree.log" )
9
11
local help = require (" neo-tree.sources.common.help" )
10
12
local Preview = require (" neo-tree.sources.common.preview" )
@@ -205,6 +207,107 @@ M.cut_to_clipboard_visual = function(state, selected_nodes, callback)
205
207
end
206
208
end
207
209
210
+ ---- ----------------------------------------------------------------------------
211
+ -- Git commands
212
+ ---- ----------------------------------------------------------------------------
213
+
214
+ M .git_add_file = function (state )
215
+ local node = state .tree :get_node ()
216
+ if node .type == " message" then
217
+ return
218
+ end
219
+ local path = node :get_id ()
220
+ local cmd = { " git" , " add" , path }
221
+ vim .fn .system (cmd )
222
+ events .fire_event (events .GIT_EVENT )
223
+ end
224
+
225
+ M .git_add_all = function (state )
226
+ local cmd = { " git" , " add" , " -A" }
227
+ vim .fn .system (cmd )
228
+ events .fire_event (events .GIT_EVENT )
229
+ end
230
+
231
+ M .git_commit = function (state , and_push )
232
+ local width = vim .fn .winwidth (0 ) - 2
233
+ local row = vim .api .nvim_win_get_height (0 ) - 3
234
+ local popup_options = {
235
+ relative = " win" ,
236
+ position = {
237
+ row = row ,
238
+ col = 0 ,
239
+ },
240
+ size = width ,
241
+ }
242
+
243
+ inputs .input (" Commit message: " , " " , function (msg )
244
+ local cmd = { " git" , " commit" , " -m" , msg }
245
+ local title = " git commit"
246
+ local result = vim .fn .systemlist (cmd )
247
+ if vim .v .shell_error ~= 0 or (# result > 0 and vim .startswith (result [1 ], " fatal:" )) then
248
+ popups .alert (" ERROR: git commit" , result )
249
+ return
250
+ end
251
+ if and_push then
252
+ title = " git commit && git push"
253
+ cmd = { " git" , " push" }
254
+ local result2 = vim .fn .systemlist (cmd )
255
+ table.insert (result , " " )
256
+ for i = 1 , # result2 do
257
+ table.insert (result , result2 [i ])
258
+ end
259
+ end
260
+ events .fire_event (events .GIT_EVENT )
261
+ popups .alert (title , result )
262
+ end , popup_options )
263
+ end
264
+
265
+ M .git_commit_and_push = function (state )
266
+ M .git_commit (state , true )
267
+ end
268
+
269
+ M .git_push = function (state )
270
+ inputs .confirm (" Are you sure you want to push your changes?" , function (yes )
271
+ if yes then
272
+ local result = vim .fn .systemlist ({ " git" , " push" })
273
+ events .fire_event (events .GIT_EVENT )
274
+ popups .alert (" git push" , result )
275
+ end
276
+ end )
277
+ end
278
+
279
+ M .git_unstage_file = function (state )
280
+ local node = state .tree :get_node ()
281
+ if node .type == " message" then
282
+ return
283
+ end
284
+ local path = node :get_id ()
285
+ local cmd = { " git" , " reset" , " --" , path }
286
+ vim .fn .system (cmd )
287
+ events .fire_event (events .GIT_EVENT )
288
+ end
289
+
290
+ M .git_revert_file = function (state )
291
+ local node = state .tree :get_node ()
292
+ if node .type == " message" then
293
+ return
294
+ end
295
+ local path = node :get_id ()
296
+ local cmd = { " git" , " checkout" , " HEAD" , " --" , path }
297
+ local msg = string.format (" Are you sure you want to revert %s?" , node .name )
298
+ inputs .confirm (msg , function (yes )
299
+ if yes then
300
+ vim .fn .system (cmd )
301
+ events .fire_event (events .GIT_EVENT )
302
+ end
303
+ end )
304
+ end
305
+
306
+ ---- ----------------------------------------------------------------------------
307
+ -- END Git commands
308
+ ---- ----------------------------------------------------------------------------
309
+
310
+
208
311
M .next_source = function (state )
209
312
local sources = require (" neo-tree" ).config .sources
210
313
local next_source = sources [1 ]
0 commit comments