|
| 1 | +let s:Process = vital#fern#import('Async.Promise.Process') |
| 2 | + |
| 3 | +function! fern#scheme#file#mapping#git#init(disable_default_mappings) abort |
| 4 | + nnoremap <buffer><silent> <Plug>(fern-action-git-stage) :<C-u>call <SID>call('stage')<CR> |
| 5 | + nnoremap <buffer><silent> <Plug>(fern-action-git-unstage) :<C-u>call <SID>call('unstage')<CR> |
| 6 | +
|
| 7 | + if !a:disable_default_mappings |
| 8 | + \ && !g:fern#scheme#file#mapping#git#disable_default_mappings |
| 9 | + nmap <buffer><nowait> << <Plug>(fern-action-git-stage) |
| 10 | + nmap <buffer><nowait> >> <Plug>(fern-action-git-unstage) |
| 11 | + endif |
| 12 | +endfunction |
| 13 | + |
| 14 | +function! s:call(name, ...) abort |
| 15 | + return call( |
| 16 | + \ 'fern#mapping#call', |
| 17 | + \ [funcref(printf('s:map_%s', a:name))] + a:000, |
| 18 | + \) |
| 19 | +endfunction |
| 20 | + |
| 21 | +function! s:map_stage(helper) abort |
| 22 | + if a:helper.sync.get_scheme() !=# 'file' |
| 23 | + throw printf("git-stage action requires 'file' scheme") |
| 24 | + endif |
| 25 | + let root = a:helper.sync.get_root_node() |
| 26 | + let nodes = a:helper.sync.get_selected_nodes() |
| 27 | + let nodes = empty(nodes) ? [a:helper.sync.get_cursor_node()] : nodes |
| 28 | + let paths = map(copy(nodes), { -> v:val._path }) |
| 29 | + |
| 30 | + call s:Process.start(['git', '-C', root._path, 'add', '--ignore-errors', '--'] + paths) |
| 31 | + \.then({ -> a:helper.async.update_marks([]) }) |
| 32 | + \.then({ -> a:helper.async.redraw() }) |
| 33 | +endfunction |
| 34 | + |
| 35 | +function! s:map_unstage(helper) abort |
| 36 | + if a:helper.sync.get_scheme() !=# 'file' |
| 37 | + throw printf("git-unstage action requires 'file' scheme") |
| 38 | + endif |
| 39 | + let root = a:helper.sync.get_root_node() |
| 40 | + let nodes = a:helper.sync.get_selected_nodes() |
| 41 | + let nodes = empty(nodes) ? [a:helper.sync.get_cursor_node()] : nodes |
| 42 | + let paths = map(copy(nodes), { -> v:val._path }) |
| 43 | + |
| 44 | + call s:Process.start(['git', '-C', root._path, 'reset', '--quiet', '--'] + paths) |
| 45 | + \.then({ -> a:helper.async.update_marks([]) }) |
| 46 | + \.then({ -> a:helper.async.redraw() }) |
| 47 | +endfunction |
| 48 | + |
| 49 | + |
| 50 | +let g:fern#scheme#file#mapping#git#disable_default_mappings = get(g:, 'fern#scheme#file#mapping#git#disable_default_mappings', 0) |
0 commit comments