From 3cea54aca9a81354df8b2e692105c8ba9fd7ac7b Mon Sep 17 00:00:00 2001
From: Jerome Reybert <jreybert@gmail.com>
Date: Wed, 19 Oct 2016 21:51:00 +0200
Subject: [PATCH] autoload/magit/utils.vim,plugin/magit.vim: escape dirs while
 chdir (fix #89)

---
 autoload/magit/utils.vim | 10 +++++-----
 plugin/magit.vim         |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/autoload/magit/utils.vim b/autoload/magit/utils.vim
index 84d26bc..2906923 100644
--- a/autoload/magit/utils.vim
+++ b/autoload/magit/utils.vim
@@ -25,7 +25,7 @@ endfunction
 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
+	execute s:magit_cd_cmd . fnameescape(a:dir)
 endfunction
 
 " magit#utils#clear_undo: this function clear local undo history.
@@ -55,7 +55,7 @@ endfunction
 function! magit#utils#system(...)
 	let dir = getcwd()
 	try
-		execute s:magit_cd_cmd . magit#git#top_dir()
+		call magit#utils#lcd(magit#git#top_dir())
 		" List as system() input is since v7.4.247, it is safe to check
 		" systemlist, which is sine v7.4.248
 		if exists('*systemlist')
@@ -75,7 +75,7 @@ function! magit#utils#system(...)
 			endif
 		endif
 	finally
-		execute s:magit_cd_cmd . dir
+		call magit#utils#lcd(dir)
 	endtry
 endfunction
 
@@ -88,7 +88,7 @@ endfunction
 function! magit#utils#systemlist(...)
 	let dir = getcwd()
 	try
-		execute s:magit_cd_cmd . magit#git#top_dir()
+		call magit#utils#lcd(magit#git#top_dir())
 		" systemlist since v7.4.248
 		if exists('*systemlist')
 			return call('systemlist', a:000)
@@ -96,7 +96,7 @@ function! magit#utils#systemlist(...)
 			return split(call('magit#utils#system', a:000), '\n')
 		endif
 	finally
-		execute s:magit_cd_cmd . dir
+		call magit#utils#lcd(dir)
 	endtry
 endfunction
 
diff --git a/plugin/magit.vim b/plugin/magit.vim
index 7ea609c..9facf1f 100644
--- a/plugin/magit.vim
+++ b/plugin/magit.vim
@@ -778,7 +778,7 @@ function! magit#show_magit(display, ...)
 		throw 'magit_not_in_git_repo'
 	endif
 
-	let buffer_name='magit://' . git_dir
+	let buffer_name=fnameescape('magit://' . git_dir)
 
 	let magit_win = magit#utils#search_buffer_in_windows(buffer_name)
 
-- 
GitLab