@@ -12,6 +12,7 @@ describe("Diff", function() {
1212
1313 before ( function ( done ) {
1414 var test = this ;
15+ var newFilePath = path . join ( path . resolve ( "test/repos/workdir" ) , "wddiff.txt" ) ;
1516
1617 return Repository . open ( reposPath ) . then ( function ( repository ) {
1718 test . repository = repository ;
@@ -26,7 +27,15 @@ describe("Diff", function() {
2627
2728 return commit . getDiff ( ) . then ( function ( diff ) {
2829 test . diff = diff ;
29- done ( ) ;
30+ fs . writeFileSync ( newFilePath , "1 line\n2 line\n3 line\n\n4" ) ;
31+
32+ exec ( "git add wddiff.txt" , { cwd : path . resolve ( "test/repos/workdir" ) } , function ( ) {
33+ Diff . treeToWorkdirWithIndex ( test . repository , test . masterCommitTree , null )
34+ . then ( function ( workdirDiff ) {
35+ test . workdirDiff = workdirDiff ;
36+ done ( ) ;
37+ } ) ;
38+ } ) ;
3039 } ) ;
3140 } ) ;
3241 } ) ;
@@ -64,25 +73,14 @@ describe("Diff", function() {
6473 assert . equal ( lines [ 3 ] . contentLen ( ) , 162 ) ;
6574 } ) ;
6675
67- it ( "can diff the workdir with index" , function ( done ) {
68- var test = this ;
69- var newFilePath = path . join ( path . resolve ( "test/repos/workdir" ) , "wddiff.txt" ) ;
70-
71- fs . writeFileSync ( newFilePath , "1 line\n2 line\n3 line\n\n4" ) ;
76+ it ( "can diff the workdir with index" , function ( ) {
77+ var patches = this . workdirDiff . patches ( ) ;
78+ assert . equal ( patches . length , 1 ) ;
7279
73- exec ( "git add wddiff.txt" , { cwd : path . resolve ( "test/repos/workdir" ) } , function ( ) {
74- Diff . treeToWorkdirWithIndex ( test . repository , test . masterCommitTree , null )
75- . then ( function ( workdirDiff ) {
76- var patches = workdirDiff . patches ( ) ;
77- assert . equal ( patches . length , 1 ) ;
80+ var hunks = patches [ 0 ] . hunks ( ) ;
81+ assert . equal ( hunks . length , 1 ) ;
7882
79- var hunks = patches [ 0 ] . hunks ( ) ;
80- assert . equal ( hunks . length , 1 ) ;
81-
82- var lines = hunks [ 0 ] . lines ( ) ;
83- assert . equal ( lines [ 0 ] . content ( ) , "1 line\n" ) ;
84- done ( ) ;
85- } ) ;
86- } ) ;
83+ var lines = hunks [ 0 ] . lines ( ) ;
84+ assert . equal ( lines [ 0 ] . content ( ) , "1 line\n" ) ;
8785 } ) ;
8886} ) ;
0 commit comments