File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -804,7 +804,13 @@ impl Repository {
804804 /// through looking for the path that you are interested in.
805805 pub fn status_file ( & self , path : & Path ) -> Result < Status , Error > {
806806 let mut ret = 0 as c_uint ;
807- let path = try!( path. into_c_string ( ) ) ;
807+ let path = if cfg ! ( windows) {
808+ // `git_status_file` dose not work with windows path separator
809+ // so we convert \ to /
810+ try!( :: std:: ffi:: CString :: new ( path. to_string_lossy ( ) . replace ( '\\' , "/" ) ) )
811+ } else {
812+ try!( path. into_c_string ( ) )
813+ } ;
808814 unsafe {
809815 try_call ! ( raw:: git_status_file( & mut ret, self . raw,
810816 path) ) ;
Original file line number Diff line number Diff line change @@ -400,8 +400,19 @@ mod tests {
400400 fn status_file ( ) {
401401 let ( td, repo) = :: test:: repo_init ( ) ;
402402 assert ! ( repo. status_file( Path :: new( "foo" ) ) . is_err( ) ) ;
403+ if cfg ! ( windows) {
404+ assert ! ( repo. status_file( Path :: new( "bar\\ foo.txt" ) ) . is_err( ) ) ;
405+ }
403406 t ! ( File :: create( td. path( ) . join( "foo" ) ) ) ;
407+ if cfg ! ( windows) {
408+ t ! ( :: std:: fs:: create_dir_all( td. path( ) . join( "bar" ) ) ) ;
409+ t ! ( File :: create( td. path( ) . join( "bar" ) . join( "foo.txt" ) ) ) ;
410+ }
404411 let status = t ! ( repo. status_file( Path :: new( "foo" ) ) ) ;
405412 assert ! ( status. contains( :: Status :: WT_NEW ) ) ;
413+ if cfg ! ( windows) {
414+ let status = t ! ( repo. status_file( Path :: new( "bar\\ foo.txt" ) ) ) ;
415+ assert ! ( status. contains( :: Status :: WT_NEW ) ) ;
416+ }
406417 }
407418}
You can’t perform that action at this time.
0 commit comments