Skip to content
Snippets Groups Projects
Commit fb8c66a3 authored by Jerome Reybert's avatar Jerome Reybert
Browse files

autoload/magit/state.vim: cd top dir when looking for file state

parent 04651213
Branches
Tags
No related merge requests found
...@@ -88,6 +88,9 @@ endfunction ...@@ -88,6 +88,9 @@ endfunction
" param[in] status: one character status code of the file (AMDRCU?) " param[in] status: one character status code of the file (AMDRCU?)
" param[in] filename: filename " param[in] filename: filename
function! magit#state#add_file(mode, status, filename) dict function! magit#state#add_file(mode, status, filename) dict
let dir = getcwd()
try
call magit#utils#lcd(magit#utils#top_dir())
let dev_null = ( a:status == '?' ) ? " /dev/null " : " " let dev_null = ( a:status == '?' ) ? " /dev/null " : " "
let staged_flag = ( a:mode == 'staged' ) ? " --staged " : " " let staged_flag = ( a:mode == 'staged' ) ? " --staged " : " "
let diff_cmd="git diff --no-ext-diff " . staged_flag . let diff_cmd="git diff --no-ext-diff " . staged_flag .
...@@ -135,6 +138,9 @@ function! magit#state#add_file(mode, status, filename) dict ...@@ -135,6 +138,9 @@ function! magit#state#add_file(mode, status, filename) dict
call add(hunk.lines, diff_line) call add(hunk.lines, diff_line)
endfor endfor
endif endif
finally
call magit#utils#lcd(dir)
endtry
endfunction endfunction
" magit#state#update: update self.dict " magit#state#update: update self.dict
......
...@@ -36,6 +36,10 @@ endfunction ...@@ -36,6 +36,10 @@ endfunction
" s:magit_cd_cmd: plugin variable to choose lcd/cd command, 'lcd' if exists, " s:magit_cd_cmd: plugin variable to choose lcd/cd command, 'lcd' if exists,
" 'cd' otherwise " 'cd' otherwise
let s:magit_cd_cmd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd ' let s:magit_cd_cmd = exists('*haslocaldir') && haslocaldir() ? 'lcd ' : 'cd '
" magit#utils#lcd: helper function to lcd. use cd if lcd doesn't exists
function! magit#utils#lcd(dir)
execute s:magit_cd_cmd . a:dir
endfunction
" magit#utils#system: wrapper for system, which only takes String as input in vim, " magit#utils#system: wrapper for system, which only takes String as input in vim,
" although it can take String or List input in neovim. " although it can take String or List input in neovim.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment