@@ -14,6 +14,12 @@ describe("Diff", function() {
1414 var diffFilename = "wddiff.txt" ;
1515 var diffFilepath = local ( "../repos/workdir" , diffFilename ) ;
1616
17+ var moveFromFile = "README.md" ;
18+ var moveToFile = "MOVED_README.md" ;
19+
20+ var moveFromPath = local ( "../repos/workdir" , moveFromFile ) ;
21+ var moveToPath = local ( "../repos/workdir" , moveToFile ) ;
22+
1723 beforeEach ( function ( ) {
1824 var test = this ;
1925
@@ -45,6 +51,9 @@ describe("Diff", function() {
4551
4652 return fse . writeFile ( diffFilepath , "1 line\n2 line\n3 line\n\n4" ) ;
4753 } )
54+ . then ( function ( ) {
55+ return fse . move ( moveFromPath , moveToPath ) ;
56+ } )
4857 . then ( function ( ) {
4958 return Diff . treeToWorkdirWithIndex (
5059 test . repository ,
@@ -56,7 +65,10 @@ describe("Diff", function() {
5665 test . workdirDiff = workdirDiff ;
5766 } )
5867 . then ( function ( ) {
59- var opts = { flags : Diff . OPTION . INCLUDE_UNTRACKED } ;
68+ var opts = {
69+ flags : Diff . OPTION . INCLUDE_UNTRACKED |
70+ Diff . OPTION . RECURSE_UNTRACKED_DIRS
71+ } ;
6072
6173 return Diff . indexToWorkdir ( test . repository , test . index , opts ) ;
6274 } )
@@ -66,6 +78,9 @@ describe("Diff", function() {
6678 . then ( function ( ) {
6779 return fse . remove ( diffFilepath ) ;
6880 } )
81+ . then ( function ( ) {
82+ return fse . move ( moveToPath , moveFromPath ) ;
83+ } )
6984 . catch ( function ( e ) {
7085 return fse . remove ( diffFilepath )
7186 . then ( function ( ) {
@@ -106,14 +121,14 @@ describe("Diff", function() {
106121
107122 it ( "can diff the workdir with index" , function ( ) {
108123 var patches = this . workdirDiff . patches ( ) ;
109- assert . equal ( patches . length , 1 ) ;
110- assert ( patches [ 0 ] . isUntracked ( ) ) ;
124+ assert . equal ( patches . length , 3 ) ;
125+ assert ( patches [ 2 ] . isUntracked ( ) ) ;
111126
112- var oldFile = patches [ 0 ] . delta . oldFile ( ) ;
127+ var oldFile = patches [ 2 ] . delta . oldFile ( ) ;
113128 assert . equal ( oldFile . path ( ) , "wddiff.txt" ) ;
114129 assert . equal ( oldFile . size ( ) , 0 ) ;
115130
116- var newFile = patches [ 0 ] . delta . newFile ( ) ;
131+ var newFile = patches [ 2 ] . delta . newFile ( ) ;
117132 assert . equal ( newFile . path ( ) , "wddiff.txt" ) ;
118133 assert . equal ( newFile . size ( ) , 23 ) ;
119134 } ) ;
@@ -151,6 +166,22 @@ describe("Diff", function() {
151166 } ) ;
152167
153168 it ( "can diff index to workdir" , function ( ) {
154- assert . equal ( this . indexToWorkdirDiff . patches ( ) . length , 1 ) ;
169+ assert . equal ( this . indexToWorkdirDiff . patches ( ) . length , 3 ) ;
170+ } ) ;
171+
172+ it ( "can find similar files in a diff" , function ( ) {
173+ var diff = this . indexToWorkdirDiff ;
174+ var opts = {
175+ flags : Diff . FIND . RENAMES |
176+ Diff . FIND . RENAMES_FROM_REWRITES |
177+ Diff . FIND . FOR_UNTRACKED
178+ } ;
179+
180+ assert . equal ( diff . patches ( ) . length , 3 ) ;
181+
182+ diff . findSimilar ( opts ) . then ( function ( ) {
183+ // Renamed file now treated as one diff, so 3 patches -> 2
184+ assert . equal ( diff . patches ( ) . length , 2 ) ;
185+ } ) ;
155186 } ) ;
156187} ) ;
0 commit comments