Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility with windows #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

livanh
Copy link

@livanh livanh commented Apr 7, 2019

I had to make some tweaks to have the plugin working on windows. I also tested it on linux and it seems that there are no regressions there.
Please tell me if some other change or explanation is required in order to merge.

@@ -15,7 +15,7 @@ endfunction

" fix for Windows users (https://github.com/wting/gitsessions.vim/issues/2)
if !exists('g:VIMFILESDIR')
let g:VIMFILESDIR = has('unix') ? $HOME . '/.vim/' : $VIM . '/vimfiles/'
let g:VIMFILESDIR = has('unix') ? $HOME . '/.vim/' : $HOME . '/vimfiles/'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a tautology and break the original reason why we added this line? Why bother with the unix check?

if has('unix')
return a:path[0] == s:os_sep()
else
return a:path[1] == ':'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hardcoding the path separator could we simply change the index position? Why use == ':'?

Suggested change
return a:path[1] == ':'
return a:path[1] == s:os_sep()

endfunction

" LOGIC FUNCTIONS

function! s:parent_dir(path)
let l:sep = s:os_sep()
let l:front = s:is_abs_path(a:path) ? l:sep : ''
let l:front = s:is_abs_path(a:path) && has('unix') ? l:sep : ''
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the has('unix') check make the is_abs_path(a:path) changes unnecessary since it'll never be true on Windows?

The result is all absolute paths are converted into relative paths on Windows, regardless if it was an absolute path to begin with or not.

return a:dir . '/.git'
elseif has('file_in_path') && has('path_extra')
if isdirectory(a:dir . s:os_sep() . '.git')
return a:dir . s:os_sep() . '.git'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this! 👍

if has('unix')
let l:path = a:sdir . a:pdir
else
let l:path = a:sdir . substitute(a:pdir,'^\([A-Z]\):','\\\1','g')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some regex backreferencing stuff. Can you help me understand why this change is necessary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants