changeset 98:e5ac6464a767

Handle absolute/relative paths properly.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 29 Jul 2014 16:34:17 -0700
parents e8b115e595d1
children 001b341ab8ad
files plugin/lawrencium.vim
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/plugin/lawrencium.vim	Fri Jul 25 09:46:00 2014 -0700
+++ b/plugin/lawrencium.vim	Tue Jul 29 16:34:17 2014 -0700
@@ -62,6 +62,11 @@
     return '"' . a:str . '"'
 endfunction
 
+" Returns whether a path is absolute.
+function! s:isabspath(path)
+    return a:path =~# '\v^(\w\:)?[/\\]'
+endfunction
+
 " Normalizes the slashes in a path.
 function! s:normalizepath(path)
     if exists('+shellslash') && &shellslash
@@ -291,16 +296,17 @@
 " Gets a full path given a repo-relative path.
 function! s:HgRepo.GetFullPath(path) abort
     let l:root_dir = self.root_dir
-    if a:path =~# '\v^[/\\]'
-        let l:root_dir = s:stripslash(l:root_dir)
+    if s:isabspath(a:path)
+        call s:throw("Expected relative path, got absolute path: " . a:path)`
     endif
     return l:root_dir . a:path
 endfunction
 
+" Gets a repo-relative path given any path.
 function! s:HgRepo.GetRelativePath(path) abort
-    execute 'cd! ' . self.root_dir
+    execute 'lcd! ' . self.root_dir
     let l:relative_path = fnamemodify(a:path, ':.')
-    execute 'cd! -'
+    execute 'lcd! -'
     return l:relative_path
 endfunction