Welcome to mirror list, hosted at ThFree Co, Russian Federation.

IndexFixture.cs « LibGit2Sharp.Tests - github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 196df26e82d6a72aa91feaa908b17570a5685a06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using LibGit2Sharp.Tests.TestHelpers;
using NUnit.Framework;

namespace LibGit2Sharp.Tests
{
    [TestFixture]
    public class IndexFixture : BaseFixture
    {
        private static readonly string subBranchFile = Path.Combine("1", "branch_file.txt");
        private readonly string[] expectedEntries = new[]
                                                        {
                                                            "1.txt",
                                                            subBranchFile,
                                                            "README",
                                                            "branch_file.txt",
                                                            //"deleted_staged_file.txt",
                                                            "deleted_unstaged_file.txt",
                                                            "modified_staged_file.txt",
                                                            "modified_unstaged_file.txt",
                                                            "new.txt",
                                                            "new_tracked_file.txt"
                                                        };

        [Test]
        public void CanCountEntriesInIndex()
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                repo.Index.Count.ShouldEqual(expectedEntries.Count());
            }
        }

        [Test]
        public void CanEnumerateIndex()
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                CollectionAssert.AreEqual(expectedEntries, repo.Index.Select(e => e.Path).ToArray());
            }
        }

        [Test]
        public void CanFetchAnIndexEntryByItsName()
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                IndexEntry entry = repo.Index["README"];
                entry.Path.ShouldEqual("README");

                // Expressed in Posix format...
                IndexEntry entryWithPath = repo.Index["1/branch_file.txt"];
                entryWithPath.Path.ShouldEqual(subBranchFile);

                //...or in native format
                IndexEntry entryWithPath2 = repo.Index[subBranchFile];
                entryWithPath2.ShouldEqual(entryWithPath);
            }
        }

        [Test]
        public void FetchingAnUnknownIndexEntryReturnsNull()
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                IndexEntry entry = repo.Index["I-do-not-exist.txt"];
                entry.ShouldBeNull();
            }
        }

        [Test]
        public void ReadIndexWithBadParamsFails()
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                Assert.Throws<ArgumentNullException>(() => { IndexEntry entry = repo.Index[null]; });
                Assert.Throws<ArgumentException>(() => { IndexEntry entry = repo.Index[string.Empty]; });
            }
        }

        [TestCase("1/branch_file.txt", FileStatus.Unaltered, true, FileStatus.Unaltered, true, 0)]
        [TestCase("deleted_unstaged_file.txt", FileStatus.Missing, true, FileStatus.Removed, false, -1)]
        [TestCase("modified_unstaged_file.txt", FileStatus.Modified, true, FileStatus.Staged, true, 0)]
        [TestCase("new_untracked_file.txt", FileStatus.Untracked, false, FileStatus.Added, true, 1)]
        [TestCase("modified_staged_file.txt", FileStatus.Staged, true, FileStatus.Staged, true, 0)]
        [TestCase("new_tracked_file.txt", FileStatus.Added, true, FileStatus.Added, true, 0)]
        public void CanStage(string relativePath, FileStatus currentStatus, bool doesCurrentlyExistInTheIndex, FileStatus expectedStatusOnceStaged, bool doesExistInTheIndexOnceStaged, int expectedIndexCountVariation)
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                int count = repo.Index.Count;
                (repo.Index[relativePath] != null).ShouldEqual(doesCurrentlyExistInTheIndex);
                repo.Index.RetrieveStatus(relativePath).ShouldEqual(currentStatus);

                repo.Index.Stage(relativePath);

                repo.Index.Count.ShouldEqual(count + expectedIndexCountVariation);
                (repo.Index[relativePath] != null).ShouldEqual(doesExistInTheIndexOnceStaged);
                repo.Index.RetrieveStatus(relativePath).ShouldEqual(expectedStatusOnceStaged);
            }
        }

        [Test]
        public void CanStageTheUpdationOfAStagedFile()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                int count = repo.Index.Count;
                const string filename = "new_tracked_file.txt";
                IndexEntry blob = repo.Index[filename];

                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added);

                File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, filename), "brand new content");
                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added | FileStatus.Modified);

                repo.Index.Stage(filename);
                IndexEntry newBlob = repo.Index[filename];

                repo.Index.Count.ShouldEqual(count);
                blob.Id.ShouldNotEqual(newBlob.Id);
                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added);
            }
        }

        [TestCase("1/I-do-not-exist.txt", FileStatus.Nonexistent)]
        [TestCase("deleted_staged_file.txt", FileStatus.Removed)]
        public void StagingAnUnknownFileThrows(string relativePath, FileStatus status)
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                repo.Index[relativePath].ShouldBeNull();
                repo.Index.RetrieveStatus(relativePath).ShouldEqual(status);

                Assert.Throws<LibGit2Exception>(() => repo.Index.Stage(relativePath));
            }
        }

        [Test]
        public void CanStageTheRemovalOfAStagedFile()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                int count = repo.Index.Count;
                const string filename = "new_tracked_file.txt";
                repo.Index[filename].ShouldNotBeNull();

                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added);

                File.Delete(Path.Combine(repo.Info.WorkingDirectory, filename));
                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added | FileStatus.Missing);

                repo.Index.Stage(filename);
                repo.Index[filename].ShouldBeNull();

                repo.Index.Count.ShouldEqual(count - 1);
                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Nonexistent);
            }
        }

        [Test]
        public void StagingANewVersionOfAFileThenUnstagingItRevertsTheBlobToTheVersionOfHead()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                int count = repo.Index.Count;

                string filename = "1" + Path.DirectorySeparatorChar + "branch_file.txt";
                const string posixifiedFileName = "1/branch_file.txt";
                ObjectId blobId = repo.Index[posixifiedFileName].Id;

                string fullpath = Path.Combine(repo.Info.WorkingDirectory, filename);

                File.AppendAllText(fullpath, "Is there there anybody out there?");
                repo.Index.Stage(filename);

                repo.Index.Count.ShouldEqual(count);
                repo.Index[posixifiedFileName].Id.ShouldNotEqual((blobId));

                repo.Index.Unstage(posixifiedFileName);
                repo.Index.Count.ShouldEqual(count);
                repo.Index[posixifiedFileName].Id.ShouldEqual((blobId));
            }
        }

        [Test]
        public void CanStageANewFileInAPersistentManner()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                const string filename = "unit_test.txt";
                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Nonexistent);
                repo.Index[filename].ShouldBeNull();

                File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, filename), "some contents");
                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Untracked);
                repo.Index[filename].ShouldBeNull();

                repo.Index.Stage(filename);
                repo.Index[filename].ShouldNotBeNull();
                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added);
                repo.Index[filename].State.ShouldEqual(FileStatus.Added);
            }

            using (var repo = new Repository(path.RepositoryPath))
            {
                const string filename = "unit_test.txt";
                repo.Index[filename].ShouldNotBeNull();
                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Added);
                repo.Index[filename].State.ShouldEqual(FileStatus.Added);
            }
        }

        [Test]
        public void CanStageANewFileWithAFullPath()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                int count = repo.Index.Count;

                const string filename = "new_untracked_file.txt";
                string fullPath = Path.Combine(repo.Info.WorkingDirectory, filename);
                File.Exists(fullPath).ShouldBeTrue();

                repo.Index.Stage(fullPath);

                repo.Index.Count.ShouldEqual(count + 1);
                repo.Index[filename].ShouldNotBeNull();
            }
        }

        [Test]
        public void CanStageANewFileWithARelativePathContainingNativeDirectorySeparatorCharacters()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                int count = repo.Index.Count;

                DirectoryInfo di = Directory.CreateDirectory(Path.Combine(repo.Info.WorkingDirectory, "Project"));
                string file = "Project" + Path.DirectorySeparatorChar + "a_file.txt";

                File.WriteAllText(Path.Combine(di.FullName, "a_file.txt"), "With backward slash on Windows!");

                repo.Index.Stage(file);

                repo.Index.Count.ShouldEqual(count + 1);

                const string posixifiedPath = "Project/a_file.txt";
                repo.Index[posixifiedPath].ShouldNotBeNull();
                repo.Index[posixifiedPath].Path.ShouldEqual(file);
            }
        }

        [Test]
        public void StagingANewFileWithAFullPathWhichEscapesOutOfTheWorkingDirThrows()
        {
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                DirectoryInfo di = Directory.CreateDirectory(scd.DirectoryPath);

                const string filename = "unit_test.txt";
                string fullPath = Path.Combine(di.FullName, filename);
                File.WriteAllText(fullPath, "some contents");

                Assert.Throws<ArgumentException>(() => repo.Index.Stage(fullPath));
            }
        }

        [Test]
        public void StageFileWithBadParamsThrows()
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                Assert.Throws<ArgumentException>(() => repo.Index.Stage(string.Empty));
                Assert.Throws<ArgumentNullException>(() => repo.Index.Stage((string)null));
                Assert.Throws<ArgumentNullException>(() => repo.Index.Stage(new string[] { }));
                Assert.Throws<ArgumentNullException>(() => repo.Index.Stage(new string[] { null }));
            }
        }

        [TestCase("1/branch_file.txt", FileStatus.Unaltered, true, FileStatus.Unaltered, true, 0)]
        [TestCase("deleted_unstaged_file.txt", FileStatus.Missing, true, FileStatus.Missing, true, 0)]
        [TestCase("modified_unstaged_file.txt", FileStatus.Modified, true, FileStatus.Modified, true, 0)]
        [TestCase("new_untracked_file.txt", FileStatus.Untracked, false, FileStatus.Untracked, false, 0)]
        [TestCase("modified_staged_file.txt", FileStatus.Staged, true, FileStatus.Modified, true, 0)]
        [TestCase("new_tracked_file.txt", FileStatus.Added, true, FileStatus.Untracked, false, -1)]
        public void CanUnStage(string relativePath, FileStatus currentStatus, bool doesCurrentlyExistInTheIndex, FileStatus expectedStatusOnceStaged, bool doesExistInTheIndexOnceStaged, int expectedIndexCountVariation)
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                int count = repo.Index.Count;
                (repo.Index[relativePath] != null).ShouldEqual(doesCurrentlyExistInTheIndex);
                repo.Index.RetrieveStatus(relativePath).ShouldEqual(currentStatus);

                repo.Index.Unstage(relativePath);

                repo.Index.Count.ShouldEqual(count + expectedIndexCountVariation);
                (repo.Index[relativePath] != null).ShouldEqual(doesExistInTheIndexOnceStaged);
                repo.Index.RetrieveStatus(relativePath).ShouldEqual(expectedStatusOnceStaged);
            }
        }

        [Test]
        public void CanUnstageTheRemovalOfAFile()
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                int count = repo.Index.Count;

                const string filename = "deleted_staged_file.txt";

                string fullPath = Path.Combine(repo.Info.WorkingDirectory, filename);
                File.Exists(fullPath).ShouldBeFalse();

                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Removed);

                repo.Index.Unstage(filename);
                repo.Index.Count.ShouldEqual(count + 1);

                repo.Index.RetrieveStatus(filename).ShouldEqual(FileStatus.Missing);
            }
        }

        [Test]
        public void UnstagingFileWithBadParamsThrows()
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                Assert.Throws<ArgumentException>(() => repo.Index.Unstage(string.Empty));
                Assert.Throws<ArgumentNullException>(() => repo.Index.Unstage((string)null));
                Assert.Throws<ArgumentNullException>(() => repo.Index.Unstage(new string[] { }));
                Assert.Throws<ArgumentNullException>(() => repo.Index.Unstage(new string[] { null }));
            }
        }

        [Test]
        public void CanRenameAFile()
        {
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

            using (var repo = Repository.Init(scd.DirectoryPath))
            {
                repo.Index.Count.ShouldEqual(0);

                const string oldName = "polite.txt";
                string oldPath = Path.Combine(repo.Info.WorkingDirectory, oldName);

                repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Nonexistent);

                File.WriteAllText(oldPath, "hello test file\n", Encoding.ASCII);
                repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Untracked);

                repo.Index.Stage(oldName);
                repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Added);

                // Generated through
                // $ echo "hello test file" | git hash-object --stdin
                const string expectedHash = "88df547706c30fa19f02f43cb2396e8129acfd9b";
                repo.Index[oldName].Id.Sha.ShouldEqual((expectedHash));

                repo.Index.Count.ShouldEqual(1);

                Signature who = Constants.Signature;
                repo.Commit("Initial commit", who, who);

                repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Unaltered);

                const string newName = "being.frakking.polite.txt";

                repo.Index.Move(oldName, newName);
                repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Removed);
                repo.Index.RetrieveStatus(newName).ShouldEqual(FileStatus.Added);

                repo.Index.Count.ShouldEqual(1);
                repo.Index[newName].Id.Sha.ShouldEqual((expectedHash));

                who = who.TimeShift(TimeSpan.FromMinutes(5));
                Commit commit = repo.Commit("Fix file name", who, who);

                repo.Index.RetrieveStatus(oldName).ShouldEqual(FileStatus.Nonexistent);
                repo.Index.RetrieveStatus(newName).ShouldEqual(FileStatus.Unaltered);

                commit.Tree[newName].Target.Id.Sha.ShouldEqual(expectedHash);
            }
        }

        [TestCase("README", FileStatus.Unaltered, "deleted_unstaged_file.txt", FileStatus.Missing, FileStatus.Removed, FileStatus.Staged)]
        [TestCase("new_tracked_file.txt", FileStatus.Added, "deleted_unstaged_file.txt", FileStatus.Missing, FileStatus.Nonexistent, FileStatus.Staged)]
        [TestCase("modified_staged_file.txt", FileStatus.Staged, "deleted_unstaged_file.txt", FileStatus.Missing, FileStatus.Removed, FileStatus.Staged)]
        [TestCase("modified_unstaged_file.txt", FileStatus.Modified, "deleted_unstaged_file.txt", FileStatus.Missing, FileStatus.Removed, FileStatus.Staged)]
        public void CanMoveAnExistingFileOverANonExistingFile(string sourcePath, FileStatus sourceStatus, string destPath, FileStatus destStatus, FileStatus sourcePostStatus, FileStatus destPostStatus)
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                repo.Index.RetrieveStatus(sourcePath).ShouldEqual(sourceStatus);
                repo.Index.RetrieveStatus(destPath).ShouldEqual(destStatus);

                repo.Index.Move(sourcePath, destPath);

                repo.Index.RetrieveStatus(sourcePath).ShouldEqual(sourcePostStatus);
                repo.Index.RetrieveStatus(destPath).ShouldEqual(destPostStatus);
            }
        }

        [TestCase("README", FileStatus.Unaltered, new[] { "README", "new_tracked_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new_untracked_file.txt" })]
        [TestCase("new_tracked_file.txt", FileStatus.Added, new[] { "README", "new_tracked_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new_untracked_file.txt" })]
        [TestCase("modified_staged_file.txt", FileStatus.Staged, new[] { "README", "new_tracked_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new_untracked_file.txt" })]
        [TestCase("modified_unstaged_file.txt", FileStatus.Modified, new[] { "README", "new_tracked_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new_untracked_file.txt" })]
        public void MovingOverAnExistingFileThrows(string sourcePath, FileStatus sourceStatus, IEnumerable<string> destPaths)
        {
            InvalidMoveUseCases(sourcePath, sourceStatus, destPaths);
        }

        [TestCase("new_untracked_file.txt", FileStatus.Untracked, new[] { "README", "new_tracked_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new_untracked_file.txt", "deleted_unstaged_file.txt", "deleted_staged_file.txt", "i_dont_exist.txt" })]
        public void MovingAFileWichIsNotUnderSourceControlThrows(string sourcePath, FileStatus sourceStatus, IEnumerable<string> destPaths)
        {
            InvalidMoveUseCases(sourcePath, sourceStatus, destPaths);
        }

        [TestCase("deleted_unstaged_file.txt", FileStatus.Missing, new[] { "README", "new_tracked_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new_untracked_file.txt", "deleted_unstaged_file.txt", "deleted_staged_file.txt", "i_dont_exist.txt" })]
        [TestCase("deleted_staged_file.txt", FileStatus.Removed, new[] { "README", "new_tracked_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new_untracked_file.txt", "deleted_unstaged_file.txt", "deleted_staged_file.txt", "i_dont_exist.txt" })]
        [TestCase("i_dont_exist.txt", FileStatus.Nonexistent, new[] { "README", "new_tracked_file.txt", "modified_staged_file.txt", "modified_unstaged_file.txt", "new_untracked_file.txt", "deleted_unstaged_file.txt", "deleted_staged_file.txt", "i_dont_exist.txt" })]
        public void MovingAFileNotInTheWorkingDirectoryThrows(string sourcePath, FileStatus sourceStatus, IEnumerable<string> destPaths)
        {
            InvalidMoveUseCases(sourcePath, sourceStatus, destPaths);
        }

        private static void InvalidMoveUseCases(string sourcePath, FileStatus sourceStatus, IEnumerable<string> destPaths)
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                repo.Index.RetrieveStatus(sourcePath).ShouldEqual(sourceStatus);

                foreach (var destPath in destPaths)
                {
                    string path = destPath;
                    Assert.Throws<LibGit2Exception>(() => repo.Index.Move(sourcePath, path));
                }
            }
        }

        [TestCase("1/branch_file.txt", FileStatus.Unaltered, true, FileStatus.Removed)]
        [TestCase("deleted_unstaged_file.txt", FileStatus.Missing, false, FileStatus.Removed)]
        public void CanRemoveAFile(string filename, FileStatus initialStatus, bool shouldInitiallyExist, FileStatus finalStatus)
        {
            TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
            using (var repo = new Repository(path.RepositoryPath))
            {
                int count = repo.Index.Count;

                string fullpath = Path.Combine(repo.Info.WorkingDirectory, filename);

                File.Exists(fullpath).ShouldEqual(shouldInitiallyExist);
                repo.Index.RetrieveStatus(filename).ShouldEqual(initialStatus);

                repo.Index.Remove(filename);

                repo.Index.Count.ShouldEqual(count - 1);
                File.Exists(fullpath).ShouldBeFalse();
                repo.Index.RetrieveStatus(filename).ShouldEqual(finalStatus);
            }
        }

        [TestCase("deleted_staged_file.txt")]
        [TestCase("modified_unstaged_file.txt")]
        [TestCase("shadowcopy_of_an_unseen_ghost.txt")]
        public void RemovingAInvalidFileThrows(string filepath)
        {
            using (var repo = new Repository(StandardTestRepoPath))
            {
                Assert.Throws<LibGit2Exception>(() => repo.Index.Remove(filepath));
            }
        }

        [Test]
        public void PathsOfIndexEntriesAreExpressedInNativeFormat()
        {
            // Initialize a new repository
            SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
            
            const string directoryName = "directory";
            const string fileName = "Testfile.txt";
            
            // Create a file and insert some content
            string directoryPath = Path.Combine(scd.RootedDirectoryPath, directoryName);
            string filePath = Path.Combine(directoryPath, fileName);
            
            Directory.CreateDirectory(directoryPath);
            File.WriteAllText(filePath, "Anybody out there?");
               
            // Initialize the repository
            using (var repo = Repository.Init(scd.DirectoryPath)) 
            {
                // Stage the file
                repo.Index.Stage(filePath);
                
                // Get the index
                Index index = repo.Index;
                
                // Build relative path
                string relFilePath = Path.Combine(directoryName, fileName);
                
                // Get the index entry
                IndexEntry ie = index[relFilePath];
                
                // Make sure the IndexEntry has been found
                ie.ShouldNotBeNull();
                
                // Make sure that the (native) relFilePath and ie.Path are equal
                ie.Path.ShouldEqual(relFilePath);
            }
        }
    }
}