@@ -118,6 +118,7 @@ pub fn get_diff(repo_path: &str, p: String, stage: bool) -> FileDiff {
118
118
scope_time ! ( "get_diff" ) ;
119
119
120
120
let repo = utils:: repo ( repo_path) ;
121
+ let repo_path = repo. path ( ) . parent ( ) . unwrap ( ) ;
121
122
122
123
let ( diff, mut opt) = get_diff_raw ( & repo, & p, stage, false ) ;
123
124
@@ -168,7 +169,6 @@ pub fn get_diff(repo_path: &str, p: String, stage: bool) -> FileDiff {
168
169
let delta: DiffDelta = diff. deltas ( ) . next ( ) . unwrap ( ) ;
169
170
170
171
if delta. status ( ) == Delta :: Untracked {
171
- let repo_path = Path :: new ( repo_path) ;
172
172
let newfile_path =
173
173
repo_path. join ( delta. new_file ( ) . path ( ) . unwrap ( ) ) ;
174
174
@@ -373,4 +373,27 @@ mod tests {
373
373
374
374
assert_eq ! ( res. hunks. len( ) , 2 )
375
375
}
376
+
377
+ #[ test]
378
+ fn test_diff_newfile_in_sub_dir_current_dir ( ) {
379
+ let file_path = Path :: new ( "foo/foo.txt" ) ;
380
+ let ( _td, repo) = repo_init_empty ( ) ;
381
+ let root = repo. path ( ) . parent ( ) . unwrap ( ) ;
382
+
383
+ let sub_path = root. join ( "foo/" ) ;
384
+
385
+ fs:: create_dir_all ( & sub_path) . unwrap ( ) ;
386
+ File :: create ( & root. join ( file_path) )
387
+ . unwrap ( )
388
+ . write_all ( b"test" )
389
+ . unwrap ( ) ;
390
+
391
+ let diff = get_diff (
392
+ sub_path. to_str ( ) . unwrap ( ) ,
393
+ String :: from ( file_path. to_str ( ) . unwrap ( ) ) ,
394
+ false ,
395
+ ) ;
396
+
397
+ assert_eq ! ( diff. hunks[ 0 ] . lines[ 1 ] . content, "test" ) ;
398
+ }
376
399
}
0 commit comments