@@ -3,6 +3,8 @@ var path = require("path");
33var promisify = require ( "promisify-node" ) ;
44var fse = promisify ( require ( "fs-extra" ) ) ;
55var Diff = require ( "../../lib/diff" ) ;
6+ var normalizeOptions = require ( "../../lib/util/normalize_options" ) ;
7+ var NodeGit = require ( "../../" ) ;
68
79describe ( "Diff" , function ( ) {
810 var Repository = require ( "../../lib/repository" ) ;
@@ -14,55 +16,48 @@ describe("Diff", function() {
1416 diffFilename
1517 ) ;
1618
17- before ( function ( done ) {
19+ before ( function ( ) {
1820 var test = this ;
1921
2022 return Repository . open ( reposPath ) . then ( function ( repository ) {
2123 test . repository = repository ;
2224
23- return repository . getBranchCommit ( "master" ) . then ( function ( masterCommit ) {
24-
25- return masterCommit . getTree ( ) . then ( function ( tree ) {
26- test . masterCommitTree = tree ;
27-
28- return repository . getCommit ( oid ) . then ( function ( commit ) {
29- test . commit = commit ;
30-
31- return commit . getDiff ( ) . then ( function ( diff ) {
32- test . diff = diff ;
33-
34- fse . writeFile ( diffFilepath , "1 line\n2 line\n3 line\n\n4" )
35- . then ( function ( ) {
36- return test . repository . openIndex ( ) ;
37- } )
38- . then ( function ( indexResult ) {
39- test . index = indexResult ;
40- return test . index . read ( 1 ) ;
41- } )
42- . then ( function ( ) {
43- return test . index . addByPath ( diffFilename ) ;
44- } )
45- . then ( function ( ) {
46- return test . index . write ( ) ;
47- } )
48- . then ( function ( ) {
49- return test . index . writeTree ( ) ;
50- } )
51- . then ( function ( ) {
52- Diff . treeToWorkdirWithIndex (
53- test . repository ,
54- test . masterCommitTree ,
55- null
56- )
57- . then ( function ( workdirDiff ) {
58- test . workdirDiff = workdirDiff ;
59- done ( ) ;
60- } ) ;
61- } ) ;
62- } ) ;
63- } ) ;
64- } ) ;
65- } ) ;
25+ return repository . getBranchCommit ( "master" ) ;
26+ } )
27+ . then ( function ( masterCommit ) {
28+ return masterCommit . getTree ( ) ;
29+ } )
30+ . then ( function ( tree ) {
31+ test . masterCommitTree = tree ;
32+
33+ return test . repository . getCommit ( oid ) ;
34+ } )
35+ . then ( function ( commit ) {
36+ test . commit = commit ;
37+
38+ return commit . getDiff ( ) ;
39+ } ) . then ( function ( diff ) {
40+ test . diff = diff ;
41+
42+ return fse . writeFile ( diffFilepath , "1 line\n2 line\n3 line\n\n4" ) ;
43+ } )
44+ . then ( function ( ) {
45+ return Diff . treeToWorkdirWithIndex (
46+ test . repository ,
47+ test . masterCommitTree ,
48+ normalizeOptions ( {
49+ flags : Diff . OPTION . INCLUDE_UNTRACKED
50+ } , NodeGit . DiffOptions )
51+ ) ;
52+ } )
53+ . then ( function ( workdirDiff ) {
54+ test . workdirDiff = workdirDiff ;
55+ } ) ;
56+ } ) ;
57+
58+ after ( function ( done ) {
59+ return fse . unlink ( diffFilepath ) . then ( function ( ) {
60+ done ( ) ;
6661 } ) ;
6762 } ) ;
6863
@@ -99,15 +94,15 @@ describe("Diff", function() {
9994 it ( "can diff the workdir with index" , function ( ) {
10095 var patches = this . workdirDiff . patches ( ) ;
10196 assert . equal ( patches . length , 1 ) ;
97+ assert ( patches [ 0 ] . isUntracked ( ) ) ;
10298
103- var hunks = patches [ 0 ] . hunks ( ) ;
104- assert . equal ( hunks . length , 1 ) ;
99+ var oldFile = patches [ 0 ] . delta . oldFile ( ) ;
100+ assert . equal ( oldFile . path ( ) , "wddiff.txt" ) ;
101+ assert . equal ( oldFile . size ( ) , 0 ) ;
105102
106- var lines = hunks [ 0 ] . lines ( ) ;
107- assert . equal (
108- lines [ 0 ] . content ( ) . substr ( 0 , lines [ 0 ] . contentLen ( ) ) ,
109- "1 line\n"
110- ) ;
103+ var newFile = patches [ 0 ] . delta . newFile ( ) ;
104+ assert . equal ( newFile . path ( ) , "wddiff.txt" ) ;
105+ assert . equal ( newFile . size ( ) , 23 ) ;
111106 } ) ;
112107
113108 it ( "can diff with a null tree" , function ( ) {
0 commit comments