Skip to content

Commit

Permalink
Merge pull request #14 from lambdalisue/fix-msys2
Browse files Browse the repository at this point in the history
Fix msys2
  • Loading branch information
lambdalisue authored Jul 15, 2021
2 parents 5c9fc21 + 01ce9ac commit 1513363
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions autoload/fern_git_status/process.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ function! fern_git_status#process#show_toplevel(root, token) abort
let args = ['git', '-C', a:root, 'rev-parse', '--show-toplevel']
let Profile = fern#profile#start('fern_git_status#process#show_toplevel')
return s:Process.start(args, {
\ 'toekn': a:token,
\ 'token': a:token,
\ 'reject_on_failure': v:true,
\})
\.catch({e -> s:Promise.reject(s:normalize_error(e)) })
\.then({v -> join(v.stdout, '') })
\.then({v -> s:normalize_path(v) })
\.then({v -> s:normalize_path(v, a:token) })
\.finally({ -> Profile() })
endfunction

Expand Down Expand Up @@ -47,7 +47,8 @@ function! fern_git_status#process#status(root, token, options) abort
\.catch({e -> s:Promise.reject(s:normalize_error(e)) })
\.then({ v -> v.stdout })
\.then(s:AsyncLambda.filter_f({ v -> v !=# '' }))
\.then(s:AsyncLambda.map_f({ v -> s:parse_status(v) }))
\.then(s:AsyncLambda.map_f({ v -> s:parse_status(v, a:token) }))
\.then({ v -> s:Promise.all(v) })
\.finally({ -> Profile() })
endfunction

Expand All @@ -58,25 +59,37 @@ function! s:normalize_error(error) abort
return a:error
endfunction

function! s:parse_status(record) abort
function! s:parse_status(record, token) 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]
return s:normalize_path(relpath, a:token)
\.then({ v -> [v, 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)
function! s:normalize_path(path, token) abort
if a:path[:0] ==# '/' && executable('cygpath')
" msys2
return s:Process.start(['cygpath', '-w', a:path], {
\ 'token': a:token,
\ 'reject_on_failure': v:true,
\})
\.then({v -> join(v.stdout, '') })
\.catch({e -> s:Promise.reject(s:normalize_error(e)) })
else
" Git for Windows
let filepath = fern#internal#filepath#from_slash(a:path)
let path = fern#internal#filepath#to_slash(filepath)
return s:Promise.resolve(path)
endif
endfunction
else
function! s:normalize_path(path) abort
return a:path
function! s:normalize_path(path, token) abort
return s:Promise.resolve(a:path)
endfunction
endif

0 comments on commit 1513363

Please sign in to comment.