@@ -82,354 +82,6 @@ public void ReadIndexWithBadParamsFails()
82
82
}
83
83
}
84
84
85
- [ Theory ]
86
- [ InlineData ( "1/branch_file.txt" , FileStatus . Unaltered , true , FileStatus . Unaltered , true , 0 ) ]
87
- [ InlineData ( "README" , FileStatus . Unaltered , true , FileStatus . Unaltered , true , 0 ) ]
88
- [ InlineData ( "deleted_unstaged_file.txt" , FileStatus . Missing , true , FileStatus . Removed , false , - 1 ) ]
89
- [ InlineData ( "modified_unstaged_file.txt" , FileStatus . Modified , true , FileStatus . Staged , true , 0 ) ]
90
- [ InlineData ( "new_untracked_file.txt" , FileStatus . Untracked , false , FileStatus . Added , true , 1 ) ]
91
- [ InlineData ( "modified_staged_file.txt" , FileStatus . Staged , true , FileStatus . Staged , true , 0 ) ]
92
- [ InlineData ( "new_tracked_file.txt" , FileStatus . Added , true , FileStatus . Added , true , 0 ) ]
93
- public void CanStage ( string relativePath , FileStatus currentStatus , bool doesCurrentlyExistInTheIndex , FileStatus expectedStatusOnceStaged , bool doesExistInTheIndexOnceStaged , int expectedIndexCountVariation )
94
- {
95
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
96
- using ( var repo = new Repository ( path . RepositoryPath ) )
97
- {
98
- int count = repo . Index . Count ;
99
- Assert . Equal ( doesCurrentlyExistInTheIndex , ( repo . Index [ relativePath ] != null ) ) ;
100
- Assert . Equal ( currentStatus , repo . Index . RetrieveStatus ( relativePath ) ) ;
101
-
102
- repo . Index . Stage ( relativePath ) ;
103
-
104
- Assert . Equal ( count + expectedIndexCountVariation , repo . Index . Count ) ;
105
- Assert . Equal ( doesExistInTheIndexOnceStaged , ( repo . Index [ relativePath ] != null ) ) ;
106
- Assert . Equal ( expectedStatusOnceStaged , repo . Index . RetrieveStatus ( relativePath ) ) ;
107
- }
108
- }
109
-
110
- [ Fact ]
111
- public void CanStageTheUpdationOfAStagedFile ( )
112
- {
113
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
114
- using ( var repo = new Repository ( path . RepositoryPath ) )
115
- {
116
- int count = repo . Index . Count ;
117
- const string filename = "new_tracked_file.txt" ;
118
- IndexEntry blob = repo . Index [ filename ] ;
119
-
120
- Assert . Equal ( FileStatus . Added , repo . Index . RetrieveStatus ( filename ) ) ;
121
-
122
- File . WriteAllText ( Path . Combine ( repo . Info . WorkingDirectory , filename ) , "brand new content" ) ;
123
- Assert . Equal ( FileStatus . Added | FileStatus . Modified , repo . Index . RetrieveStatus ( filename ) ) ;
124
-
125
- repo . Index . Stage ( filename ) ;
126
- IndexEntry newBlob = repo . Index [ filename ] ;
127
-
128
- Assert . Equal ( count , repo . Index . Count ) ;
129
- Assert . NotEqual ( newBlob . Id , blob . Id ) ;
130
- Assert . Equal ( FileStatus . Added , repo . Index . RetrieveStatus ( filename ) ) ;
131
- }
132
- }
133
-
134
- [ Theory ]
135
- [ InlineData ( "1/I-do-not-exist.txt" , FileStatus . Nonexistent ) ]
136
- [ InlineData ( "deleted_staged_file.txt" , FileStatus . Removed ) ]
137
- public void StagingAnUnknownFileThrows ( string relativePath , FileStatus status )
138
- {
139
- using ( var repo = new Repository ( StandardTestRepoPath ) )
140
- {
141
- Assert . Null ( repo . Index [ relativePath ] ) ;
142
- Assert . Equal ( status , repo . Index . RetrieveStatus ( relativePath ) ) ;
143
-
144
- Assert . Throws < LibGit2SharpException > ( ( ) => repo . Index . Stage ( relativePath ) ) ;
145
- }
146
- }
147
-
148
- [ Fact ]
149
- public void CanStageTheRemovalOfAStagedFile ( )
150
- {
151
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
152
- using ( var repo = new Repository ( path . RepositoryPath ) )
153
- {
154
- int count = repo . Index . Count ;
155
- const string filename = "new_tracked_file.txt" ;
156
- Assert . NotNull ( repo . Index [ filename ] ) ;
157
-
158
- Assert . Equal ( FileStatus . Added , repo . Index . RetrieveStatus ( filename ) ) ;
159
-
160
- File . Delete ( Path . Combine ( repo . Info . WorkingDirectory , filename ) ) ;
161
- Assert . Equal ( FileStatus . Added | FileStatus . Missing , repo . Index . RetrieveStatus ( filename ) ) ;
162
-
163
- repo . Index . Stage ( filename ) ;
164
- Assert . Null ( repo . Index [ filename ] ) ;
165
-
166
- Assert . Equal ( count - 1 , repo . Index . Count ) ;
167
- Assert . Equal ( FileStatus . Nonexistent , repo . Index . RetrieveStatus ( filename ) ) ;
168
- }
169
- }
170
-
171
- [ Fact ]
172
- public void StagingANewVersionOfAFileThenUnstagingItRevertsTheBlobToTheVersionOfHead ( )
173
- {
174
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
175
- using ( var repo = new Repository ( path . RepositoryPath ) )
176
- {
177
- int count = repo . Index . Count ;
178
-
179
- string filename = Path . Combine ( "1" , "branch_file.txt" ) ;
180
- const string posixifiedFileName = "1/branch_file.txt" ;
181
- ObjectId blobId = repo . Index [ posixifiedFileName ] . Id ;
182
-
183
- string fullpath = Path . Combine ( repo . Info . WorkingDirectory , filename ) ;
184
-
185
- File . AppendAllText ( fullpath , "Is there there anybody out there?" ) ;
186
- repo . Index . Stage ( filename ) ;
187
-
188
- Assert . Equal ( count , repo . Index . Count ) ;
189
- Assert . NotEqual ( ( blobId ) , repo . Index [ posixifiedFileName ] . Id ) ;
190
-
191
- repo . Index . Unstage ( posixifiedFileName ) ;
192
-
193
- Assert . Equal ( count , repo . Index . Count ) ;
194
- Assert . Equal ( blobId , repo . Index [ posixifiedFileName ] . Id ) ;
195
- }
196
- }
197
-
198
- [ Fact ]
199
- public void CanStageANewFileInAPersistentManner ( )
200
- {
201
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoPath ) ;
202
- using ( var repo = new Repository ( path . RepositoryPath ) )
203
- {
204
- const string filename = "unit_test.txt" ;
205
- Assert . Equal ( FileStatus . Nonexistent , repo . Index . RetrieveStatus ( filename ) ) ;
206
- Assert . Null ( repo . Index [ filename ] ) ;
207
-
208
- File . WriteAllText ( Path . Combine ( repo . Info . WorkingDirectory , filename ) , "some contents" ) ;
209
- Assert . Equal ( FileStatus . Untracked , repo . Index . RetrieveStatus ( filename ) ) ;
210
- Assert . Null ( repo . Index [ filename ] ) ;
211
-
212
- repo . Index . Stage ( filename ) ;
213
- Assert . NotNull ( repo . Index [ filename ] ) ;
214
- Assert . Equal ( FileStatus . Added , repo . Index . RetrieveStatus ( filename ) ) ;
215
- }
216
-
217
- using ( var repo = new Repository ( path . RepositoryPath ) )
218
- {
219
- const string filename = "unit_test.txt" ;
220
- Assert . NotNull ( repo . Index [ filename ] ) ;
221
- Assert . Equal ( FileStatus . Added , repo . Index . RetrieveStatus ( filename ) ) ;
222
- }
223
- }
224
-
225
- [ Fact ]
226
- public void CanStageANewFileWithAFullPath ( )
227
- {
228
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath );
229
- using ( var repo = new Repository ( path . RepositoryPath ) )
230
- {
231
- int count = repo . Index . Count ;
232
-
233
- const string filename = "new_untracked_file.txt" ;
234
- string fullPath = Path . Combine ( repo . Info . WorkingDirectory , filename ) ;
235
- Assert . True ( File . Exists ( fullPath ) ) ;
236
-
237
- repo . Index . Stage ( fullPath ) ;
238
-
239
- Assert . Equal ( count + 1 , repo . Index . Count ) ;
240
- Assert . NotNull ( repo . Index [ filename ] ) ;
241
- }
242
- }
243
-
244
- [ Fact ]
245
- public void CanStageANewFileWithARelativePathContainingNativeDirectorySeparatorCharacters ( )
246
- {
247
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
248
- using ( var repo = new Repository ( path . RepositoryPath ) )
249
- {
250
- int count = repo . Index . Count ;
251
-
252
- DirectoryInfo di = Directory . CreateDirectory ( Path . Combine ( repo . Info . WorkingDirectory , "Project" ) ) ;
253
- string file = Path . Combine ( "Project" , "a_file.txt" ) ;
254
-
255
- File . WriteAllText ( Path . Combine ( di . FullName , "a_file.txt" ) , "With backward slash on Windows!" ) ;
256
-
257
- repo . Index . Stage ( file ) ;
258
-
259
- Assert . Equal ( count + 1 , repo . Index . Count ) ;
260
-
261
- const string posixifiedPath = "Project/a_file.txt" ;
262
- Assert . NotNull ( repo . Index [ posixifiedPath ] ) ;
263
- Assert . Equal ( file , repo . Index [ posixifiedPath ] . Path ) ;
264
- }
265
- }
266
-
267
- [ Fact ]
268
- public void CanStageAndUnstageAnIgnoredFile ( )
269
- {
270
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
271
- using ( var repo = new Repository ( path . RepositoryPath ) )
272
- {
273
- string gitignorePath = Path . Combine ( repo . Info . WorkingDirectory , ".gitignore" ) ;
274
- File . WriteAllText ( gitignorePath , "*.ign" + Environment . NewLine ) ;
275
-
276
- const string relativePath = "Champa.ign" ;
277
- string gitignoredFile = Path . Combine ( repo . Info . WorkingDirectory , relativePath ) ;
278
- File . WriteAllText ( gitignoredFile , "On stage!" + Environment . NewLine ) ;
279
-
280
- Assert . Equal ( FileStatus . Ignored , repo . Index . RetrieveStatus ( relativePath ) ) ;
281
-
282
- repo . Index . Stage ( relativePath ) ;
283
- Assert . Equal ( FileStatus . Added , repo . Index . RetrieveStatus ( relativePath ) ) ;
284
-
285
- repo . Index . Unstage ( relativePath ) ;
286
- Assert . Equal ( FileStatus . Ignored , repo . Index . RetrieveStatus ( relativePath ) ) ;
287
- }
288
- }
289
-
290
- [ Fact ]
291
- public void StagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirThrows ( )
292
- {
293
- SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
294
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
295
- using ( var repo = new Repository ( path . RepositoryPath ) )
296
- {
297
- DirectoryInfo di = Directory . CreateDirectory ( scd . DirectoryPath ) ;
298
-
299
- const string filename = "unit_test.txt" ;
300
- string fullPath = Path . Combine ( di . FullName , filename ) ;
301
- File . WriteAllText ( fullPath , "some contents" ) ;
302
-
303
- Assert . Throws < ArgumentException > ( ( ) => repo . Index . Stage ( fullPath ) ) ;
304
- }
305
- }
306
-
307
- [ Fact ]
308
- public void StageFileWithBadParamsThrows ( )
309
- {
310
- using ( var repo = new Repository ( StandardTestRepoPath ) )
311
- {
312
- Assert . Throws < ArgumentException > ( ( ) => repo . Index . Stage ( string . Empty ) ) ;
313
- Assert . Throws < ArgumentNullException > ( ( ) => repo . Index . Stage ( ( string ) null ) ) ;
314
- Assert . Throws < ArgumentException > ( ( ) => repo . Index . Stage ( new string [ ] { } ) ) ;
315
- Assert . Throws < ArgumentException > ( ( ) => repo . Index . Stage ( new string [ ] { null } ) ) ;
316
- }
317
- }
318
-
319
- [ Theory ]
320
- [ InlineData ( "1/branch_file.txt" , FileStatus . Unaltered , true , FileStatus . Unaltered , true , 0 ) ]
321
- [ InlineData ( "deleted_unstaged_file.txt" , FileStatus . Missing , true , FileStatus . Missing , true , 0 ) ]
322
- [ InlineData ( "modified_unstaged_file.txt" , FileStatus . Modified , true , FileStatus . Modified , true , 0 ) ]
323
- [ InlineData ( "new_untracked_file.txt" , FileStatus . Untracked , false , FileStatus . Untracked , false , 0 ) ]
324
- [ InlineData ( "modified_staged_file.txt" , FileStatus . Staged , true , FileStatus . Modified , true , 0 ) ]
325
- [ InlineData ( "new_tracked_file.txt" , FileStatus . Added , true , FileStatus . Untracked , false , - 1 ) ]
326
- [ InlineData ( "where-am-I.txt" , FileStatus . Nonexistent , false , FileStatus . Nonexistent , false , 0 ) ]
327
- public void CanUnStage ( string relativePath , FileStatus currentStatus , bool doesCurrentlyExistInTheIndex , FileStatus expectedStatusOnceStaged , bool doesExistInTheIndexOnceStaged , int expectedIndexCountVariation )
328
- {
329
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
330
- using ( var repo = new Repository ( path . RepositoryPath ) )
331
- {
332
- int count = repo . Index . Count ;
333
- Assert . Equal ( doesCurrentlyExistInTheIndex , ( repo . Index [ relativePath ] != null ) ) ;
334
- Assert . Equal ( currentStatus , repo . Index . RetrieveStatus ( relativePath ) ) ;
335
-
336
- repo . Index . Unstage ( relativePath ) ;
337
-
338
- Assert . Equal ( count + expectedIndexCountVariation , repo . Index . Count ) ;
339
- Assert . Equal ( doesExistInTheIndexOnceStaged , ( repo . Index [ relativePath ] != null ) ) ;
340
- Assert . Equal ( expectedStatusOnceStaged , repo . Index . RetrieveStatus ( relativePath ) ) ;
341
- }
342
- }
343
-
344
- [ Fact ]
345
- public void CanUnstageTheRemovalOfAFile ( )
346
- {
347
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
348
- using ( var repo = new Repository ( path . RepositoryPath ) )
349
- {
350
- int count = repo . Index . Count ;
351
-
352
- const string filename = "deleted_staged_file.txt" ;
353
-
354
- string fullPath = Path . Combine ( repo . Info . WorkingDirectory , filename ) ;
355
- Assert . False ( File . Exists ( fullPath ) ) ;
356
-
357
- Assert . Equal ( FileStatus . Removed , repo . Index . RetrieveStatus ( filename ) ) ;
358
-
359
- repo . Index . Unstage ( filename ) ;
360
- Assert . Equal ( count + 1 , repo . Index . Count ) ;
361
-
362
- Assert . Equal ( FileStatus . Missing , repo . Index . RetrieveStatus ( filename ) ) ;
363
- }
364
- }
365
-
366
- [ Fact ]
367
- public void CanUnstageUntrackedFileAgainstAnOrphanedHead ( )
368
- {
369
- SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
370
-
371
- using ( var repo = Repository . Init ( scd . DirectoryPath ) )
372
- {
373
- string relativePath = "a.txt" ;
374
- string absolutePath = Path . Combine ( repo . Info . WorkingDirectory , relativePath ) ;
375
-
376
- File . WriteAllText ( absolutePath , "hello test file\n " , Encoding . ASCII ) ;
377
- repo . Index . Stage ( absolutePath ) ;
378
-
379
- repo . Index . Unstage ( relativePath ) ;
380
- RepositoryStatus status = repo . Index . RetrieveStatus ( ) ;
381
- Assert . Equal ( 0 , status . Staged . Count ( ) ) ;
382
- Assert . Equal ( 1 , status . Untracked . Count ( ) ) ;
383
- }
384
- }
385
-
386
- [ Fact ]
387
- public void UnstagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirThrows ( )
388
- {
389
- SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
390
- TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo ( StandardTestRepoWorkingDirPath ) ;
391
- using ( var repo = new Repository ( path . RepositoryPath ) )
392
- {
393
- DirectoryInfo di = Directory . CreateDirectory ( scd . DirectoryPath ) ;
394
-
395
- const string filename = "unit_test.txt" ;
396
- string fullPath = Path . Combine ( di . FullName , filename ) ;
397
- File . WriteAllText ( fullPath , "some contents" ) ;
398
-
399
- Assert . Throws < ArgumentException > ( ( ) => repo . Index . Unstage ( fullPath ) ) ;
400
- }
401
- }
402
-
403
- [ Fact ]
404
- public void UnstagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirAgainstAnOrphanedHeadThrows ( )
405
- {
406
- SelfCleaningDirectory scd = BuildSelfCleaningDirectory ( ) ;
407
- SelfCleaningDirectory scd2 = BuildSelfCleaningDirectory ( ) ;
408
-
409
- using ( var repo = Repository . Init ( scd2 . DirectoryPath ) )
410
- {
411
- DirectoryInfo di = Directory . CreateDirectory ( scd . DirectoryPath ) ;
412
-
413
- const string filename = "unit_test.txt" ;
414
- string fullPath = Path . Combine ( di . FullName , filename ) ;
415
- File . WriteAllText ( fullPath , "some contents" ) ;
416
-
417
- Assert . Throws < ArgumentException > ( ( ) => repo . Index . Unstage ( fullPath ) ) ;
418
- }
419
- }
420
-
421
- [ Fact ]
422
- public void UnstagingFileWithBadParamsThrows ( )
423
- {
424
- using ( var repo = new Repository ( StandardTestRepoPath ) )
425
- {
426
- Assert . Throws < ArgumentException > ( ( ) => repo . Index . Unstage ( string . Empty ) ) ;
427
- Assert . Throws < ArgumentNullException > ( ( ) => repo . Index . Unstage ( ( string ) null ) ) ;
428
- Assert . Throws < ArgumentException > ( ( ) => repo . Index . Unstage ( new string [ ] { } ) ) ;
429
- Assert . Throws < ArgumentException > ( ( ) => repo . Index . Unstage ( new string [ ] { null } ) ) ;
430
<
97AE
td data-grid-cell-id="diff-83fc1b5f69efc363a77b912186ab6c928ad59b02ef4b9ad5505005dc06a83dd8-430-84-1" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-deletionNum-bgColor, var(--diffBlob-deletion-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
- }
431
- }
432
-
433
85
[ Fact ]
434
86
public void CanRenameAFile ( )
435
87
{
0 commit comments