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