Skip to content

Commit f67f385

Browse files
committed
Set the dummy user in the local configuration
We set a dummy user name and email in the global configuration through the options. Move away from this obsoleted method and set the configuration at the repo level, which is where a test-specific configuration should live.
1 parent 1bd1cd5 commit f67f385

File tree

6 files changed

+34
-58
lines changed

6 files changed

+34
-58
lines changed

LibGit2Sharp.Tests/CommitFixture.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,10 @@ public void DirectlyAccessingAnUnknownTreeEntryOfTheCommitReturnsNull()
542542
public void CanCommitWithSignatureFromConfig()
543543
{
544544
string repoPath = InitNewRepository();
545-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
546-
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
547545

548-
using (var repo = new Repository(repoPath, options))
546+
using (var repo = new Repository(repoPath))
549547
{
548+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
550549
string dir = repo.Info.Path;
551550
Assert.True(Path.IsPathRooted(dir));
552551
Assert.True(Directory.Exists(dir));

LibGit2Sharp.Tests/ConfigurationFixture.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,10 @@ public void CanReadStringValue()
139139
[Fact]
140140
public void CanEnumerateGlobalConfig()
141141
{
142-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
143-
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
144-
145142
var path = SandboxStandardTestRepoGitDir();
146-
using (var repo = new Repository(path, options))
143+
using (var repo = new Repository(path))
147144
{
145+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
148146
var entry = repo.Config.FirstOrDefault<ConfigurationEntry<string>>(e => e.Key == "user.name");
149147
Assert.NotNull(entry);
150148
Assert.Equal(Constants.Signature.Name, entry.Value);
@@ -196,16 +194,14 @@ public void CanFindInLocalConfig()
196194
[Fact]
197195
public void CanFindInGlobalConfig()
198196
{
199-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
200-
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
201197

202198
var path = SandboxStandardTestRepoGitDir();
203-
using (var repo = new Repository(path, options))
199+
using (var repo = new Repository(path))
204200
{
205-
var matches = repo.Config.Find(@"\.name", ConfigurationLevel.Global);
201+
var matches = repo.Config.Find("-rocks", ConfigurationLevel.Global);
206202

207203
Assert.NotNull(matches);
208-
Assert.Equal(new[] { "user.name" },
204+
Assert.Equal(new[] { "woot.this-rocks" },
209205
matches.Select(m => m.Key).ToArray());
210206
}
211207
}
@@ -375,16 +371,14 @@ public void CanAccessConfigurationWithoutARepository(Func<string, string> localC
375371
{
376372
var path = SandboxStandardTestRepoGitDir();
377373

378-
string globalConfigPath = CreateConfigurationWithDummyUser(Constants.Identity);
379-
var options = new RepositoryOptions { GlobalConfigurationLocation = globalConfigPath };
380-
381-
using (var repo = new Repository(path, options))
374+
using (var repo = new Repository(path))
382375
{
383376
repo.Config.Set("my.key", "local");
384377
repo.Config.Set("my.key", "mouse", ConfigurationLevel.Global);
385378
}
386379

387-
using (var config = Configuration.BuildFrom(localConfigurationPathProvider(path), globalConfigPath))
380+
var globalPath = Path.Combine(GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global).Single(), ".gitconfig");
381+
using (var config = Configuration.BuildFrom(localConfigurationPathProvider(path), globalPath))
388382
{
389383
Assert.Equal("local", config.Get<string>("my.key").Value);
390384
Assert.Equal("mouse", config.Get<string>("my.key", ConfigurationLevel.Global).Value);
@@ -406,11 +400,10 @@ public void PassingANonExistingLocalConfigurationFileToBuildFromthrowss()
406400
public void CannotBuildAProperSignatureFromConfigWhenFullIdentityCannotBeFoundInTheConfig(string name, string email)
407401
{
408402
string repoPath = InitNewRepository();
409-
string configPath = CreateConfigurationWithDummyUser(name, email);
410-
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
411403

412-
using (var repo = new Repository(repoPath, options))
404+
using (var repo = new Repository(repoPath))
413405
{
406+
CreateConfigurationWithDummyUser(repo, name, email);
414407
Assert.Equal(name, repo.Config.GetValueOrDefault<string>("user.name"));
415408
Assert.Equal(email, repo.Config.GetValueOrDefault<string>("user.email"));
416409

LibGit2Sharp.Tests/FilterFixture.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,9 @@ public void CanFilterLargeFiles()
276276
string attributesPath = Path.Combine(Directory.GetParent(repoPath).Parent.FullName, ".gitattributes");
277277
FileInfo attributesFile = new FileInfo(attributesPath);
278278

279-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
280-
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
281-
282-
using (Repository repo = new Repository(repoPath, repositoryOptions))
279+
using (Repository repo = new Repository(repoPath))
283280
{
281+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
284282
File.WriteAllText(attributesPath, "*.blob filter=test");
285283
repo.Stage(attributesFile.Name);
286284
repo.Stage(contentFile.Name);
@@ -421,9 +419,8 @@ private static FileInfo StageNewFile(IRepository repo, string contents = "null")
421419

422420
private Repository CreateTestRepository(string path)
423421
{
424-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
425-
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
426-
var repository = new Repository(path, repositoryOptions);
422+
var repository = new Repository(path);
423+
CreateConfigurationWithDummyUser(repository, Constants.Identity);
427424
CreateAttributesFile(repository, "* filter=test");
428425
return repository;
429426
}

LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ public void SmugdeIsNotCalledForFileWhichDoesNotMatchAnAttributeEntry()
2121

2222
string repoPath = InitNewRepository();
2323
string fileName = Guid.NewGuid() + ".rot13";
24-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
25-
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
26-
using (var repo = new Repository(repoPath, repositoryOptions))
24+
using (var repo = new Repository(repoPath))
2725
{
26+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
2827
CreateAttributesFile(repo, "*.rot13 filter=rot13");
2928

3029
var blob = CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);
@@ -61,10 +60,9 @@ public void CorrectlyEncodesAndDecodesInput()
6160

6261
string repoPath = InitNewRepository();
6362
string fileName = Guid.NewGuid() + ".rot13";
64-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
65-
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
66-
using (var repo = new Repository(repoPath, repositoryOptions))
63+
using (var repo = new Repository(repoPath))
6764
{
65+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
6866
CreateAttributesFile(repo, "*.rot13 filter=rot13");
6967

7068
var blob = CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);
@@ -106,10 +104,9 @@ public void WhenStagedFileDoesNotMatchPathSpecFileIsNotFiltered(string pathSpec,
106104
string repoPath = InitNewRepository();
107105
string fileName = Guid.NewGuid() + fileExtension;
108106

109-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
110-
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
111-
using (var repo = new Repository(repoPath, repositoryOptions))
107+
using (var repo = new Repository(repoPath))
112108
{
109+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
113110
CreateAttributesFile(repo, attributeFileEntry);
114111

115112
CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);
@@ -141,10 +138,9 @@ public void CleanIsCalledIfAttributeEntryMatches(string filterAttribute, string
141138
string repoPath = InitNewRepository();
142139
string fileName = Guid.NewGuid() + ".txt";
143140

144-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
145-
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
146-
using (var repo = new Repository(repoPath, repositoryOptions))
141+
using (var repo = new Repository(repoPath))
147142
{
143+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
148144
CreateAttributesFile(repo, attributeEntry);
149145

150146
CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);
@@ -172,10 +168,9 @@ public void SmudgeIsCalledIfAttributeEntryMatches(string filterAttribute, string
172168
string repoPath = InitNewRepository();
173169
string fileName = Guid.NewGuid() + ".txt";
174170

175-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
176-
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
177-
using (var repo = new Repository(repoPath, repositoryOptions))
171+
using (var repo = new Repository(repoPath))
178172
{
173+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
179174
CreateAttributesFile(repo, attributeEntry);
180175

181176
CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);

LibGit2Sharp.Tests/NoteFixture.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,11 @@ public void CreatingANoteWhichAlreadyExistsOverwritesThePreviousNote()
168168
[Fact]
169169
public void CanAddANoteWithSignatureFromConfig()
170170
{
171-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
172-
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
173171
string path = SandboxBareTestRepo();
174172

175-
using (var repo = new Repository(path, options))
173+
using (var repo = new Repository(path))
176174
{
175+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
177176
var commit = repo.Lookup<Commit>("9fd738e8f7967c078dceed8190330fc8648ee56a");
178177

179178
Signature signature = repo.Config.BuildSignature(DateTimeOffset.Now);
@@ -268,12 +267,11 @@ public void RemovingANonExistingNoteDoesntThrow()
268267
[Fact]
269268
public void CanRemoveANoteWithSignatureFromConfig()
270269
{
271-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
272-
RepositoryOptions options = new RepositoryOptions() { GlobalConfigurationLocation = configPath };
273270
string path = SandboxBareTestRepo();
274271

275-
using (var repo = new Repository(path, options))
272+
using (var repo = new Repository(path))
276273
{
274+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
277275
var commit = repo.Lookup<Commit>("8496071c1b46c854b31185ea97743be6a8774479");
278276
var notes = repo.Notes[commit.Id];
279277

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,14 @@ private static void BuildFakeRepositoryOptions(SelfCleaningDirectory scd, out st
335335
/// <remarks>The configuration file will be removed automatically when the tests are finished</remarks>
336336
/// <param name="identity">The identity to use for user.name and user.email</param>
337337
/// <returns>The path to the configuration file</returns>
338-
protected string CreateConfigurationWithDummyUser(Identity identity)
338+
protected void CreateConfigurationWithDummyUser(Repository repo, Identity identity)
339339
{
340-
return CreateConfigurationWithDummyUser(identity.Name, identity.Email);
340+
CreateConfigurationWithDummyUser(repo, identity.Name, identity.Email);
341341
}
342342

343-
protected string CreateConfigurationWithDummyUser(string name, string email)
343+
protected void CreateConfigurationWithDummyUser(Repository repo, string name, string email)
344344
{
345-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
346-
347-
string configFilePath = Touch(scd.DirectoryPath, "fake-config");
348-
349-
using (Configuration config = Configuration.BuildFrom(configFilePath))
345+
Configuration config = repo.Config;
350346
{
351347
if (name != null)
352348
{
@@ -358,8 +354,6 @@ protected string CreateConfigurationWithDummyUser(string name, string email)
358354
config.Set("user.email", email);
359355
}
360356
}
361-
362-
return configFilePath;
363357
}
364358

365359
/// <summary>

0 commit comments

Comments
 (0)