@@ -204,6 +204,156 @@ public void CanStashIgnoredFiles()
204
204
}
205
205
}
206
206
207
+ [ Fact ]
208
+ public void CanStashAndApplyWithOptions ( )
209
+ {
210
+ string path = SandboxStandardTestRepo ( ) ;
211
+ using ( var repo = new Repository ( path ) )
212
+ {
213
+ var stasher = Constants . Signature ;
214
+
215
+ const string filename = "staged_file_path.txt" ;
216
+ Touch ( repo . Info . WorkingDirectory , filename , "I'm staged\n " ) ;
217
+ repo . Stage ( filename ) ;
218
+
219
+ repo . Stashes . Add ( stasher , "This stash with default options" ) ;
220
+ Assert . Equal ( StashApplyStatus . Applied , repo . Stashes . Apply ( 0 ) ) ;
221
+
222
+ Assert . Equal ( FileStatus . NewInWorkdir , repo . RetrieveStatus ( filename ) ) ;
223
+ Assert . Equal ( 1 , repo . Stashes . Count ( ) ) ;
224
+
225
+ repo . Stage ( filename ) ;
226
+
227
+ repo . Stashes . Add ( stasher , "This stash with default options" ) ;
228
+ Assert . Equal ( StashApplyStatus . Applied , repo . Stashes . Apply (
229
+ 0 ,
230
+ new StashApplyOptions
231
+ {
232
+ ApplyModifiers = StashApplyModifiers . ReinstateIndex ,
233
+ } ) ) ;
234
+
235
+ Assert . Equal ( FileStatus . NewInIndex , repo . RetrieveStatus ( filename ) ) ;
236
+ Assert . Equal ( 2 , repo . Stashes . Count ( ) ) ;
237
+ }
238
+ }
239
+
240
+ [ Fact ]
241
+ public void CanStashAndPop ( )
242
+ {
243
+ string path = SandboxStandardTestRepo ( ) ;
244
+ using ( var repo = new Repository ( path ) )
245
+ {
246
+ var stasher = Constants . Signature ;
247
+
248
+ Assert . Equal ( 0 , repo . Stashes . Count ( ) ) ;
249
+
250
+ const string filename = "staged_file_path.txt" ;
251
+ const string contents = "I'm staged" ;
252
+ Touch ( repo . Info . WorkingDirectory , filename , contents ) ;
253
+ repo . Stage ( filename ) ;
254
+
255
+ repo . Stashes . Add ( stasher , "This stash with default options" ) ;
256
+ Assert . Equal ( 1 , repo . Stashes . Count ( ) ) ;
257
+
258
+ Assert . Equal ( StashApplyStatus . Applied , repo . Stashes . Pop ( 0 ) ) ;
259
+ Assert . Equal ( 0 , repo . Stashes . Count ( ) ) ;
260
+
261
+ Assert . Equal ( FileStatus . NewInWorkdir , repo . RetrieveStatus ( filename ) ) ;
262
+ Assert . Equal ( contents , File . ReadAllText ( Path . Combine ( repo . Info . WorkingDirectory , filename ) ) ) ;
263
+ }
264
+ }
265
+
266
+ [ Fact ]
267
+ public void StashReportsConflictsWhenReinstated ( )
268
+ {
269
+ string path = SandboxStandardTestRepo ( ) ;
270
+ using ( var repo = new Repository ( path ) )
271
+ {
272
+ var stasher = Constants . Signature ;
273
+
274
+ const string filename = "staged_file_path.txt" ;
275
+ const string originalContents = "I'm pre-stash." ;
276
+ const string filename2 = "unstaged_file_path.txt" ;
277
+ const string newContents = "I'm post-stash." ;
278
+
279
+ Touch ( repo . Info . WorkingDirectory , filename , originalContents ) ;
280
+ repo . Stage ( filename ) ;
281
+ Touch ( repo . Info . WorkingDirectory , filename2 , originalContents ) ;
282
+
283
+ repo . Stashes . Add ( stasher , "This stash with default options" ) ;
284
+
285
+ Touch ( repo . Info . WorkingDirectory , filename , newContents ) ;
286
+ repo . Stage ( filename ) ;
287
+ Touch ( repo . Info . WorkingDirectory , filename2 , newContents ) ;
288
+
289
+ Assert . Equal ( StashApplyStatus . Conflicts , repo . Stashes . Pop ( 0 , new StashApplyOptions
290
+ {
291
+ ApplyModifiers = StashApplyModifiers . ReinstateIndex ,
292
+ } ) ) ;
293
+ Assert . Equal ( 1 , repo . Stashes . Count ( ) ) ;
294
+ Assert . Equal ( newContents , File . ReadAllText ( Path . Combine ( repo . Info . WorkingDirectory , filename ) ) ) ;
295
+ Assert . Equal ( newContents , File . ReadAllText ( Path . Combine ( repo . Info . WorkingDirectory , filename2 ) ) ) ;
296
+ }
297
+ }
298
+
299
+ [ Fact ]
300
+ public void StashCallsTheCallback ( )
301
+ {
302
+ string path = SandboxStandardTestRepo ( ) ;
303
+ using ( var repo = new Repository ( path ) )
304
+ {
305
+ var stasher = Constants . Signature ;
306
+ bool called ;
307
+
308
+ const string filename = "staged_file_path.txt" ;
309
+ const string filename2 = "unstaged_file_path.txt" ;
310
+ const string originalContents = "I'm pre-stash." ;
311
+
312
+ Touch ( repo . Info . WorkingDirectory , filename , originalContents ) ;
313
+ repo . Stage ( filename ) ;
314
+ Touch ( repo . Info . WorkingDirectory , filename2 , originalContents ) ;
315
+
316
+ repo . Stashes . Add ( stasher , "This stash with default options" ) ;
317
+
318
+ called = false ;
319
+ repo . Stashes . Apply ( 0 , new StashApplyOptions
320
+ {
321
+ ProgressHandler = ( progress ) => { called = true ; return true ; }
322
+ } ) ;
323
+
324
+ Assert . Equal ( true , called ) ;
325
+
326
+ repo . Reset ( ResetMode . Hard ) ;
327
+
328
+ called = false ;
329
+ repo . Stashes . Pop ( 0 , new StashApplyOptions
330
+ {
331
+ ProgressHandler = ( progress ) => { called = true ; return true ; }
332
+ } ) ;
333
+
334
+ Assert . Equal ( true , called ) ;
335
+ }
336
+ }
337
+
338
+ [ Fact ]
339
+ public void StashApplyReportsNotFound ( )
340
+ {
341
+ string path = SandboxStandardTestRepo ( ) ;
342
+ using ( var repo = new Repository ( path ) )
343
+ {
344
+ var stasher = Constants . Signature ;
345
+
346
+ const string filename = "unstaged_file_path.txt" ;
347
+ Touch ( repo . Info . WorkingDirectory , filename , "I'm unstaged\n " ) ;
348
+
349
+ repo . Stashes . Add ( stasher , "This stash with default options" , StashModifiers . IncludeUntracked ) ;
350
+ Touch ( repo . Info . WorkingDirectory , filename , "I'm another unstaged\n " ) ;
351
+
352
+ Assert . Equal ( StashApplyStatus . NotFound , repo . Stashes . Pop ( 1 ) ) ;
353
+ Assert . Throws < ArgumentException > ( ( ) => repo . Stashes . Pop ( - 1 ) ) ;
354
+ }
355
+ }
356
+
207
357
[ Theory ]
208
358
[ InlineData ( - 1 ) ]
209
359
[ InlineData ( - 42 ) ]
0 commit comments