@@ -39,6 +39,15 @@ pub struct FileBlame {
39
39
pub lines : Vec < ( Option < BlameHunk > , String ) > ,
40
40
}
41
41
42
+ #[ cfg( windows) ]
43
+ fn fixup_windows_path ( path : String ) -> String {
44
+ path. replace ( "\\ " , "/" )
45
+ }
46
+ #[ cfg( not( windows) ) ]
47
+ const fn fixup_windows_path ( path : & str ) -> & str {
48
+ path
49
+ }
50
+
42
51
///
43
52
pub fn blame_file (
44
53
repo_path : & str ,
@@ -50,7 +59,11 @@ pub fn blame_file(
50
59
51
60
let commit_id = utils:: get_head_repo ( & repo) ?;
52
61
53
- let spec = format ! ( "{}:{}" , commit_id. to_string( ) , file_path) ;
62
+ let spec = format ! (
63
+ "{}:{}" ,
64
+ commit_id. to_string( ) ,
65
+ fixup_windows_path( file_path)
66
+ ) ;
54
67
55
68
let object = repo. revparse_single ( & spec) ?;
56
69
let blob = repo. find_blob ( object. id ( ) ) ?;
@@ -214,4 +227,24 @@ mod tests {
214
227
215
228
Ok ( ( ) )
216
229
}
230
+
231
+ #[ test]
232
+ fn test_blame_windows_path_dividers ( ) {
233
+ let file_path = Path :: new ( "bar\\ foo" ) ;
234
+ let ( _td, repo) = repo_init_empty ( ) . unwrap ( ) ;
235
+ let root = repo. path ( ) . parent ( ) . unwrap ( ) ;
236
+ let repo_path = root. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
237
+
238
+ std:: fs:: create_dir ( & root. join ( "bar" ) ) . unwrap ( ) ;
239
+
240
+ File :: create ( & root. join ( file_path) )
241
+ . unwrap ( )
242
+ . write_all ( b"line 1\n " )
243
+ . unwrap ( ) ;
244
+
245
+ stage_add_file ( repo_path, file_path) . unwrap ( ) ;
246
+ commit ( repo_path, "first commit" ) . unwrap ( ) ;
247
+
248
+ assert ! ( blame_file( & repo_path, "bar\\ foo" ) . is_ok( ) ) ;
249
+ }
217
250
}
0 commit comments