Skip to content

Commit 8738461

Browse files
committed
Make test directory clones consistent
1 parent 6185c08 commit 8738461

30 files changed

+370
-433
lines changed

LibGit2Sharp.Tests/AttributesFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public class AttributesFixture : BaseFixture
1010
[Fact]
1111
public void StagingHonorsTheAttributesFiles()
1212
{
13-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
14-
using (var repo = new Repository(path.RepositoryPath))
13+
string path = CloneStandardTestRepo();
14+
using (var repo = new Repository(path))
1515
{
1616
CreateAttributesFile(repo);
1717

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 42 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class BranchFixture : BaseFixture
1717
[InlineData("Ångström")]
1818
public void CanCreateBranch(string name)
1919
{
20-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
21-
using (var repo = new Repository(path.RepositoryPath))
20+
string path = CloneBareTestRepo();
21+
using (var repo = new Repository(path))
2222
{
2323
Branch newBranch = repo.CreateBranch(name, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
2424
Assert.NotNull(newBranch);
@@ -35,8 +35,8 @@ public void CanCreateBranch(string name)
3535
[Fact]
3636
public void CanCreateBranchUsingAbbreviatedSha()
3737
{
38-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
39-
using (var repo = new Repository(path.RepositoryPath))
38+
string path = CloneBareTestRepo();
39+
using (var repo = new Repository(path))
4040
{
4141
const string name = "unit_test";
4242
Branch newBranch = repo.CreateBranch(name, "be3563a");
@@ -48,8 +48,8 @@ public void CanCreateBranchUsingAbbreviatedSha()
4848
[Fact]
4949
public void CanCreateBranchFromImplicitHead()
5050
{
51-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
52-
using (var repo = new Repository(path.RepositoryPath))
51+
string path = CloneBareTestRepo();
52+
using (var repo = new Repository(path))
5353
{
5454
const string name = "unit_test";
5555
Branch newBranch = repo.CreateBranch(name);
@@ -66,8 +66,8 @@ public void CanCreateBranchFromImplicitHead()
6666
[Fact]
6767
public void CanCreateBranchFromExplicitHead()
6868
{
69-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
70-
using (var repo = new Repository(path.RepositoryPath))
69+
string path = CloneBareTestRepo();
70+
using (var repo = new Repository(path))
7171
{
7272
const string name = "unit_test";
7373
Branch newBranch = repo.CreateBranch(name, "HEAD");
@@ -79,8 +79,8 @@ public void CanCreateBranchFromExplicitHead()
7979
[Fact]
8080
public void CanCreateBranchFromCommit()
8181
{
82-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
83-
using (var repo = new Repository(path.RepositoryPath))
82+
string path = CloneBareTestRepo();
83+
using (var repo = new Repository(path))
8484
{
8585
const string name = "unit_test";
8686
var commit = repo.Lookup<Commit>("HEAD");
@@ -93,8 +93,8 @@ public void CanCreateBranchFromCommit()
9393
[Fact]
9494
public void CanCreateBranchFromRevparseSpec()
9595
{
96-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
97-
using (var repo = new Repository(path.RepositoryPath))
96+
string path = CloneBareTestRepo();
97+
using (var repo = new Repository(path))
9898
{
9999
const string name = "revparse_branch";
100100
var target = repo.Lookup<Commit>("master~2");
@@ -107,8 +107,8 @@ public void CanCreateBranchFromRevparseSpec()
107107
[Fact]
108108
public void CreatingABranchFromATagPeelsToTheCommit()
109109
{
110-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
111-
using (var repo = new Repository(path.RepositoryPath))
110+
string path = CloneBareTestRepo();
111+
using (var repo = new Repository(path))
112112
{
113113
const string name = "i-peel-tag";
114114
Branch newBranch = repo.CreateBranch(name, "refs/tags/test");
@@ -120,8 +120,8 @@ public void CreatingABranchFromATagPeelsToTheCommit()
120120
[Fact]
121121
public void CreatingABranchTriggersTheCreationOfADirectReference()
122122
{
123-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
124-
using (var repo = new Repository(path.RepositoryPath))
123+
string path = CloneBareTestRepo();
124+
using (var repo = new Repository(path))
125125
{
126126
Branch newBranch = repo.CreateBranch("clone-of-master");
127127
Assert.False(newBranch.IsCurrentRepositoryHead);
@@ -193,9 +193,8 @@ public void CanListAllBranches()
193193
[Fact]
194194
public void CanListBranchesWithRemoteAndLocalBranchWithSameShortName()
195195
{
196-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
197-
198-
using (var repo = new Repository(path.RepositoryPath))
196+
string path = CloneStandardTestRepo();
197+
using (var repo = new Repository(path))
199198
{
200199
// Create a local branch with the same short name as a remote branch.
201200
repo.Branches.Add("origin/master", repo.Branches["origin/test"].Tip);
@@ -316,8 +315,8 @@ public void CanLookupLocalBranch()
316315
[Fact]
317316
public void CanLookupABranchWhichNameIsMadeOfNon7BitsAsciiCharacters()
318317
{
319-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
320-
using (var repo = new Repository(path.RepositoryPath))
318+
string path = CloneBareTestRepo();
319+
using (var repo = new Repository(path))
321320
{
322321
const string name = "Ångström";
323322
Branch newBranch = repo.CreateBranch(name, "be3563a");
@@ -368,8 +367,8 @@ public void CanGetInformationFromUnbornBranch()
368367
[Fact]
369368
public void CanGetTrackingInformationFromBranchSharingNoHistoryWithItsTrackedBranch()
370369
{
371-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
372-
using (var repo = new Repository(path.RepositoryPath))
370+
string path = CloneStandardTestRepo();
371+
using (var repo = new Repository(path))
373372
{
374373
Branch master = repo.Branches["master"];
375374
repo.Refs.UpdateTarget("refs/remotes/origin/master", "origin/test");
@@ -460,9 +459,8 @@ public void CanSetUpstreamBranch()
460459
const string testBranchName = "branchToSetUpstreamInfoFor";
461460
const string upstreamBranchName = "refs/remotes/origin/master";
462461

463-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
464-
465-
using (var repo = new Repository(path.RepositoryPath))
462+
string path = CloneStandardTestRepo();
463+
using (var repo = new Repository(path))
466464
{
467465
Branch branch = repo.CreateBranch(testBranchName);
468466
Assert.False(branch.IsTracking);
@@ -494,9 +492,8 @@ public void CanSetUpstreamMergeBranch()
494492
const string upstreamBranchName = "refs/remotes/origin/master";
495493
const string upstreamRemoteName = "origin";
496494

497-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
498-
499-
using (var repo = new Repository(path.RepositoryPath))
495+
string path = CloneStandardTestRepo();
496+
using (var repo = new Repository(path))
500497
{
501498
Branch branch = repo.CreateBranch(testBranchName);
502499
Assert.False(branch.IsTracking);
@@ -524,9 +521,8 @@ public void CanSetLocalUpstreamBranch()
524521
const string testBranchName = "branchToSetUpstreamInfoFor";
525522
const string upstreamBranchName = "refs/heads/master";
526523

527-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
528-
529-
using (var repo = new Repository(path.RepositoryPath))
524+
string path = CloneStandardTestRepo();
525+
using (var repo = new Repository(path))
530526
{
531527
Branch branch = repo.CreateBranch(testBranchName);
532528
Assert.False(branch.IsTracking);
@@ -562,8 +558,8 @@ public void CanUnsetUpstreamBranch()
562558
const string testBranchName = "branchToSetUpstreamInfoFor";
563559
const string upstreamBranchName = "refs/remotes/origin/master";
564560

565-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
566-
using (var repo = new Repository(path.RepositoryPath))
561+
string path = CloneStandardTestRepo();
562+
using (var repo = new Repository(path))
567563
{
568564
Branch branch = repo.CreateBranch(testBranchName);
569565
Assert.False(branch.IsTracking);
@@ -594,9 +590,8 @@ public void CanWalkCommitsFromBranch()
594590

595591
private void AssertRemoval(string branchName, bool isRemote, bool shouldPreviouslyAssertExistence)
596592
{
597-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
598-
599-
using (var repo = new Repository(path.RepositoryPath))
593+
string path = CloneStandardTestRepo();
594+
using (var repo = new Repository(path))
600595
{
601596
if (shouldPreviouslyAssertExistence)
602597
{
@@ -622,9 +617,8 @@ public void CanRemoveAnExistingNamedBranch(string branchName, bool isRemote)
622617
[InlineData("origin/br2")]
623618
public void CanRemoveAnExistingBranch(string branchName)
624619
{
625-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoPath);
626-
627-
using (var repo = new Repository(path.RepositoryPath))
620+
string path = CloneStandardTestRepo();
621+
using (var repo = new Repository(path))
628622
{
629623
Branch curBranch = repo.Branches[branchName];
630624

@@ -693,8 +687,8 @@ public void OnlyOneBranchIsTheHead()
693687
[Fact]
694688
public void TwoBranchesPointingAtTheSameCommitAreNotBothCurrent()
695689
{
696-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
697-
using (var repo = new Repository(path.RepositoryPath))
690+
string path = CloneBareTestRepo();
691+
using (var repo = new Repository(path))
698692
{
699693
Branch master = repo.Branches["refs/heads/master"];
700694

@@ -706,8 +700,8 @@ public void TwoBranchesPointingAtTheSameCommitAreNotBothCurrent()
706700
[Fact]
707701
public void CanMoveABranch()
708702
{
709-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
710-
using (var repo = new Repository(path.RepositoryPath))
703+
string path = CloneBareTestRepo();
704+
using (var repo = new Repository(path))
711705
{
712706
Assert.Null(repo.Branches["br3"]);
713707

@@ -731,8 +725,8 @@ public void BlindlyMovingABranchOverAnExistingOneThrows()
731725
[Fact]
732726
public void CanMoveABranchWhileOverwritingAnExistingOne()
733727
{
734-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo();
735-
using (var repo = new Repository(path.RepositoryPath))
728+
string path = CloneBareTestRepo();
729+
using (var repo = new Repository(path))
736730
{
737731
Branch test = repo.Branches["test"];
738732
Assert.NotNull(test);
@@ -756,8 +750,8 @@ public void CanMoveABranchWhileOverwritingAnExistingOne()
756750
[Fact]
757751
public void DetachedHeadIsNotATrackingBranch()
758752
{
759-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
760-
using (var repo = new Repository(path.DirectoryPath))
753+
string path = CloneStandardTestRepo();
754+
using (var repo = new Repository(path))
761755
{
762756
repo.Reset(ResetOptions.Hard);
763757
repo.RemoveUntrackedFiles();

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class CheckoutFixture : BaseFixture
1919
[InlineData("diff-test-cases")]
2020
public void CanCheckoutAnExistingBranch(string branchName)
2121
{
22-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
23-
using (var repo = new Repository(path.RepositoryPath))
22+
string path = CloneStandardTestRepo();
23+
using (var repo = new Repository(path))
2424
{
2525
Branch master = repo.Branches["master"];
2626
Assert.True(master.IsCurrentRepositoryHead);
@@ -52,8 +52,8 @@ public void CanCheckoutAnExistingBranch(string branchName)
5252
[InlineData("diff-test-cases")]
5353
public void CanCheckoutAnExistingBranchByName(string branchName)
5454
{
55-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
56-
using (var repo = new Repository(path.RepositoryPath))
55+
string path = CloneStandardTestRepo();
56+
using (var repo = new Repository(path))
5757
{
5858
Branch master = repo.Branches["master"];
5959
Assert.True(master.IsCurrentRepositoryHead);
@@ -82,8 +82,8 @@ public void CanCheckoutAnExistingBranchByName(string branchName)
8282
[InlineData("refs/tags/lw")]
8383
public void CanCheckoutAnArbitraryCommit(string commitPointer)
8484
{
85-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
86-
using (var repo = new Repository(path.RepositoryPath))
85+
string path = CloneStandardTestRepo();
86+
using (var repo = new Repository(path))
8787
{
8888
Branch master = repo.Branches["master"];
8989
Assert.True(master.IsCurrentRepositoryHead);
@@ -202,9 +202,8 @@ public void CanForcefullyCheckoutWithConflictingStagedChanges()
202202
// 4) Create conflicting change
203203
// 5) Forcefully checkout master
204204

205-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
206-
207-
using (var repo = new Repository(path.RepositoryPath))
205+
string path = CloneStandardTestRepo();
206+
using (var repo = new Repository(path))
208207
{
209208
string fileFullPath = Path.Combine(repo.Info.WorkingDirectory, originalFilePath);
210209
Branch master = repo.Branches["master"];
@@ -556,8 +555,8 @@ public void CheckoutBranchSnapshot()
556555
[Fact]
557556
public void CheckingOutRemoteBranchResultsInDetachedHead()
558557
{
559-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
560-
using (var repo = new Repository(path.RepositoryPath))
558+
string path = CloneStandardTestRepo();
559+
using (var repo = new Repository(path))
561560
{
562561
Branch master = repo.Branches["master"];
563562
Assert.True(master.IsCurrentRepositoryHead);
@@ -576,8 +575,8 @@ public void CheckingOutRemoteBranchResultsInDetachedHead()
576575
[Fact]
577576
public void CheckingOutABranchDoesNotAlterBinaryFiles()
578577
{
579-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
580-
using (var repo = new Repository(path.RepositoryPath))
578+
string path = CloneStandardTestRepo();
579+
using (var repo = new Repository(path))
581580
{
582581
// $ git hash-object square-logo.png
583582
// b758c5bc1c8117c2a4c545dae2903e36360501c5

LibGit2Sharp.Tests/CleanFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ public class CleanFixture : BaseFixture
99
[Fact]
1010
public void CanCleanWorkingDirectory()
1111
{
12-
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
13-
using (var repo = new Repository(path.RepositoryPath))
12+
string path = CloneStandardTestRepo();
13+
using (var repo = new Repository(path))
1414
{
1515
// Verify that there are the expected number of entries and untracked files
1616
Assert.Equal(6, repo.Index.RetrieveStatus().Count());

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private void AssertLocalClone(string path)
5454
public void CanLocallyCloneAndCommitAndPush()
5555
{
5656
var scd = BuildSelfCleaningDirectory();
57-
using (var originalRepo = new Repository(BuildTemporaryCloneOfTestRepo(BareTestRepoPath).RepositoryPath))
57+
using (var originalRepo = new Repository(CloneBareTestRepo()))
5858
using (Repository clonedRepo = Repository.Clone(originalRepo.Info.Path, scd.RootedDirectoryPath))
5959
{
6060
Remote remote = clonedRepo.Network.Remotes["origin"];

LibGit2Sharp.Tests/CommitAncestorFixture.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ public void CanFindCommonAncestorForSeveralCommits()
7878
[Fact]
7979
public void CannotFindAncestorForTwoCommmitsWithoutCommonAncestor()
8080
{
81-
var scd = BuildTemporaryCloneOfTestRepo();
82-
83-
using (var repo = new Repository(scd.RepositoryPath))
81+
string path = CloneBareTestRepo();
82+
using (var repo = new Repository(path))
8483
{
8584
var first = repo.Lookup<Commit>("4c062a6361ae6959e06292c1fa5e2822d9c96345");
8685
var second = repo.Lookup<Commit>("be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
@@ -97,9 +96,8 @@ public void CannotFindAncestorForTwoCommmitsWithoutCommonAncestor()
9796
[Fact]
9897
public void CannotFindCommonAncestorForSeveralCommmitsWithoutCommonAncestor()
9998
{
100-
var scd = BuildTemporaryCloneOfTestRepo();
101-
102-
using (var repo = new Repository(scd.RepositoryPath))
99+
string path = CloneBareTestRepo();
100+
using (var repo = new Repository(path))
103101
{
104102
var first = repo.Lookup<Commit>("4c062a6361ae6959e06292c1fa5e2822d9c96345");
105103

0 commit comments

Comments
 (0)