From 3d4f6374a276a76228289ccb766b4eb241b43828 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Tue, 17 Nov 2015 13:59:04 +0100 Subject: [PATCH 01/18] plugin/magit.vim: better handling of magit buffer, including clean quit command (fix #43) --- plugin/magit.vim | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index 46dc088..6abd5fb 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -583,11 +583,15 @@ function! magit#show_magit(display, ...) return endif if ( a:display == 'v' ) - vnew + vnew elseif ( a:display == 'h' ) - new + new elseif ( a:display == 'c' ) - enew + if ( bufname("%") == "" ) + keepalt enew + else + enew + endif else throw 'parameter_error' endif @@ -603,19 +607,21 @@ function! magit#show_magit(display, ...) let b:magit_default_fold_level = a:2 endif - if ( bufexists(g:magit_buffer_name) ) - silent! execute "bdelete " . g:magit_buffer_name - endif - silent! execute "file " . g:magit_buffer_name - setlocal buftype=nofile setlocal bufhidden=hide setlocal noswapfile setlocal foldmethod=syntax + setlocal nobuflisted let &l:foldlevel = b:magit_default_fold_level setlocal filetype=magit "setlocal readonly + try + silent execute "buffer " . g:magit_buffer_name + catch /^Vim\%((\a\+)\)\=:E94/ + silent execute "keepalt file " . g:magit_buffer_name + endtry + call magit#utils#setbufnr(bufnr(g:magit_buffer_name)) call magit#sign#init() From 4237501b9fe0c01e45dc3c9840f4d6f22ea93a3a Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Tue, 17 Nov 2015 14:04:03 +0100 Subject: [PATCH 02/18] plugin/magit.vim: add MagitOnly command --- README.md | 7 ++++++- doc/vimagit.txt | 8 ++++++-- plugin/magit.vim | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f3a9e76..dfdb400 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,12 @@ It takes 3 parameters: (see [g:magit_default_fold_level](#gmagit_default_fold_level)) #### :Magit - * open magit buffer. +open magit buffer in a vertical split + +#### :MagitOnly +open magit buffer in current window + +You can create a bash alias like magit="vim -c MagitOnly" ### Mappings diff --git a/doc/vimagit.txt b/doc/vimagit.txt index 863267e..5d8d65f 100644 --- a/doc/vimagit.txt +++ b/doc/vimagit.txt @@ -139,8 +139,12 @@ It takes 3 parameters: * foldlevel: set default magit buffer foldlevel for this session (see |vimagit-g:magit_default_fold_level|) - *:Magit* *magit#show_magit('v')* - :Magit open magit buffer + *:Magit* + :Magit open magit buffer in a vertical split + + *:MagitOnly* + :MagitOnly open magit buffer in current window +You can create a bash alias like magit="vim -c MagitOnly" MAPPINGS *vimagit-mappings* diff --git a/plugin/magit.vim b/plugin/magit.vim index 6abd5fb..87714b0 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -895,5 +895,6 @@ function! magit#commit_command(mode) endfunction command! Magit call magit#show_magit('v') +command! MagitOnly call magit#show_magit('c') " }}} From 982d161d7a0fc2e5163c36c6264678c9803cbb95 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Tue, 17 Nov 2015 18:53:52 +0100 Subject: [PATCH 03/18] plugin/magit.vim,autoload/{git,sign}.vim: magit can handle multiple git repository within one vim session (fix #44,#34,#29) it also adds the ability to open a magit buffer from a netrw buffer --- autoload/magit/git.vim | 56 ++++++++++++++++++++++----------------- autoload/magit/sign.vim | 2 -- plugin/magit.vim | 58 +++++++++++++++++++++++++++++------------ 3 files changed, 73 insertions(+), 43 deletions(-) diff --git a/autoload/magit/git.vim b/autoload/magit/git.vim index 0f54775..f57ca09 100644 --- a/autoload/magit/git.vim +++ b/autoload/magit/git.vim @@ -19,39 +19,47 @@ function! magit#git#get_status() return file_list endfunction -" s:magit_top_dir: top directory of git tree -" it is evaluated only once -" FIXME: it won't work when playing with multiple git directories wihtin one -" vim session -let s:magit_top_dir='' -" magit#git#top_dir: return the absolute path of current git worktree -" return top directory -function! magit#git#top_dir() - if ( s:magit_top_dir == '' ) - let s:magit_top_dir=magit#utils#strip( - \ system(s:git_cmd . " rev-parse --show-toplevel")) . "/" +" magit#git#set_top_dir: this function set b:magit_top_dir according to a path +" param[in] path: path to check if it is in a git repository +" return: 1 if path is in a git repo and b:magit_top_dir is set, 0 otherwise +function! magit#git#set_top_dir(path) + let dir = getcwd() + try + call magit#utils#lcd(a:path) + let top_dir=magit#utils#strip( + \ system(s:git_cmd . " rev-parse --show-toplevel")) . "/" if ( v:shell_error != 0 ) - echoerr "Git error: " . s:magit_top_dir + return 0 endif + let git_dir=magit#utils#strip(system(s:git_cmd . " rev-parse --git-dir")) . "/" + if ( v:shell_error != 0 ) + throw "magit: git_dir error " . b:magit_git_dir + endif + let b:magit_top_dir=top_dir + let b:magit_git_dir=git_dir + return 1 + finally + call magit#utils#lcd(dir) + endtry +endfunction + +" magit#git#top_dir: return the absolute path of current git worktree for the +" current magit buffer +" return top directory +function! magit#git#top_dir() + if ( !exists("b:magit_top_dir") ) + throw 'top_dir_not_set' endif - return s:magit_top_dir + return b:magit_top_dir endfunction -" s:magit_git_dir: git directory -" it is evaluated only once -" FIXME: it won't work when playing with multiple git directories wihtin one -" vim session -let s:magit_git_dir='' " magit#git#git_dir: return the absolute path of current git worktree " return git directory function! magit#git#git_dir() - if ( s:magit_git_dir == '' ) - let s:magit_git_dir=magit#utils#strip(system(s:git_cmd . " rev-parse --git-dir")) . "/" - if ( v:shell_error != 0 ) - echoerr "Git error: " . s:magit_git_dir - endif + if ( !exists("b:magit_git_dir") ) + throw 'git_dir_not_set' endif - return s:magit_git_dir + return b:magit_git_dir endfunction " magit#git#git_diff: helper function to get diff of a file diff --git a/autoload/magit/sign.vim b/autoload/magit/sign.vim index 7a53390..097e0c8 100644 --- a/autoload/magit/sign.vim +++ b/autoload/magit/sign.vim @@ -12,8 +12,6 @@ let s:dummy_sign_id = s:first_sign_id - 1 " Remove-all-signs optimisation requires Vim 7.3.596+. let s:supports_star = v:version > 703 || (v:version == 703 && has("patch596")) -let s:bufnr = bufnr(g:magit_buffer_name) - function! magit#sign#remove_all(...) if ( a:0 == 1 ) let pattern = a:1 diff --git a/plugin/magit.vim b/plugin/magit.vim index 87714b0..b1a225b 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -15,9 +15,6 @@ let g:loaded_magit = 1 " syntax files execute 'source ' . resolve(expand(':p:h')) . '/../common/magit_common.vim' -" g:magit_buffer_name: vim buffer name for vimagit -let g:magit_buffer_name = "magit-playground" - let s:state = deepcopy(magit#state#state) " these mappings are broadly applied, for all vim buffers @@ -125,8 +122,9 @@ function! s:mg_get_info() silent put ='' let branch=magit#utils#system("git rev-parse --abbrev-ref HEAD") let commit=magit#utils#system("git show -s --oneline") - silent put ='Current branch: ' . branch - silent put ='Last commit: ' . commit + silent put ='Current repository: ' . magit#git#top_dir() + silent put ='Current branch: ' . branch + silent put ='Last commit: ' . commit silent put ='' endfunction @@ -522,8 +520,9 @@ let s:mg_display_functions = { " 4. fills with unstage stuff " 5. restore window state function! magit#update_buffer() - if ( @% != g:magit_buffer_name ) - echoerr "Not in magit buffer " . g:magit_buffer_name . " but in " . @% + let buffer_name=bufname("%") + if ( buffer_name !~ 'magit://.*' ) + echoerr "Not in magit buffer but in " . buffer_name return endif " FIXME: find a way to save folding state. According to help, this won't @@ -578,10 +577,14 @@ endfunction " 'h': horizontal split " 'c': current buffer (should be used when opening vim in vimagit mode function! magit#show_magit(display, ...) - if ( magit#utils#strip(system("git rev-parse --is-inside-work-tree")) != 'true' ) - echoerr "Magit must be started from a git repository" - return + if ( &filetype == 'netrw' ) + let cur_file_path = b:netrw_curdir + else + let cur_file = expand("%:p") + let cur_file_path = isdirectory(cur_file) ? cur_file : fnamemodify(cur_file, ":h") endif + let try_paths = [ cur_file_path, getcwd() ] + if ( a:display == 'v' ) vnew elseif ( a:display == 'h' ) @@ -596,6 +599,33 @@ function! magit#show_magit(display, ...) throw 'parameter_error' endif + for path in try_paths + if ( magit#git#set_top_dir(path) == 1 ) + break + endif + endfor + try + let top_dir=magit#git#top_dir() + catch 'top_dir_not_set' + echohl ErrorMsg + echom "magit can not find any git repository" + echom "make sure that current opened file or vim current directory points to a git repository" + echom "search paths:" + for path in try_paths + echom path + endfor + echohl None + call magit#close_magit() + throw 'magit_not_in_git_repo' + endtry + + let buffer_name='magit://' . top_dir + try + silent execute "buffer " . buffer_name + catch /^Vim\%((\a\+)\)\=:E94/ + silent execute "keepalt file " . buffer_name + endtry + let b:magit_default_show_all_files = g:magit_default_show_all_files let b:magit_default_fold_level = g:magit_default_fold_level let b:magit_warning_max_lines_answered = 0 @@ -616,13 +646,7 @@ function! magit#show_magit(display, ...) setlocal filetype=magit "setlocal readonly - try - silent execute "buffer " . g:magit_buffer_name - catch /^Vim\%((\a\+)\)\=:E94/ - silent execute "keepalt file " . g:magit_buffer_name - endtry - - call magit#utils#setbufnr(bufnr(g:magit_buffer_name)) + call magit#utils#setbufnr(bufnr(buffer_name)) call magit#sign#init() execute "nnoremap " . g:magit_stage_file_mapping . " :call magit#stage_file()" From a5f468504b179d27bed5c29ccebded0c0d36508e Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Wed, 18 Nov 2015 14:03:17 +0100 Subject: [PATCH 04/18] plugin/magit.vim,autoload/git.vim: yet another rework of magit#show_magit() (fix #41) --- autoload/magit/git.vim | 30 +++++++++++++++++----- plugin/magit.vim | 56 ++++++++++++++++++++++-------------------- 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/autoload/magit/git.vim b/autoload/magit/git.vim index f57ca09..b009105 100644 --- a/autoload/magit/git.vim +++ b/autoload/magit/git.vim @@ -19,9 +19,28 @@ function! magit#git#get_status() return file_list endfunction -" magit#git#set_top_dir: this function set b:magit_top_dir according to a path -" param[in] path: path to check if it is in a git repository -" return: 1 if path is in a git repo and b:magit_top_dir is set, 0 otherwise +" magit#git#is_work_tree: this function check that path passed as parameter is +" inside a git work tree +" param[in] path: path to check +" return: top work tree path if in a work tree, empty string otherwise +function! magit#git#is_work_tree(path) + let dir = getcwd() + try + call magit#utils#lcd(a:path) + let top_dir=magit#utils#strip( + \ system(s:git_cmd . " rev-parse --show-toplevel")) . "/" + if ( v:shell_error != 0 ) + return '' + endif + return top_dir + finally + call magit#utils#lcd(dir) + endtry +endfunction + +" magit#git#set_top_dir: this function set b:magit_top_dir and b:magit_git_dir +" according to a path +" param[in] path: path to set. This path must be in a git repository work tree function! magit#git#set_top_dir(path) let dir = getcwd() try @@ -29,15 +48,14 @@ function! magit#git#set_top_dir(path) let top_dir=magit#utils#strip( \ system(s:git_cmd . " rev-parse --show-toplevel")) . "/" if ( v:shell_error != 0 ) - return 0 + throw "magit: git-show-toplevel error: " . top_dir endif let git_dir=magit#utils#strip(system(s:git_cmd . " rev-parse --git-dir")) . "/" if ( v:shell_error != 0 ) - throw "magit: git_dir error " . b:magit_git_dir + throw "magit: git-git-dir error: " . git_dir endif let b:magit_top_dir=top_dir let b:magit_git_dir=git_dir - return 1 finally call magit#utils#lcd(dir) endtry diff --git a/plugin/magit.vim b/plugin/magit.vim index b1a225b..9aaf55d 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -583,30 +583,17 @@ function! magit#show_magit(display, ...) let cur_file = expand("%:p") let cur_file_path = isdirectory(cur_file) ? cur_file : fnamemodify(cur_file, ":h") endif - let try_paths = [ cur_file_path, getcwd() ] - - if ( a:display == 'v' ) - vnew - elseif ( a:display == 'h' ) - new - elseif ( a:display == 'c' ) - if ( bufname("%") == "" ) - keepalt enew - else - enew - endif - else - throw 'parameter_error' - endif + let git_dir='' + let try_paths = [ cur_file_path, getcwd() ] for path in try_paths - if ( magit#git#set_top_dir(path) == 1 ) + let git_dir=magit#git#is_work_tree(path) + if ( git_dir != '' ) break endif endfor - try - let top_dir=magit#git#top_dir() - catch 'top_dir_not_set' + + if ( git_dir == '' ) echohl ErrorMsg echom "magit can not find any git repository" echom "make sure that current opened file or vim current directory points to a git repository" @@ -615,16 +602,31 @@ function! magit#show_magit(display, ...) echom path endfor echohl None - call magit#close_magit() throw 'magit_not_in_git_repo' - endtry + endif - let buffer_name='magit://' . top_dir - try - silent execute "buffer " . buffer_name - catch /^Vim\%((\a\+)\)\=:E94/ - silent execute "keepalt file " . buffer_name - endtry + let buffer_name='magit://' . git_dir + + if ( a:display == 'v' ) + silent execute "vnew " . buffer_name + elseif ( a:display == 'h' ) + silent execute "new " . buffer_name + elseif ( a:display == 'c' ) + if ( bufexists(buffer_name) ) + silent execute "buffer " . buffer_name + else + if ( bufname("%") == "" ) + keepalt enew + else + enew + endif + silent execute "file " . buffer_name + endif + else + throw 'parameter_error' + endif + + call magit#git#set_top_dir(git_dir) let b:magit_default_show_all_files = g:magit_default_show_all_files let b:magit_default_fold_level = g:magit_default_fold_level From 8f8bea6d8a540048b5dca728c54c3b2bb8377b06 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Wed, 18 Nov 2015 17:08:28 +0100 Subject: [PATCH 05/18] plugin/magit.vim: in show_magit(), always open buffer with :buffer command (fix #41) --- plugin/magit.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index 9aaf55d..fcbf02c 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -612,20 +612,20 @@ function! magit#show_magit(display, ...) elseif ( a:display == 'h' ) silent execute "new " . buffer_name elseif ( a:display == 'c' ) - if ( bufexists(buffer_name) ) - silent execute "buffer " . buffer_name - else + if ( !bufexists(buffer_name) ) if ( bufname("%") == "" ) keepalt enew else enew endif - silent execute "file " . buffer_name + execute "file " . buffer_name endif else throw 'parameter_error' endif + silent execute "buffer " . buffer_name + call magit#git#set_top_dir(git_dir) let b:magit_default_show_all_files = g:magit_default_show_all_files From 7bc4ccf70fb03274a3f931c3f0240246d08ed8f6 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Fri, 20 Nov 2015 10:22:06 +0100 Subject: [PATCH 06/18] state.vim: display modified files first --- autoload/magit/state.vim | 23 +++++++++++++++++++++-- plugin/magit.vim | 2 +- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/autoload/magit/state.vim b/autoload/magit/state.vim index 1be452b..4f2cbb4 100644 --- a/autoload/magit/state.vim +++ b/autoload/magit/state.vim @@ -304,13 +304,31 @@ function! magit#state#set_files_visible(is_visible) dict endfor endfunction -" magit#state#get_files: global dict getter function +" magit#state#get_files: global dict file objects getter function " param[in] mode: mode to select, can be 'staged' or 'unstaged' -" return all files belonging to mode +" return list of file objects belonging to mode function! magit#state#get_files(mode) dict return self.dict[a:mode] endfunction +" magit#state#get_filenames: global dict filenames getter function +" param[in] mode: mode to select, can be 'staged' or 'unstaged' +" return ordered list of filename strings belonging to mode, modified files +" first +function! magit#state#get_filenames(mode) dict + let modified = [] + let others = [] + for filename in sort(keys(self.dict[a:mode])) + let file = self.get_file(a:mode, filename) + if ( file.status == 'M' ) + call add(modified, filename) + else + call add(others, filename) + endif + endfor + return modified + others +endfunction + " dict: structure containing all diffs " It is formatted as follow @@ -330,6 +348,7 @@ let magit#state#state = { \ 'nb_diff_lines': 0, \ 'get_file': function("magit#state#get_file"), \ 'get_files': function("magit#state#get_files"), + \ 'get_filenames': function("magit#state#get_filenames"), \ 'add_file': function("magit#state#add_file"), \ 'set_files_visible': function("magit#state#set_files_visible"), \ 'check_max_lines': function("magit#state#check_max_lines"), diff --git a/plugin/magit.vim b/plugin/magit.vim index 87714b0..765deb5 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -140,7 +140,7 @@ endfunction function! s:mg_display_files(mode, curdir, depth) " FIXME: ouch, must store subdirs in more efficient way - for filename in sort(keys(s:state.get_files(a:mode))) + for filename in s:state.get_filenames(a:mode) let file = s:state.get_file(a:mode, filename, 0) if ( file.depth != a:depth || filename !~ a:curdir . '.*' ) continue From 5dc54b0614e84a8bbbad14f42883eec49e8741aa Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Fri, 20 Nov 2015 10:52:57 +0100 Subject: [PATCH 07/18] plugin/magit.vim: update inline help --- plugin/magit.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index 765deb5..4383f00 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -90,7 +90,7 @@ let s:magit_inline_help = { \'You will still be able to toggle inline help with h', \], \ 'commit': [ -\'CC,:w commit all staged changes with commit mode previously set (normal or', +\'CC commit all staged changes with commit mode previously set (normal or', \' amend) with message written in this section', \], \} From b971b18f8e094bb857ab58590b2a240dacf9dc5d Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Mon, 30 Nov 2015 20:58:39 +0100 Subject: [PATCH 08/18] plugin/magit.vim: disable inline help by default (fix #46) --- plugin/magit.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index 3de06e9..0cd9130 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -40,7 +40,7 @@ let g:magit_folding_close_mapping = get(g:, 'magit_folding_close_mapping', " user options let g:magit_enabled = get(g:, 'magit_enabled', 1) -let g:magit_show_help = get(g:, 'magit_show_help', 1) +let g:magit_show_help = get(g:, 'magit_show_help', 0) let g:magit_default_show_all_files = get(g:, 'magit_default_show_all_files', 1) let g:magit_default_fold_level = get(g:, 'magit_default_fold_level', 1) let g:magit_default_sections = get(g:, 'magit_default_sections', ['info', 'global_help', 'commit', 'staged', 'unstaged']) @@ -82,9 +82,6 @@ let s:magit_inline_help = { \'R refresh magit buffer', \'q close magit buffer', \'h toggle help showing in magit buffer', -\'', -\'To disable inline default appearance, add "let g:magit_show_help=0" to .vimrc', -\'You will still be able to toggle inline help with h', \], \ 'commit': [ \'CC commit all staged changes with commit mode previously set (normal or', @@ -126,6 +123,7 @@ function! s:mg_get_info() silent put ='Current branch: ' . branch silent put ='Last commit: ' . commit silent put ='' + silent put ='Press h to display help' endfunction " s:mg_display_files: display in current buffer files, filtered by some From d25ee9073584a8f73e92fa11870235da94a69310 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Mon, 30 Nov 2015 20:59:05 +0100 Subject: [PATCH 09/18] syntax/magit.vim: add some color in Info section --- common/magit_common.vim | 6 ++++++ plugin/magit.vim | 6 +++--- syntax/magit.vim | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/common/magit_common.vim b/common/magit_common.vim index 7773b0d..7232aa7 100644 --- a/common/magit_common.vim +++ b/common/magit_common.vim @@ -10,6 +10,12 @@ let g:magit_sections = { \ 'stash': 'Stash list' \ } +let g:magit_section_info = { + \ 'cur_repo': 'Current repository', + \ 'cur_branch': 'Current branch', + \ 'cur_commit': 'Last commit', + \ } + let g:magit_git_status_code = { \ 'M': 'modified', \ 'A': 'added', diff --git a/plugin/magit.vim b/plugin/magit.vim index 0cd9130..96595be 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -119,9 +119,9 @@ function! s:mg_get_info() silent put ='' let branch=magit#utils#system("git rev-parse --abbrev-ref HEAD") let commit=magit#utils#system("git show -s --oneline") - silent put ='Current repository: ' . magit#git#top_dir() - silent put ='Current branch: ' . branch - silent put ='Last commit: ' . commit + silent put =g:magit_section_info.cur_repo . ': ' . magit#git#top_dir() + silent put =g:magit_section_info.cur_branch . ': ' . branch + silent put =g:magit_section_info.cur_commit . ': ' . commit silent put ='' silent put ='Press h to display help' endfunction diff --git a/syntax/magit.vim b/syntax/magit.vim index e33e322..108810b 100644 --- a/syntax/magit.vim +++ b/syntax/magit.vim @@ -36,4 +36,20 @@ execute 'syn region gitHunk start=/' . \ g:magit_hunk_re . '/ end=/\%(' . g:magit_end_diff_re . '\|' . g:magit_hunk_re \ '\)\@=/ contains=@diff fold' +execute 'syn region gitInfo start=/^' . g:magit_sections.info . '$/ end=/' . + \ g:magit_section_re . '/' + +execute 'syn region gitInfoRepo start=/^' . g:magit_section_info.cur_repo . + \ ':\s*.*/hs=s+20 end=/$/ oneline' +highlight default link gitInfoRepo Directory +execute 'syn region gitInfoBranch start=/^' . g:magit_section_info.cur_branch . + \ ':\s*.*/hs=s+20 end=/$/ oneline' +highlight default link gitInfoBranch Identifier + +execute 'syn region gitInfoCommit start=/^' . g:magit_section_info.cur_commit . + \ ':\s*\(.*\)/ end=/$/ contains=infoSha1 oneline' +syntax match infoSha1 containedin=gitInfoCommit "\x\{7}" +highlight default link infoSha1 Identifier + + let b:current_syntax = "magit" From 77597be6850581d2d71fc51ce73960b9fb46b2c0 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Mon, 30 Nov 2015 22:19:57 +0100 Subject: [PATCH 10/18] plugin/magit.vim: add mappings N and P to jump to next and previous hunk (fix #25) --- README.md | 6 ++++++ doc/vimagit.txt | 9 +++++++++ plugin/magit.vim | 29 ++++++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dfdb400..9fff9a9 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,9 @@ Open magit buffer. All files diffs are hidden by default. To inspect changes in a file, move cursor to the filename line, and press 'Enter' in Normal mode. Diffs are displayed below the file name. +#### N +* Jump to next hunk with **N**. + #### S * Modify a file, for example foo.c, in your repository. @@ -184,6 +187,9 @@ Following mappings are set locally, for magit buffer only, in normal mode. * If cursor is in diff header, discard whole file at cursor position. * Only works in "Unstaged changes" section. +##### N,P + * Move to **N**ext or **P**revious hunk. + ##### CC * If not in commit section, set commit mode to "New commit" and show "Commit message" section with brand new commit message. * If in commit section, commit the all staged changes in commit mode previously set. diff --git a/doc/vimagit.txt b/doc/vimagit.txt index 5d8d65f..fb6576d 100644 --- a/doc/vimagit.txt +++ b/doc/vimagit.txt @@ -59,6 +59,11 @@ All files diffs are hidden by default. To inspect changes in a file, move cursor to the filename line, and press 'Enter' in Normal mode. Diffs are displayed below the file name. + N +----------- + +* Jump to next hunk with N. + S ----------- @@ -223,6 +228,10 @@ Following mappings are set locally, for magit buffer only, in normal mode. position. Only works in "Unstaged changes" section. + *vimagit-N* *magit#jump_hunk()* + *vimagit-P* + N,P Move to Next or Previous hunk. + *vimagit-CC* *magit#commit_command('CC')* *vimagit-g:magit_commit_mapping* CC If not in commit section, set commit mode to "New commit" and show diff --git a/plugin/magit.vim b/plugin/magit.vim index 96595be..9c2697b 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -38,6 +38,8 @@ let g:magit_folding_toggle_mapping = get(g:, 'magit_folding_toggle_mapping', let g:magit_folding_open_mapping = get(g:, 'magit_folding_open_mapping', [ 'zo', 'zO' ]) let g:magit_folding_close_mapping = get(g:, 'magit_folding_close_mapping', [ 'zc', 'zC' ]) +let g:magit_jump_next_hunk = get(g:, 'magit_jump_next_hunk', 'N') +let g:magit_jump_prev_hunk = get(g:, 'magit_jump_prev_hunk', 'P') " user options let g:magit_enabled = get(g:, 'magit_enabled', 1) let g:magit_show_help = get(g:, 'magit_show_help', 0) @@ -665,7 +667,10 @@ function! magit#show_magit(display, ...) execute "nnoremap " . g:magit_mark_line_mapping . " :call magit#mark_vselect()" execute "xnoremap " . g:magit_mark_line_mapping . " :call magit#mark_vselect()" - + + execute "nnoremap " . g:magit_jump_next_hunk . " :call magit#jump_hunk('N')" + execute "nnoremap " . g:magit_jump_prev_hunk . " :call magit#jump_hunk('P')" + for mapping in g:magit_folding_toggle_mapping " trick to pass '' in a mapping command without being interpreted let func_arg = ( mapping ==? "" ) ? '+' : mapping @@ -918,6 +923,28 @@ function! magit#commit_command(mode) call magit#update_buffer() endfunction +" magit#jump_hunk: function to jump among hunks +" it closes the current fold (if any), jump to next hunk and unfold it +" param[in] dir: can be 'N' (for next) or 'P' (for previous) +function! magit#jump_hunk(dir) + let back = ( a:dir == 'P' ) ? 'b' : '' + let line = search("^@@ ", back . 'wn') + if ( line != 0 ) + try + foldclose + catch /^Vim\%((\a\+)\)\=:E490/ + endtry + call cursor(line, 0) + try + foldopen + catch /^Vim\%((\a\+)\)\=:E490/ + echohl WarningMsg + echom "Warning: you should have jumped on a folded hunk" + echohl None + endtry + endif +endfunction + command! Magit call magit#show_magit('v') command! MagitOnly call magit#show_magit('c') From 1c25087af85bbc6f6858e152e37b2080dd42155f Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Mon, 30 Nov 2015 22:36:50 +0100 Subject: [PATCH 11/18] README,doc: misc changes --- README.md | 3 ++- doc/vimagit.txt | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9fff9a9..3c784ce 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Take a look at [TL;DR](#tldr) to start using it immediatly. * [x] Stage part of hunks, by visual select, lines or selecting bunch of lines with marks. * [x] Start to write the commit message in one key press, commit also in one key press. * [x] Modify in line the content just before staging it. -* [x] Visualize stashes. Apply, pop, drop are on going. +* [x] Move easily through hunks. * [x] Add file to .gitignore file. * [ ] Chase all corner cases. Please remember that vimagit is at an early development stage. If you try vimagit and nothing is working, please don't throw it, fill an [issue](https://github.com/jreybert/vimagit/issues/new) on github :heart: ! @@ -32,6 +32,7 @@ More to come: * Handle multiple git repositories within one vim session. * Stage multiple hunks or file by visually selecting them. * Go through history, cherry-pick changes. +* Handle stash: add, pop, apply, drop... * Vizualize and checkout branches. * Something is missing? Open an [issue](https://github.com/jreybert/vimagit/issues/new)! diff --git a/doc/vimagit.txt b/doc/vimagit.txt index fb6576d..de2de0b 100644 --- a/doc/vimagit.txt +++ b/doc/vimagit.txt @@ -239,23 +239,23 @@ Following mappings are set locally, for magit buffer only, in normal mode. If in commit section, commit the all staged changes in commit mode previously set. - *vimagit-CA* *magit#commit_command('CA')* + *vimagit-CA* *magit#commit_command('CA')* *vimagit-g:magit_commit_amend_mapping* CA If not in commit section, set commit mode to "Amend commit" and show "Commit message" section with previous commit message. If in commit section, commit the staged changes in commit mode previously set. - *vimagit-CF* *magit#commit_command('CF')* + *vimagit-CF* *magit#commit_command('CF')* *vimagit-g:magit_commit_fixup_mapping* CF Amend the staged changes into the previous commit, without modifying previous commit message - *vimagit-I* *magit#ignore_file()* + *vimagit-I* *magit#ignore_file()* *vimagit-g:magit_ignore_mapping* I Add the file under the cursor in .gitgnore - *vimagit-R* *magit#update_buffer()* + *vimagit-R* *magit#update_buffer()* *vimagit-g:magit_reload_mapping* R Refresh magit buffer. @@ -263,7 +263,7 @@ Following mappings are set locally, for magit buffer only, in normal mode. *vimagit-g:magit_close_mapping* q close magit buffer. - *vimagit-h* *magit#toggle_help()* + *vimagit-h* *magit#toggle_help()* *vimagit-g:magit_toggle_help_mapping* h Toggle help showing in magit buffer From 23d22250ac6a9b23c47d27c69ae281e17a95ea5b Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Mon, 30 Nov 2015 23:09:52 +0100 Subject: [PATCH 12/18] README,doc: add notes that magit handles multiple git repo --- README.md | 11 +++++++---- doc/vimagit.txt | 16 ++++++++++------ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 3c784ce..8fee851 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Take a look at [TL;DR](#tldr) to start using it immediatly. * [x] Start to write the commit message in one key press, commit also in one key press. * [x] Modify in line the content just before staging it. * [x] Move easily through hunks. +* [x] Handle multiple git repositories within one vim instance. * [x] Add file to .gitignore file. * [ ] Chase all corner cases. Please remember that vimagit is at an early development stage. If you try vimagit and nothing is working, please don't throw it, fill an [issue](https://github.com/jreybert/vimagit/issues/new) on github :heart: ! @@ -59,7 +60,7 @@ This is the minimal required set of command you must know to start playing with #### :Magit -Open magit buffer. +Open magit buffer (see [details](#magitshow_magit)). #### Enter,\ @@ -117,7 +118,9 @@ Visual selection and marked lines have some limitations for the moment: #### magit#show_magit() -Function to open magit buffer. +Function to open magit buffer. This buffer will handle the git repository including focused file. +It is possible to handle multiple git repositories within one vim instance. + It takes 3 parameters: * orientation (mandatory): it can be - 'v', curent window is split vertically, and magit is displayed in new @@ -131,10 +134,10 @@ It takes 3 parameters: (see [g:magit_default_fold_level](#gmagit_default_fold_level)) #### :Magit -open magit buffer in a vertical split +Open magit buffer in a vertical split (see [details](magitshow_magit)). #### :MagitOnly -open magit buffer in current window +Open magit buffer in current window (see [details](magitshow_magit)). You can create a bash alias like magit="vim -c MagitOnly" diff --git a/doc/vimagit.txt b/doc/vimagit.txt index de2de0b..7a4ba8f 100644 --- a/doc/vimagit.txt +++ b/doc/vimagit.txt @@ -50,7 +50,7 @@ with vimagit. See |vimagit-commands| for a complete description. :Magit ----------- -Open magit buffer. +Open magit buffer (see |magit#show_magit()|) Enter ----------- @@ -131,7 +131,11 @@ Visual selection and marked lines have some limitations for the moment: COMMANDS *vimagit-commands* *magit#show_magit()* -Function to open magit buffer. +Function to open magit buffer. This buffer will handle the git repository +including focused file. +It is possible to handle multiple git repositories within one vim instance. +Each git repository will have its own buffer. + It takes 3 parameters: * orientation (mandatory): it can be - 'v', curent window is split vertically, and magit is displayed in new @@ -144,11 +148,11 @@ It takes 3 parameters: * foldlevel: set default magit buffer foldlevel for this session (see |vimagit-g:magit_default_fold_level|) - *:Magit* - :Magit open magit buffer in a vertical split + *:Magit* + :Magit open magit buffer in a vertical split (see |magit#show_magit()|) - *:MagitOnly* - :MagitOnly open magit buffer in current window + *:MagitOnly* + :MagitOnly open magit buffer in current window (see |magit#show_magit()|) You can create a bash alias like magit="vim -c MagitOnly" From 49d424a687c4ba311fdb1a7799c683f973f6cb86 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Mon, 30 Nov 2015 23:40:06 +0100 Subject: [PATCH 13/18] Update Changelog --- Changelog | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 6 deletions(-) diff --git a/Changelog b/Changelog index ba0149b..606da83 100644 --- a/Changelog +++ b/Changelog @@ -1,16 +1,117 @@ +Release 1.5.0 +============= + +Features +-------- + +* vimagit is now able to handle multiple git repositories (fix #44,#34,#29). +* add mappings N and P to jump to next and previous hunk (fix #25). +* reorder magit display: display modified files first. +* disable inline help by default (fix #46). It is always possible to switch + inline help display with 'h', or with g:magit_show_help +* add some color in Info section. +* rename magit buffer, now named after git repository path, e.g. + magit:///path/to/git/repo/ +* add MagitOnly command. It can be used to craft a bash alias like: + alias magit='vim -c MagitOnly' + +Fixes +----- + +* safe and smart handling of quit command (fix #41,#43). + * close vimagit window if there is another window. + * switch to alternate buffer if any. + * close vim if magit buffer the only buffer. +* disable ':w' mapping, which was not safe. This feature will be re inserted + with a safer method later. + +Release 1.4.2 +============= + +Enhancements +------------ + +* smarter way to handle magit buffer: + * improve some internal mechanisms, which should improve performances for + huge repositories + * by default, do not show untracked/deleted/added/renamed files diffs (ref + #28) + * see g:magit_default_show_all_files new behavior +* add g:magit_default_sections to let user choose which sections are displayed + (fix #37) user can now choose which sections to display, and in which order + +Bug fixes +--------- + +* magit buffer become empty after switching to other window and back (#35) +* remove warning when opening magit buffer +* check that magit buffer exists before removing it (refs #39) + +Release 1.4.1 +============= + +Fixes +----- + +* fix add binary file (fixes #27) +* fix some display problem (Unstaged changes may not be highlighted) +* fix reset and discard for binary files + +Features +-------- + +* git works in a clean environment, without any configuration + +Release 1.4 +=========== + +This is a major step for vimagit. It should now contain all primary command +needed for staging. Then, this release should be the real 1.0 version. + +Features +-------- + +* Stage parts of hunk (fixes #8 and #19) + * select some with v, then stage your selection with S + * stage a single line with L + * mark lines (can be non contiguous) with M, then stage marked lines in + the hunk with S +* Stage single files in new directories (fixes #10) +* New options (fixes #18) + * g:magit_default_show_all_files to define if file diffs are shown or not + at magit buffer opening. + * If magit buffer contains more than g:magit_warning_max_lines (default + 10000) lines to display, user is asked if he wants to display all + these lines. + * g:magit_default_fold_level to define foldlevel of magit buffer. + * These options can be overriden with new magit#show_magit() parameters + (allowing user to define its own mappings/commands) +* File display is now sorted. +* Show submodule diffs (fixes #12) + +Fixes +----- + +No bugs have been reported since release 1.3. + Release 1.3 =========== Features -------- -* hide file diffs: to hide/unhide diffs for a file, move the cursor to the filename and press (Enter). It allows vimagit to be fast when there is a lot of diffs in a repository. +* hide file diffs: to hide/unhide diffs for a file, move the cursor to the + filename and press (Enter). It allows vimagit to be fast when there is a + lot of diffs in a repository. * zo, zO, zc, zC mappings on a filename hide/unhide file diffs. -* modify hunk before staging: in the Magit buffer, it is possible to modify a hunk before staging it. Only '+' lines can be modified. No lines can be deleted or added for the moment. (fixes #9). +* modify hunk before staging: in the Magit buffer, it is possible to modify a + hunk before staging it. Only '+' lines can be modified. No lines can be + deleted or added for the moment. (fixes #9). * handle new empty files and new symlink (fix #11). * handle binary files (fix #13). * stage/unstage/ignore/discard a file with cursor on the filename. -* add global mapping M to open magit buffer (it can be overwritten with g:magit_show_magit_mapping). +* add global mapping M to open magit buffer (it can be overwritten + with g:magit_show_magit_mapping). * remove 'C' default mapping. Fixes @@ -25,7 +126,8 @@ Release 1.2 Fixes ----- -* read COMMIT_EDITMSG only if exists (commit command failed for fresh new git directory) +* read COMMIT_EDITMSG only if exists (commit command failed for fresh new git + directory) * fix issue of some rare hunk staging (because of some whitespaces) Features @@ -40,8 +142,10 @@ Release 1.1 Fixes ----- -* add wrappers to system and systemlist, when vim doesn't support system with List (available since vim v7.4.248) -* fix git diff failing when cwd is not in top dir (it ends with an empty Magit buffer) +* add wrappers to system and systemlist, when vim doesn't support system with + List (available since vim v7.4.248) +* fix git diff failing when cwd is not in top dir (it ends with an empty Magit + buffer) * ensure to not use external diff if any * Check commentChar from git config From 80ac108ba07ad81c935bde007fad0fc16679d664 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Mon, 30 Nov 2015 23:58:31 +0100 Subject: [PATCH 14/18] syntax/magit.vim: rework section title color --- syntax/magit.vim | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/syntax/magit.vim b/syntax/magit.vim index 108810b..8e6b0be 100644 --- a/syntax/magit.vim +++ b/syntax/magit.vim @@ -9,14 +9,8 @@ syn sync minlines=50 syn include @diff syntax/diff.vim -execute 'syn match titleEntry "' . g:magit_section_re . '" contains=titleSign' -if has("conceal") - syn match titleSign contained "\%(&@\|@&\)" conceal -else - syn match titleSign contained "\%(&@\|@&\)" -endif -hi def link titleEntry String -hi def link titleSign Ignore +execute 'syn match titleEntry "' . g:magit_section_re . '\n=\+"' +hi def link titleEntry Comment execute 'syn match stashEntry "' . g:magit_stash_re . '"' hi def link stashEntry String From f777911f233ca65ea207819efd1d81f9ceb15065 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Tue, 1 Dec 2015 00:14:52 +0100 Subject: [PATCH 15/18] plugin/magit.vim: display commit mode in Info section --- common/magit_common.vim | 6 ++++++ plugin/magit.vim | 21 +++++++++------------ syntax/magit.vim | 3 +++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/common/magit_common.vim b/common/magit_common.vim index 7232aa7..718bb45 100644 --- a/common/magit_common.vim +++ b/common/magit_common.vim @@ -14,6 +14,7 @@ let g:magit_section_info = { \ 'cur_repo': 'Current repository', \ 'cur_branch': 'Current branch', \ 'cur_commit': 'Last commit', + \ 'commit_mode': 'Commit mode', \ } let g:magit_git_status_code = { @@ -31,6 +32,11 @@ let g:magit_git_status_code = { \ 'S': 'submodule', \ } +let g:magit_commit_mode = { + \ 'CC': 'normal', + \ 'CA': 'amend', + \ } + " Regular expressions used to select blocks let g:magit_file_re = '^\(' for status_code in values(g:magit_git_status_code) diff --git a/plugin/magit.vim b/plugin/magit.vim index 9c2697b..540ca16 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -121,9 +121,13 @@ function! s:mg_get_info() silent put ='' let branch=magit#utils#system("git rev-parse --abbrev-ref HEAD") let commit=magit#utils#system("git show -s --oneline") - silent put =g:magit_section_info.cur_repo . ': ' . magit#git#top_dir() - silent put =g:magit_section_info.cur_branch . ': ' . branch - silent put =g:magit_section_info.cur_commit . ': ' . commit + silent put =g:magit_section_info.cur_repo . ': ' . magit#git#top_dir() + silent put =g:magit_section_info.cur_branch . ': ' . branch + silent put =g:magit_section_info.cur_commit . ': ' . commit + if ( s:magit_commit_mode != '' ) + silent put =g:magit_section_info.commit_mode . ': ' + \ . g:magit_commit_mode[s:magit_commit_mode] + endif silent put ='' silent put ='Press h to display help' endfunction @@ -226,15 +230,8 @@ let s:magit_commit_mode='' " 'CA': get the last commit message function! s:mg_get_commit_section() if ( s:magit_commit_mode != '' ) - let commit_mode_str="" - if ( s:magit_commit_mode == 'CC' ) - let commit_mode_str="normal" - elseif ( s:magit_commit_mode == 'CA' ) - let commit_mode_str="amend" - endif silent put ='' silent put =g:magit_sections.commit_start - silent put ='Commit mode: '.commit_mode_str call mg_section_help('commit') silent put =magit#utils#underline(g:magit_sections.commit_start) silent put ='' @@ -324,7 +321,7 @@ function! s:mg_git_commit(mode) abort else let commit_section_pat_start='^'.g:magit_sections.commit_start.'$' let commit_section_pat_end='^'.g:magit_sections.commit_end.'$' - let commit_jump_line = 3 + mg_get_inline_help_line_nb('commit') + let commit_jump_line = 2 + mg_get_inline_help_line_nb('commit') let [start, end] = mg_search_block( \ [commit_section_pat_start, commit_jump_line], \ [ [commit_section_pat_end, -1] ], "") @@ -557,7 +554,7 @@ function! magit#update_buffer() if ( s:magit_commit_mode != '' ) let commit_section_pat_start='^'.g:magit_sections.commit_start.'$' silent! let section_line=search(commit_section_pat_start, "w") - silent! call cursor(section_line+3+mg_get_inline_help_line_nb('commit'), 0) + silent! call cursor(section_line+2+mg_get_inline_help_line_nb('commit'), 0) endif set filetype=magit diff --git a/syntax/magit.vim b/syntax/magit.vim index 8e6b0be..904d8d3 100644 --- a/syntax/magit.vim +++ b/syntax/magit.vim @@ -39,6 +39,9 @@ highlight default link gitInfoRepo Directory execute 'syn region gitInfoBranch start=/^' . g:magit_section_info.cur_branch . \ ':\s*.*/hs=s+20 end=/$/ oneline' highlight default link gitInfoBranch Identifier +execute 'syn region gitCommitMode start=/^' . g:magit_section_info.commit_mode . + \ ':\s*.*/hs=s+20 end=/$/ oneline' +highlight default link gitCommitMode Special execute 'syn region gitInfoCommit start=/^' . g:magit_section_info.cur_commit . \ ':\s*\(.*\)/ end=/$/ contains=infoSha1 oneline' From 78c2d56efb1c81644aa0fbfa445690d228136e28 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Tue, 1 Dec 2015 00:26:58 +0100 Subject: [PATCH 16/18] plugin/magit.vim: move s:state to buffer variable b:state --- plugin/magit.vim | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index 540ca16..c48f527 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -15,8 +15,6 @@ let g:loaded_magit = 1 " syntax files execute 'source ' . resolve(expand(':p:h')) . '/../common/magit_common.vim' -let s:state = deepcopy(magit#state#state) - " these mappings are broadly applied, for all vim buffers let g:magit_show_magit_mapping = get(g:, 'magit_show_magit_mapping', 'M' ) @@ -142,8 +140,8 @@ endfunction function! s:mg_display_files(mode, curdir, depth) " FIXME: ouch, must store subdirs in more efficient way - for filename in s:state.get_filenames(a:mode) - let file = s:state.get_file(a:mode, filename, 0) + for filename in b:state.get_filenames(a:mode) + let file = b:state.get_file(a:mode, filename, 0) if ( file.depth != a:depth || filename !~ a:curdir . '.*' ) continue endif @@ -177,7 +175,7 @@ function! s:mg_display_files(mode, curdir, depth) endfunction " s:mg_get_staged_section: this function writes in current buffer all staged -" or unstaged files, using s:state.dict information +" or unstaged files, using b:state.dict information " WARNING: this function writes in file, it should only be called through " protected functions like magit#update_buffer " param[in] mode: 'staged' or 'unstaged' @@ -392,7 +390,7 @@ function! s:mg_create_diff_from_select(select_lines) endif let section=mg_get_section() let filename=mg_get_filename() - let hunks = s:state.get_file(section, filename).get_hunks() + let hunks = b:state.get_file(section, filename).get_hunks() for hunk in hunks if ( hunk.header == getline(starthunk) ) let current_hunk = hunk @@ -490,7 +488,7 @@ function! magit#open_close_folding(...) let section=mg_get_section() " if first param is set, force visible to this value " else, toggle value - let file = s:state.get_file(section, filename, 0) + let file = b:state.get_file(section, filename, 0) if ( a:0 == 1 ) call file.set_visible(a:1) else @@ -535,7 +533,7 @@ function! magit#update_buffer() " delete buffer silent! execute "silent :%delete _" - call s:state.update() + call b:state.update() for section in g:magit_default_sections try @@ -645,6 +643,8 @@ function! magit#show_magit(display, ...) setlocal filetype=magit "setlocal readonly + let b:state = deepcopy(g:magit#state#state) + call magit#utils#setbufnr(bufnr(buffer_name)) call magit#sign#init() @@ -702,7 +702,7 @@ function! s:mg_stage_closed_file(discard) let filename = list[2] let section=mg_get_section() - let file = s:state.get_file(section, filename) + let file = b:state.get_file(section, filename) if ( file.is_visible() == 0 || \ file.is_dir() == 1 ) if ( a:discard == 0 ) @@ -739,9 +739,9 @@ endfunction function! magit#stage_block(selection, discard) abort let section=mg_get_section() let filename=mg_get_filename() - let header = s:state.get_file(section, filename).get_header() + let header = b:state.get_file(section, filename).get_header() - let file = s:state.get_file(section, filename, 0) + let file = b:state.get_file(section, filename, 0) if ( a:discard == 0 ) if ( section == 'unstaged' ) if ( file.must_be_added() ) From c74160bea4c206f87afb03ddee43e2d260292c65 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Tue, 1 Dec 2015 00:30:19 +0100 Subject: [PATCH 17/18] plugin/magit.vim: move s:magit_commit_mode to buffer variable b:magit_current_commit_mode --- plugin/magit.vim | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/plugin/magit.vim b/plugin/magit.vim index c48f527..c50ccf4 100644 --- a/plugin/magit.vim +++ b/plugin/magit.vim @@ -122,9 +122,9 @@ function! s:mg_get_info() silent put =g:magit_section_info.cur_repo . ': ' . magit#git#top_dir() silent put =g:magit_section_info.cur_branch . ': ' . branch silent put =g:magit_section_info.cur_commit . ': ' . commit - if ( s:magit_commit_mode != '' ) + if ( b:magit_current_commit_mode != '' ) silent put =g:magit_section_info.commit_mode . ': ' - \ . g:magit_commit_mode[s:magit_commit_mode] + \ . g:magit_commit_mode[b:magit_current_commit_mode] endif silent put ='' silent put ='Press h to display help' @@ -211,23 +211,16 @@ function! s:mg_get_stashes() endif endfunction -" s:magit_commit_mode: global variable which states in which commit mode we are -" values are: -" '': not in commit mode -" 'CC': normal commit mode, next commit command will create a new commit -" 'CA': amend commit mode, next commit command will ament current commit -" 'CF': fixup commit mode, it should not be a global state mode -let s:magit_commit_mode='' " s:mg_get_commit_section: this function writes in current buffer the commit -" section. It is a commit message, depending on s:magit_commit_mode +" section. It is a commit message, depending on b:magit_current_commit_mode " WARNING: this function writes in file, it should only be called through " protected functions like magit#update_buffer -" param[in] s:magit_commit_mode: this function uses global commit mode +" param[in] b:magit_current_commit_mode: this function uses global commit mode " 'CC': prepare a brand new commit message " 'CA': get the last commit message function! s:mg_get_commit_section() - if ( s:magit_commit_mode != '' ) + if ( b:magit_current_commit_mode != '' ) silent put ='' silent put =g:magit_sections.commit_start call mg_section_help('commit') @@ -236,9 +229,9 @@ function! s:mg_get_commit_section() let git_dir=magit#git#git_dir() " refresh the COMMIT_EDITMSG file - if ( s:magit_commit_mode == 'CC' ) + if ( b:magit_current_commit_mode == 'CC' ) silent! call magit#utils#system("GIT_EDITOR=/bin/false git commit -e 2> /dev/null") - elseif ( s:magit_commit_mode == 'CA' ) + elseif ( b:magit_current_commit_mode == 'CA' ) silent! call magit#utils#system("GIT_EDITOR=/bin/false git commit --amend -e 2> /dev/null") endif if ( filereadable(git_dir . 'COMMIT_EDITMSG') ) @@ -549,7 +542,7 @@ function! magit#update_buffer() call winrestview(l:winview) - if ( s:magit_commit_mode != '' ) + if ( b:magit_current_commit_mode != '' ) let commit_section_pat_start='^'.g:magit_sections.commit_start.'$' silent! let section_line=search(commit_section_pat_start, "w") silent! call cursor(section_line+2+mg_get_inline_help_line_nb('commit'), 0) @@ -644,6 +637,13 @@ function! magit#show_magit(display, ...) "setlocal readonly let b:state = deepcopy(g:magit#state#state) + " s:magit_commit_mode: global variable which states in which commit mode we are + " values are: + " '': not in commit mode + " 'CC': normal commit mode, next commit command will create a new commit + " 'CA': amend commit mode, next commit command will ament current commit + " 'CF': fixup commit mode, it should not be a global state mode + let b:magit_current_commit_mode='' call magit#utils#setbufnr(bufnr(buffer_name)) call magit#sign#init() @@ -896,25 +896,25 @@ endfunction " magit#commit_command: entry function for commit mode " INFO: it has a different effect if current section is commit section or not " param[in] mode: commit mode -" 'CF': do not set global s:magit_commit_mode, directly call magit#git_commit +" 'CF': do not set global b:magit_current_commit_mode, directly call magit#git_commit " 'CA'/'CF': if in commit section mode, call magit#git_commit, else just set -" global state variable s:magit_commit_mode, +" global state variable b:magit_current_commit_mode, function! magit#commit_command(mode) if ( a:mode == 'CF' ) call mg_git_commit(a:mode) else let section=mg_get_section() if ( section == 'commit_start' ) - if ( s:magit_commit_mode == '' ) + if ( b:magit_current_commit_mode == '' ) echoerr "Error, commit section should not be enabled" return endif " when we do commit, it is prefered ot commit the way we prepared it " (.i.e normal or amend), whatever we commit with CC or CA. - call mg_git_commit(s:magit_commit_mode) - let s:magit_commit_mode='' + call mg_git_commit(b:magit_current_commit_mode) + let b:magit_current_commit_mode='' else - let s:magit_commit_mode=a:mode + let b:magit_current_commit_mode=a:mode endif endif call magit#update_buffer() From d1b6b4cdc0bd20836fdd88882656f76cdce9e6b1 Mon Sep 17 00:00:00 2001 From: Jerome Reybert Date: Tue, 1 Dec 2015 00:32:40 +0100 Subject: [PATCH 18/18] Update Changelog --- Changelog | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 606da83..d5c9d7f 100644 --- a/Changelog +++ b/Changelog @@ -9,7 +9,8 @@ Features * reorder magit display: display modified files first. * disable inline help by default (fix #46). It is always possible to switch inline help display with 'h', or with g:magit_show_help -* add some color in Info section. +* rework magit buffer color syntax. +* display commit mode in Info section. * rename magit buffer, now named after git repository path, e.g. magit:///path/to/git/repo/ * add MagitOnly command. It can be used to craft a bash alias like: