8000 Add InitNewRepository() test helper · freevoid/libgit2sharp@5e40bff · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e40bff

Browse files
committed
Add InitNewRepository() test helper
1 parent f62b134 commit 5e40bff

22 files changed

+189
-160
lines changed

LibGit2Sharp.Tests/BlobFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public static void CopyStream(Stream input, Stream output)
8484
[Fact]
8585
public void CanStageAFileGeneratedFromABlobContentStream()
8686
{
87-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
87+
string repoPath = InitNewRepository();
8888

89-
using (Repository repo = Repository.Init(scd.DirectoryPath))
89+
using (var repo = new Repository(repoPath))
9090
{
9191
for (int i = 0; i < 5; i++)
9292
{

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,9 @@ public void LookingOutABranchByNameWithBadParamsThrows()
352352

353353
public void CanGetInformationFromUnbornBranch()
354354
{
355-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
356-
using (var repo = Repository.Init(scd.DirectoryPath, true))
355+
string repoPath = InitNewRepository(true);
356+
357+
using (var repo = new Repository(repoPath))
357358
{
358359
var head = repo.Head;
359360

@@ -793,10 +794,11 @@ public void DetachedHeadIsNotATrackingBranch()
793794
[Fact]
794795
public void TrackedBranchExistsFromDefaultConfigInEmptyClone()
795796
{
796-
SelfCleaningDirectory scd1 = BuildSelfCleaningDirectory();
797+
string repoPath = InitNewRepository(true);
797798

798799
Uri uri;
799-
using (var emptyRepo = Repository.Init(scd1.DirectoryPath, true))
800+
801+
using (var emptyRepo = new Repository(repoPath))
800802
{
801803
uri = new Uri(emptyRepo.Info.Path);
802804
}

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ public void CanCheckoutAnArbitraryCommit(string commitPointer)
141141
[Fact]
142142
public void CheckoutAddsMissingFilesInWorkingDirectory()
143143
{
144-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
144+
string repoPath = InitNewRepository();
145145

146-
using (var repo = Repository.Init(scd.DirectoryPath))
146+
using (var repo = new Repository(repoPath))
147147
{
148148
PopulateBasicRepository(repo);
149149

@@ -167,9 +167,9 @@ public void CheckoutAddsMissingFilesInWorkingDirectory()
167167
[Fact]
168168
public void CheckoutRemovesExtraFilesInWorkingDirectory()
169169
{
170-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
170+
string repoPath = InitNewRepository();
171171

172-
using (var repo = Repository.Init(scd.DirectoryPath))
172+
using (var repo = new Repository(repoPath))
173173
{
174174
PopulateBasicRepository(repo);
175175

@@ -195,9 +195,9 @@ public void CheckoutRemovesExtraFilesInWorkingDirectory()
195195
[Fact]
196196
public void CheckoutUpdatesModifiedFilesInWorkingDirectory()
197197
{
198-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
198+
string repoPath = InitNewRepository();
199199

200-
using (var repo = Repository.Init(scd.DirectoryPath))
200+
using (var repo = new Repository(repoPath))
201201
{
202202
PopulateBasicRepository(repo);
203203

@@ -276,9 +276,9 @@ public void CanForcefullyCheckoutWithConflictingStagedChanges()
276276
[Fact]
277277
public void CheckingOutWithMergeConflictsThrows()
278278
{
279-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
279+
string repoPath = InitNewRepository();
280280

281-
using (var repo = Repository.Init(scd.DirectoryPath))
281+
using (var repo = new Repository(repoPath))
282282
{
283283
Touch(repo.Info.WorkingDirectory, originalFilePath, "Hello\n");
284284
repo.Index.Stage(originalFilePath);
@@ -319,9 +319,9 @@ public void CheckingOutInABareRepoThrows()
319319
[Fact]
320320
public void CheckingOutAgainstAnUnbornBranchThrows()
321321
{
322-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
322+
string repoPath = InitNewRepository();
323323

324-
using (var repo = Repository.Init(scd.DirectoryPath))
324+
using (var repo = new Repository(repoPath))
325325
{
326326
Assert.True(repo.Info.IsHeadOrphaned);
327327

@@ -352,9 +352,9 @@ public void CheckingOutABranchWithBadParamsThrows()
352352
[Fact]
353353
public void CheckingOutThroughBranchCallsCheckoutProgress()
354354
{
355-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
355+
string repoPath = InitNewRepository();
356356

357-
using (var repo = Repository.Init(scd.DirectoryPath))
357+
using (var repo = new Repository(repoPath))
358358
{
359359
PopulateBasicRepository(repo);
360360
bool wasCalled = false;
@@ -369,9 +369,9 @@ public void CheckingOutThroughBranchCallsCheckoutProgress()
369369
[Fact]
370370
public void CheckingOutThroughRepositoryCallsCheckoutProgress()
371371
{
372-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
372+
string repoPath = InitNewRepository();
373373

374-
using (var repo = Repository.Init(scd.DirectoryPath))
374+
using (var repo = new Repository(repoPath))
375375
{
376376
PopulateBasicRepository(repo);
377377
bool wasCalled = false;
@@ -385,9 +385,9 @@ public void CheckingOutThroughRepositoryCallsCheckoutProgress()
385385
[Fact]
386386
public void CheckoutRetainsUntrackedChanges()
387387
{
388-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
388+
string repoPath = InitNewRepository();
389389

390-
using (var repo = Repository.Init(scd.DirectoryPath))
390+
using (var repo = new Repository(repoPath))
391391
{
392392
PopulateBasicRepository(repo);
393393

@@ -409,9 +409,9 @@ public void CheckoutRetainsUntrackedChanges()
409409
[Fact]
410410
public void ForceCheckoutRetainsUntrackedChanges()
411411
{
412-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
412+
string repoPath = InitNewRepository();
413413

414-
using (var repo = Repository.Init(scd.DirectoryPath))
414+
using (var repo = new Repository(repoPath))
415415
{
416416
PopulateBasicRepository(repo);
417417

@@ -433,9 +433,9 @@ public void ForceCheckoutRetainsUntrackedChanges()
433433
[Fact]
434434
public void CheckoutRetainsUnstagedChanges()
435435
{
436-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
436+
string repoPath = InitNewRepository();
437437

438-
using (var repo = Repository.Init(scd.DirectoryPath))
438+
using (var repo = new Repository(repoPath))
439439
{
440440
PopulateBasicRepository(repo);
441441

@@ -457,9 +457,9 @@ public void CheckoutRetainsUnstagedChanges()
457457
[Fact]
458458
public void CheckoutRetainsStagedChanges()
459459
{
460-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
460+
string repoPath = InitNewRepository();
461461

462-
using (var repo = Repository.Init(scd.DirectoryPath))
462+
using (var repo = new Repository(repoPath))
463463
{
464464
PopulateBasicRepository(repo);
465465

@@ -482,9 +482,9 @@ public void CheckoutRetainsStagedChanges()
482482
[Fact]
483483
public void CheckoutRetainsIgnoredChanges()
484484
{
485-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
485+
string repoPath = InitNewRepository();
486486

487-
using (var repo = Repository.Init(scd.DirectoryPath))
487+
using (var repo = new Repository(repoPath))
488488
{
489489
PopulateBasicRepository(repo);
490490

@@ -509,9 +509,9 @@ public void CheckoutRetainsIgnoredChanges()
509509
[Fact]
510510
public void ForceCheckoutRetainsIgnoredChanges()
511511
{
512-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
512+
string repoPath = InitNewRepository();
513513

514-
using (var repo = Repository.Init(scd.DirectoryPath))
514+
using (var repo = new Repository(repoPath))
515515
{
516516
PopulateBasicRepository(repo);
517517

@@ -536,9 +536,9 @@ public void ForceCheckoutRetainsIgnoredChanges()
536536
[Fact]
537537
public void CheckoutBranchSnapshot()
538538
{
539-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
539+
string repoPath = InitNewRepository();
540540

541-
using (var repo = Repository.Init(scd.DirectoryPath))
541+
using (var repo = new Repository(repoPath))
542542
{
543543
PopulateBasicRepository(repo);
544544

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,9 @@ public void DirectlyAccessingAnUnknownTreeEntryOfTheCommitReturnsNull()
494494
[SkippableFact]
495495
public void CanCommitWithSignatureFromConfig()
496496
{
497-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
497+
string repoPath = InitNewRepository();
498498

499-
using (var repo = Repository.Init(scd.DirectoryPath))
499+
using (var repo = new Repository(repoPath))
500500
{
501501
string dir = repo.Info.Path;
502502
Assert.True(Path.IsPathRooted(dir));
@@ -562,9 +562,9 @@ public void CommitParentsAreMergeHeads()
562562
[Fact]
563563
public void CommitCleansUpMergeMetadata()
564564
{
565-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
565+
string repoPath = InitNewRepository();
566566

567-
using (var repo = Repository.Init(scd.DirectoryPath))
567+
using (var repo = new Repository(repoPath))
568568
{
569569
string dir = repo.Info.Path;
570570
Assert.True(Path.IsPathRooted(dir));
@@ -597,9 +597,9 @@ public void CommitCleansUpMergeMetadata()
597597
[Fact]
598598
public void CanCommitALittleBit()
599599
{
600-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
600+
string repoPath = InitNewRepository();
601601

602-
using (var repo = Repository.Init(scd.DirectoryPath))
602+
using (var repo = new Repository(repoPath))
603603
{
604604
string dir = repo.Info.Path;
605605
Assert.True(Path.IsPathRooted(dir));
@@ -681,9 +681,9 @@ private static void AssertBlobContent(TreeEntry entry, string expectedContent)
681681
Assert.Equal(expectedContent, ((Blob)(entry.Target)).ContentAsUtf8());
682682
}
683683

684-
private static void CommitToANewRepository(string path)
684+
private static void AddCommitToRepo(string path)
685685
{
686-
using (Repository repo = Repository.Init(path))
686+
using (var repo = new Repository(path))
687687
{
688688
const string relativeFilepath = "test.txt";
689689
Touch(repo.Info.WorkingDirectory, relativeFilepath, "test\n");
@@ -697,11 +697,11 @@ private static void CommitToANewRepository(string path)
697697
[Fact]
698698
public void CanGeneratePredictableObjectShas()
699699
{
700-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
700+
string repoPath = InitNewRepository();
701701

702-
CommitToANewRepository(scd.DirectoryPath);
702+
AddCommitToRepo(repoPath);
703703

704-
using (var repo = new Repository(scd.DirectoryPath))
704+
using (var repo = new Repository(repoPath))
705705
{
706706
Commit commit = repo.Commits.Single();
707707
Assert.Equal("1fe3126578fc4eca68c193e4a3a0a14a0704624d", commit.Sha);
@@ -717,11 +717,11 @@ public void CanGeneratePredictableObjectShas()
717717
[Fact]
718718
public void CanAmendARootCommit()
719719
{
720-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
720+
string repoPath = InitNewRepository();
721721

722-
CommitToANewRepository(scd.DirectoryPath);
722+
AddCommitToRepo(repoPath);
723723

724-
using (var repo = new Repository(scd.DirectoryPath))
724+
using (var repo = new Repository(repoPath))
725725
{
726726
Assert.Equal(1, repo.Head.Commits.Count());
727727

@@ -784,9 +784,9 @@ private static void AssertCommitHasBeenAmended(Repository repo, Commit amendedCo
784784
[Fact]
785785
public void CanNotAmendAnEmptyRepository()
786786
{
787-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
787+
string repoPath = InitNewRepository();
788788

789-
using (Repository repo = Repository.Init(scd.DirectoryPath))
789+
using (var repo = new Repository(repoPath))
790790
{
791791
Assert.Throws<OrphanedHeadException>(() => repo.Commit("I can not amend anything !:(", DummySignature, DummySignature, true));
792792
}
@@ -846,9 +846,10 @@ public void CanCorrectlyDistinguishAuthorFromCommitter()
846846
public void CanCommitOnOrphanedBranch()
847847
{
848848
string newBranchName = "refs/heads/newBranch";
849-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
850849

851-
using (var repo = Repository.Init(scd.DirectoryPath))
850+
string repoPath = InitNewRepository();
851+
852+
using (var repo = new Repository(repoPath))
852853
{
853854
// Set Head to point to branch other than master
854855
repo.Refs.UpdateTarget("HEAD", newBranchName);

LibGit2Sharp.Tests/CurrentOperationFixture.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public class CurrentOperationFixture : BaseFixture
1313
[InlineData(false)]
1414
public void CurrentOperationIsNoneForNewRepo(bool isBare)
1515
{
16-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
17-
using (var repo = Repository.Init(scd.DirectoryPath, isBare))
16+
string repoPath = InitNewRepository(isBare);
17+
18+
using (var repo = new Repository(repoPath))
1819
{
1920
Assert.Equal(CurrentOperation.None, repo.Info.CurrentOperation);
2021
}

0 commit comments

Comments
 (0)
0