Skip to content

Commit

Permalink
Merge pull request #12 from lambdalisue/fix-windows
Browse files Browse the repository at this point in the history
Force slash path internally to fix behavior on Windows
  • Loading branch information
lambdalisue authored Jan 31, 2021
2 parents db931a5 + d470328 commit 5c9fc21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion autoload/fern_git_status.vim
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ function! s:on_redraw(helper) abort
\ 'stained_patterns': g:fern_git_status#stained_patterns,
\}
call fern_git_status#investigator#investigate(a:helper, options)
\.then({ m -> fern#logger#tap(m) })
\.then({ m -> map(a:helper.fern.visible_nodes, { -> s:update_node(m, v:val) }) })
\.then({ -> s:redraw(a:helper) })
\.catch({ e -> s:handle_error(e) })
endfunction

function! s:update_node(status_map, node) abort
let status = get(a:status_map, a:node._path, '')
let path = fern#internal#filepath#to_slash(a:node._path)
let status = get(a:status_map, path, '')
let a:node.badge = status ==# '' ? '' : printf(' [%s]', status)
return a:node
endfunction
Expand Down
17 changes: 17 additions & 0 deletions autoload/fern_git_status/process.vim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function! fern_git_status#process#show_toplevel(root, token) abort
\})
\.catch({e -> s:Promise.reject(s:normalize_error(e)) })
\.then({v -> join(v.stdout, '') })
\.then({v -> s:normalize_path(v) })
\.finally({ -> Profile() })
endfunction

Expand Down Expand Up @@ -61,5 +62,21 @@ function! s:parse_status(record) abort
let status = a:record[:1]
let relpath = split(a:record[3:], ' -> ')[-1]
let relpath = relpath[-1:] ==# '/' ? relpath[:-2] : relpath
let relpath = s:normalize_path(relpath)
return [relpath, status]
endfunction

" NOTE:
" Git for Windows return slash separated path but the path is
" not compatible with fern's slash separated path so normalization
" is required
if has('win32')
function! s:normalize_path(path) abort
let filepath = fern#internal#filepath#from_slash(a:path)
return fern#internal#filepath#to_slash(filepath)
endfunction
else
function! s:normalize_path(path) abort
return a:path
endfunction
endif

0 comments on commit 5c9fc21

Please sign in to comment.