Skip to content

Commit 408d52d

Browse files
carlosmnnulltoken
authored andcommitted
BaseFixture: easy creation of a config-isolated repository
We should try to keep the user's configuration away from the tests as it may affect what the code ends up doing. To that effect, InitIsolatedRepository() returns a Repository with some dummy configuration. This includes moving the fetch tests over to this.
1 parent b9d7e79 commit 408d52d

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

LibGit2Sharp.Tests/FetchFixture.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ public class FetchFixture : BaseFixture
1616
[InlineData("git://github.com/libgit2/TestGitRepository.git")]
1717
public void CanFetchIntoAnEmptyRepository(string url)
1818
{
19-
string repoPath = InitNewRepository();
20-
21-
using (var repo = new Repository(repoPath))
19+
using (var repo = InitIsolatedRepository())
2220
{
2321
Remote remote = repo.Network.Remotes.Add(remoteName, url);
2422

@@ -55,9 +53,7 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials()
5553
InconclusiveIf(() => string.IsNullOrEmpty(Constants.PrivateRepoUrl),
5654
"Populate Constants.PrivateRepo* to run this test");
5755

58-
string repoPath = InitNewRepository();
59-
60-
using (var repo = new Repository(repoPath))
56+
using (var repo = InitIsolatedRepository())
6157
{
6258
Remote remote = repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);
6359

@@ -79,9 +75,7 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials()
7975
[InlineData("git://github.com/libgit2/TestGitRepository.git")]
8076
public void CanFetchAllTagsIntoAnEmptyRepository(string url)
8177
{
82-
string repoPath = InitNewRepository();
83-
84-
using (var repo = new Repository(repoPath))
78+
using (var repo = InitIsolatedRepository())
8579
{
8680
Remote remote = repo.Network.Remotes.Add(remoteName, url);
8781

@@ -116,9 +110,7 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url)
116110
[InlineData("git://github.com/libgit2/TestGitRepository.git", "master", "first-merge")]
117111
public void CanFetchCustomRefSpecsIntoAnEmptyRepository(string url, string localBranchName, string remoteBranchName)
118112
{
119-
string repoPath = InitNewRepository();
120-
121-
using (var repo = new Repository(repoPath))
113+
using (var repo = InitIsolatedRepository())
122114
{
123115
Remote remote = repo.Network.Remotes.Add(remoteName, url);
124116

@@ -153,9 +145,7 @@ public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int
153145
{
154146
string url = "http://github.com/libgit2/TestGitRepository";
155147

156-
string repoPath = InitNewRepository();
157-
158-
using (var repo = new Repository(repoPath))
148+
using (var repo = InitIsolatedRepository())
159149
{
160150
Remote remote = repo.Network.Remotes.Add(remoteName, url);
161151
Assert.NotNull(remote);

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ protected string InitNewRepository(bool isBare = false)
154154
return Repository.Init(scd.DirectoryPath, isBare);
155155
}
156156

157+
protected Repository InitIsolatedRepository(bool isBare = false)
158+
{
159+
return new Repository(InitNewRepository(), options: BuildFakeConfigs(BuildSelfCleaningDirectory()));
160+
}
161+
157162
public void Register(string directoryPath)
158163
{
159164
directories.Add(directoryPath);

0 commit comments

Comments
 (0)