@@ -8,6 +8,7 @@ describe("Reset", function() {
88 var NodeGit = require ( "../../" ) ;
99 var Repository = NodeGit . Repository ;
1010 var Reset = NodeGit . Reset ;
11+ var AnnotatedCommit = NodeGit . AnnotatedCommit ;
1112
1213 var reposPath = local ( "../repos/workdir" ) ;
1314 var currentCommitOid = "32789a79e71fbc9e04d3eff7425e1771eb595150" ;
@@ -104,33 +105,65 @@ describe("Reset", function() {
104105 } ) ;
105106 } ) ;
106107
107- it ( "can perform a soft reset" , function ( ) {
108- var test = this ;
109-
110- return Reset . reset ( test . repo , test . previousCommit , Reset . TYPE . SOFT )
108+ function resetFrom ( repo , commit , resetType , annotated ) {
109+ var promise = null ;
110+ if ( annotated ) {
111+ promise = AnnotatedCommit . lookup ( repo , commit . id ( ) )
112+ . then ( function ( annotatedCommit ) {
113+ return Reset . fromAnnotated ( repo , annotatedCommit , resetType ) ;
114+ } ) ;
115+ } else {
116+ promise = Reset . reset ( repo , commit , resetType ) ;
117+ }
118+ return promise
111119 . then ( function ( ) {
112- return test . repo . refreshIndex ( ) ;
120+ return repo . refreshIndex ( ) ;
113121 } )
114122 . then ( function ( index ) {
115123 return index . writeTree ( ) ;
116124 } )
117125 . then ( function ( oid ) {
118- return test . repo . getTree ( oid ) ;
126+ return repo . getTree ( oid ) ;
119127 } )
120128 . then ( function ( tree ) {
121129 return tree . getEntry ( filePath ) ;
122130 } )
123131 . then ( function ( entry ) {
124132 return entry . getBlob ( ) ;
125- } )
133+ } ) ;
134+ }
135+
136+ it ( "can perform a soft reset" , function ( ) {
137+ var test = this ;
138+
139+ return resetFrom ( test . repo , test . previousCommit , Reset . TYPE . SOFT , false )
140+ . then ( function ( blob ) {
141+ var currentCommitContents = test . currentCommitBlob . toString ( ) ;
142+ var previousCommitContents = test . previousCommitBlob . toString ( ) ;
143+ var resetContents = blob . toString ( ) ;
144+
145+ // With a soft reset all of the changes should be in the index
146+ // still so the index should still == what we had at the current
147+ // commit and not the one nwe reset to
148+ assert ( resetContents == currentCommitContents ) ;
149+ assert ( resetContents != previousCommitContents ) ;
150+
151+ return Reset ( test . repo , test . currentCommit , Reset . TYPE . HARD ) ;
152+ } ) ;
153+ } ) ;
154+
155+ it ( "can perform an annotated soft reset" , function ( ) {
156+ var test = this ;
157+
158+ return resetFrom ( test . repo , test . previousCommit , Reset . TYPE . SOFT , true )
126159 . then ( function ( blob ) {
127160 var currentCommitContents = test . currentCommitBlob . toString ( ) ;
128161 var previousCommitContents = test . previousCommitBlob . toString ( ) ;
129162 var resetContents = blob . toString ( ) ;
130163
131164 // With a soft reset all of the changes should be in the index
132165 // still so the index should still == what we had at the current
133- // commit and not the one we reset to
166+ // commit and not the one nwe reset to
134167 assert ( resetContents == currentCommitContents ) ;
135168 assert ( resetContents != previousCommitContents ) ;
136169
@@ -141,22 +174,32 @@ describe("Reset", function() {
141174 it ( "can perform a mixed reset" , function ( ) {
142175 var test = this ;
143176
144- return Reset . reset ( test . repo , test . previousCommit , Reset . TYPE . MIXED )
145- . then ( function ( ) {
146- return test . repo . refreshIndex ( ) ;
147- } )
148- . then ( function ( index ) {
149- return index . writeTree ( ) ;
150- } )
151- . then ( function ( oid ) {
152- return test . repo . getTree ( oid ) ;
153- } )
154- . then ( function ( tree ) {
155- return tree . getEntry ( filePath ) ;
156- } )
157- . then ( function ( entry ) {
158- return entry . getBlob ( ) ;
177+ return resetFrom ( test . repo , test . previousCommit , Reset . TYPE . MIXED , false )
178+ . then ( function ( blob ) {
179+ var currentCommitContents = test . currentCommitBlob . toString ( ) ;
180+ var previousCommitContents = test . previousCommitBlob . toString ( ) ;
181+ var resetContents = blob . toString ( ) ;
182+
183+ // With a mixed reset all of the changes should removed from the index
184+ // but still in the working directory. (i.e. unstaged)
185+ assert ( resetContents != currentCommitContents ) ;
186+ assert ( resetContents == previousCommitContents ) ;
187+
188+ return fse . readFile ( path . join ( test . repo . workdir ( ) , filePath ) ) ;
159189 } )
190+ . then ( function ( fileContents ) {
191+ var currentCommitContents = test . currentCommitBlob . toString ( ) ;
192+
193+ assert ( fileContents == currentCommitContents ) ;
194+
195+ return Reset . reset ( test . repo , test . currentCommit , Reset . TYPE . HARD ) ;
196+ } ) ;
197+ } ) ;
198+
199+ it ( "can perform an annotated mixed reset" , function ( ) {
200+ var test = this ;
201+
202+ return resetFrom ( test . repo , test . previousCommit , Reset . TYPE . MIXED , true )
160203 . then ( function ( blob ) {
161204 var currentCommitContents = test . currentCommitBlob . toString ( ) ;
162205 var previousCommitContents = test . previousCommitBlob . toString ( ) ;
@@ -181,22 +224,32 @@ describe("Reset", function() {
181224 it ( "can perform a hard reset" , function ( ) {
182225 var test = this ;
183226
184- return Reset . reset ( test . repo , test . previousCommit , Reset . TYPE . HARD )
185- . then ( function ( ) {
186- return test . repo . refreshIndex ( ) ;
187- } )
188- . then ( function ( index ) {
189- return index . writeTree ( ) ;
190- } )
191- . then ( function ( oid ) {
192- return test . repo . getTree ( oid ) ;
193- } )
194- . then ( function ( tree ) {
195- return tree . getEntry ( filePath ) ;
196- } )
197- . then ( function ( entry ) {
198- return entry . getBlob ( ) ;
227+ return resetFrom ( test . repo , test . previousCommit , Reset . TYPE . HARD , false )
228+ . then ( function ( blob ) {
229+ var currentCommitContents = test . currentCommitBlob . toString ( ) ;
230+ var previousCommitContents = test . previousCommitBlob . toString ( ) ;
231+ var resetContents = blob . toString ( ) ;
232+
233+ // With a hard reset all of the changes should removed from the index
234+ // and also removed from the working directory
235+ assert ( resetContents != currentCommitContents ) ;
236+ assert ( resetContents == previousCommitContents ) ;
237+
238+ return fse . readFile ( path . join ( test . repo . workdir ( ) , filePath ) ) ;
199239 } )
240+ . then ( function ( fileContents ) {
241+ var previousCommitContents = test . previousCommitBlob . toString ( ) ;
242+
243+ assert ( fileContents == previousCommitContents ) ;
244+
245+ return Reset . reset ( test . repo , test . currentCommit , Reset . TYPE . HARD ) ;
246+ } ) ;
247+ } ) ;
248+
249+ it ( "can perform an annotated hard reset" , function ( ) {
250+ var test = this ;
251+
252+ return resetFrom ( test . repo , test . previousCommit , Reset . TYPE . HARD , true )
200253 . then ( function ( blob ) {
201254 var currentCommitContents = test . currentCommitBlob . toString ( ) ;
202255 var previousCommitContents = test . previousCommitBlob . toString ( ) ;
0 commit comments