From 0a2be9fb938d5b6421aa5e77aaf39e3a94e3e9d1 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Sat, 13 Apr 2019 16:31:16 +0800 Subject: [PATCH] Add layer option for git layer (#2583) * Add layer option for git layer * Change git diff command * Change git push * Add vim-dispatch --- autoload/SpaceVim/layers/git.vim | 36 ++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/layers/git.vim b/autoload/SpaceVim/layers/git.vim index e18c53c6c..0f5990e56 100644 --- a/autoload/SpaceVim/layers/git.vim +++ b/autoload/SpaceVim/layers/git.vim @@ -6,13 +6,28 @@ " License: GPLv3 "============================================================================= + +" Layer Options: +" s:git_plugin which plugin is used as the background plugin in git layer + + +if has('patch-8.0.0027') || has('nvim') + let s:git_plugin = 'gina' +else + let s:git_plugin = 'gita' +endif + + + function! SpaceVim#layers#git#plugins() abort let plugins = [ \ ['junegunn/gv.vim', { 'on_cmd' : ['GV']}], \ ] call add(plugins, ['tpope/vim-fugitive', { 'merged' : 0}]) - if has('patch-8.0.0027') || has('nvim') + if s:git_plugin ==# 'gina' call add(plugins, ['lambdalisue/gina.vim', { 'on_cmd' : 'Gina'}]) + elseif s:git_plugin ==# 'fugitive' + call add(plugins, ['tpope/vim-dispatch', { 'merged' : 0}]) else call add(plugins, ['lambdalisue/vim-gita', { 'on_cmd' : 'Gita'}]) endif @@ -25,7 +40,7 @@ endfunction function! SpaceVim#layers#git#config() abort let g:_spacevim_mappings_space.g = get(g:_spacevim_mappings_space, 'g', {'name' : '+VersionControl/git'}) - if has('patch-8.0.0027') || has('nvim') + if s:git_plugin ==# 'gina' call SpaceVim#mapping#space#def('nnoremap', ['g', 's'], 'Gina status --opener=10split', 'git status', 1) call SpaceVim#mapping#space#def('nnoremap', ['g', 'S'], 'Gina add %', 'stage current file', 1) call SpaceVim#mapping#space#def('nnoremap', ['g', 'U'], 'Gina reset -q %', 'unstage current file', 1) @@ -34,6 +49,15 @@ function! SpaceVim#layers#git#config() abort call SpaceVim#mapping#space#def('nnoremap', ['g', 'd'], 'Gina diff', 'view git diff', 1) call SpaceVim#mapping#space#def('nnoremap', ['g', 'A'], 'Gina add .', 'stage all files', 1) call SpaceVim#mapping#space#def('nnoremap', ['g', 'b'], 'Gina blame', 'view git blame', 1) + elseif s:git_plugin ==# 'fugitive' + call SpaceVim#mapping#space#def('nnoremap', ['g', 's'], 'Gstatus', 'git status', 1) + call SpaceVim#mapping#space#def('nnoremap', ['g', 'S'], 'Git add %', 'stage current file', 1) + call SpaceVim#mapping#space#def('nnoremap', ['g', 'U'], 'Git reset -q %', 'unstage current file', 1) + call SpaceVim#mapping#space#def('nnoremap', ['g', 'c'], 'Git commit', 'edit git commit', 1) + call SpaceVim#mapping#space#def('nnoremap', ['g', 'p'], 'Gpush', 'git push', 1) + call SpaceVim#mapping#space#def('nnoremap', ['g', 'd'], 'Gdiff', 'view git diff', 1) + call SpaceVim#mapping#space#def('nnoremap', ['g', 'A'], 'Git add .', 'stage all files', 1) + call SpaceVim#mapping#space#def('nnoremap', ['g', 'b'], 'Git blame', 'view git blame', 1) else call SpaceVim#mapping#space#def('nnoremap', ['g', 's'], 'Gita status', 'git status', 1) call SpaceVim#mapping#space#def('nnoremap', ['g', 'S'], 'Gita add %', 'stage current file', 1) @@ -60,6 +84,14 @@ function! SpaceVim#layers#git#config() abort call SpaceVim#mapping#space#def('nnoremap', ['g', 'v'], 'GV', 'View git log of current repo', 1) endfunction +function! SpaceVim#layers#git#set_variable(var) abort + + let s:git_plugin = get(a:var, + \ 'git-plugin', + \ s:git_plugin) + +endfunction + function! s:display_last_commit_of_current_line() abort let line = line('.') let file = expand('%')