Skip to content

Commit 45846e2

Browse files
author
Edward Thomson
committed
Merge pull request #1274 from libgit2/cmn/obsolete-repo-config-paths
Obsolete the config paths in RepositoryOptions
2 parents 3615df9 + ebc43b4 commit 45846e2

21 files changed

+148
-196
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
### Changes
1818

19+
- Obsolete the config paths in RepositoryOptions
20+
1921
### Fixes
2022

2123
## v0.22 - ([diff](https://github.com/libgit2/libgit2sharp/compare/v0.21.1...v0.22))

LibGit2Sharp.Tests/AttributesFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class AttributesFixture : BaseFixture
99
[Fact]
1010
public void StagingHonorsTheAttributesFiles()
1111
{
12-
using (var repo = InitIsolatedRepository())
12+
using (var repo = new Repository(InitNewRepository()))
1313
{
1414
CreateAttributesFile(repo);
1515

LibGit2Sharp.Tests/BranchFixture.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,10 @@ public void QueryRemoteForRemoteBranch()
447447
[Fact]
448448
public void QueryUnresolvableRemoteForRemoteBranch()
449449
{
450-
var path = SandboxStandardTestRepo();
451-
452450
var fetchRefSpecs = new string[] { "+refs/heads/notfound/*:refs/remotes/origin/notfound/*" };
453451

454-
using (var repo = InitIsolatedRepository(path))
452+
var path = SandboxStandardTestRepo();
453+
using (var repo = new Repository(path))
455454
{
456455
// Update the remote config such that the remote for a
457456
// remote branch cannot be resolved
@@ -472,12 +471,11 @@ public void QueryUnresolvableRemoteForRemoteBranch()
472471
[Fact]
473472
public void QueryAmbigousRemoteForRemoteBranch()
474473
{
475-
var path = SandboxStandardTestRepo();
476-
477474
const string fetchRefSpec = "+refs/heads/*:refs/remotes/origin/*";
478475
const string url = "http://github.com/libgit2/TestGitRepository";
479476

480-
using (var repo = InitIsolatedRepository(path))
477+
var path = SandboxStandardTestRepo();
478+
using (var repo = new Repository(path))
481479
{
482480
// Add a second remote so that it is ambiguous which remote
483481
// the remote-tracking branch tracks.

LibGit2Sharp.Tests/CommitFixture.cs

+2-3
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

+13-32
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@ public void CanUnsetAnEntryFromTheLocalConfiguration()
3636
[Fact]
3737
public void CanUnsetAnEntryFromTheGlobalConfiguration()
3838
{
39-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
40-
41-
var options = BuildFakeConfigs(scd);
42-
4339
string path = SandboxBareTestRepo();
44-
using (var repo = new Repository(path, options))
40+
using (var repo = new Repository(path))
4541
{
4642
Assert.True(repo.Config.HasConfig(ConfigurationLevel.Global));
4743
Assert.Equal(42, repo.Config.Get<int>("Wow.Man-I-am-totally-global").Value);
@@ -143,12 +139,10 @@ public void CanReadStringValue()
143139
[Fact]
144140
public void CanEnumerateGlobalConfig()
145141
{
146-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
147-
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
148-
149142
var path = SandboxStandardTestRepoGitDir();
150-
using (var repo = new Repository(path, options))
143+
using (var repo = new Repository(path))
151144
{
145+
CreateConfigurationWithDummyUser(repo, Constants.Identity);
152146
var entry = repo.Config.FirstOrDefault<ConfigurationEntry<string>>(e => e.Key == "user.name");
153147
Assert.NotNull(entry);
154148
Assert.Equal(Constants.Signature.Name, entry.Value);
@@ -200,16 +194,14 @@ public void CanFindInLocalConfig()
200194
[Fact]
201195
public void CanFindInGlobalConfig()
202196
{
203-
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
204-
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
205197

206198
var path = SandboxStandardTestRepoGitDir();
207-
using (var repo = new Repository(path, options))
199+
using (var repo = new Repository(path))
208200
{
209-
var matches = repo.Config.Find(@"\.name", ConfigurationLevel.Global);
201+
var matches = repo.Config.Find("-rocks", ConfigurationLevel.Global);
210202

211203
Assert.NotNull(matches);
212-
Assert.Equal(new[] { "user.name" },
204+
Assert.Equal(new[] { "woot.this-rocks" },
213205
matches.Select(m => m.Key).ToArray());
214206
}
215207
}
@@ -331,12 +323,8 @@ public void SettingUnsupportedTypeThrows()
331323
[Fact]
332324
public void CanGetAnEntryFromASpecificStore()
333325
{
334-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
335-
336-
var options = BuildFakeConfigs(scd);
337-
338326
string path = SandboxStandardTestRepo();
339-
using (var repo = new Repository(path, options))
327+
using (var repo = new Repository(path))
340328
{
341329
Assert.True(repo.Config.HasConfig(ConfigurationLevel.Local));
342330
Assert.True(repo.Config.HasConfig(ConfigurationLevel.Global));
@@ -356,12 +344,8 @@ public void CanGetAnEntryFromASpecificStore()
356344
[Fact]
357345
public void CanTellIfASpecificStoreContainsAKey()
358346
{
359-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
360-
361-
var options = BuildFakeConfigs(scd);
362-
363347
string path = SandboxBareTestRepo();
364-
using (var repo = new Repository(path, options))
348+
using (var repo = new Repository(path))
365349
{
366350
Assert.True(repo.Config.HasConfig(ConfigurationLevel.System));
367351

@@ -387,16 +371,14 @@ public void CanAccessConfigurationWithoutARepository(Func<string, string> localC
387371
{
388372
var path = SandboxStandardTestRepoGitDir();
389373

390-
string globalConfigPath = CreateConfigurationWithDummyUser(Constants.Identity);
391-
var options = new RepositoryOptions { GlobalConfigurationLocation = globalConfigPath };
392-
393-
using (var repo = new Repository(path, options))
374+
using (var repo = new Repository(path))
394375
{
395376
repo.Config.Set("my.key", "local");
396377
repo.Config.Set("my.key", "mouse", ConfigurationLevel.Global);
397378
}
398379

399-
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))
400382
{
401383
Assert.Equal("local", config.Get<string>("my.key").Value);
402384
Assert.Equal("mouse", config.Get<string>("my.key", ConfigurationLevel.Global).Value);
@@ -418,11 +400,10 @@ public void PassingANonExistingLocalConfigurationFileToBuildFromthrowss()
418400
public void CannotBuildAProperSignatureFromConfigWhenFullIdentityCannotBeFoundInTheConfig(string name, string email)
419401
{
420402
string repoPath = InitNewRepository();
421-
string configPath = CreateConfigurationWithDummyUser(name, email);
422-
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };
423403

424-
using (var repo = new Repository(repoPath, options))
404+
using (var repo = new Repository(repoPath))
425405
{
406+
CreateConfigurationWithDummyUser(repo, name, email);
426407
Assert.Equal(name, repo.Config.GetValueOrDefault<string>("user.name"));
427408
Assert.Equal(email, repo.Config.GetValueOrDefault<string>("user.email"));
428409

LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

+6-25
Original file line numberDiff line numberDiff line change
@@ -1044,12 +1044,9 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
10441044
repo.Config.Unset("core.filemode");
10451045
}
10461046

1047-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
1048-
1049-
var options = BuildFakeSystemConfigFilemodeOption(scd, true);
1050-
1051-
using (var repo = new Repository(path, options))
1047+
using (var repo = new Repository(path))
10521048
{
1049+
SetFilemode(repo, true);
10531050
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });
10541051

10551052
Assert.Equal(1, changes.Count());
@@ -1059,34 +1056,18 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
10591056
Assert.Equal(Mode.NonExecutableFile, change.Mode);
10601057
}
10611058

1062-
options = BuildFakeSystemConfigFilemodeOption(scd, false);
1063-
1064-
using (var repo = new Repository(path, options))
1059+
using (var repo = new Repository(path))
10651060
{
1061+
SetFilemode(repo, false);
10661062
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });
10671063

10681064
Assert.Equal(0, changes.Count());
10691065
}
10701066
}
10711067

1072-
private RepositoryOptions BuildFakeSystemConfigFilemodeOption(
1073-
SelfCleaningDirectory scd,
1074-
bool value)
1068+
void SetFilemode(Repository repo, bool value)
10751069
{
1076-
Directory.CreateDirectory(scd.DirectoryPath);
1077-
1078-
var options = new RepositoryOptions
1079-
{
1080-
SystemConfigurationLocation = Path.Combine(
1081-
scd.RootedDirectoryPath, "fake-system.config")
1082-
};
1083-
1084-
StringBuilder sb = new StringBuilder()
1085-
.AppendFormat("[core]{0}", Environment.NewLine)
1086-
.AppendFormat("filemode = {1}{0}", Environment.NewLine, value);
1087-
Touch("", options.SystemConfigurationLocation, sb.ToString());
1088-
1089-
return options;
1070+
repo.Config.Set("core.filemode", value);
10901071
}
10911072

10921073
[Fact]

LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs

+6-25
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,9 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
127127
repo.Config.Unset("core.filemode", ConfigurationLevel.Local);
128128
}
129129

130-
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
131-
132-
var options = BuildFakeSystemConfigFilemodeOption(scd, true);
133-
134-
using (var repo = new Repository(path, options))
130+
using (var repo = new Repository(path))
135131
{
132+
SetFilemode(repo, true);
136133
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });
137134

138135
Assert.Equal(1, changes.Count());
@@ -142,34 +139,18 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
142139
Assert.Equal(Mode.NonExecutableFile, change.Mode);
143140
}
144141

145-
options = BuildFakeSystemConfigFilemodeOption(scd, false);
146-
147-
using (var repo = new Repository(path, options))
142+
using (var repo = new Repository(path))
148143
{
144+
SetFilemode(repo, false);
149145
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });
150146

151147
Assert.Equal(0, changes.Count());
152148
}
153149
}
154150

155-
private RepositoryOptions BuildFakeSystemConfigFilemodeOption(
156-
SelfCleaningDirectory scd,
157-
bool value)
151+
void SetFilemode(Repository repo, bool value)
158152
{
159-
Directory.CreateDirectory(scd.DirectoryPath);
160-
161-
var options = new RepositoryOptions
162-
{
163-
SystemConfigurationLocation = Path.Combine(
164-
scd.RootedDirectoryPath, "fake-system.config")
165-
};
166-
167-
StringBuilder sb = new StringBuilder()
168-
.AppendFormat("[core]{0}", Environment.NewLine)
169-
.AppendFormat("filemode = {1}{0}", Environment.NewLine, value);
170-
File.WriteAllText(options.SystemConfigurationLocation, sb.ToString());
171-
172-
return options;
153+
repo.Config.Set("core.filemode", value);
173154
}
174155

175156
[Fact]

LibGit2Sharp.Tests/FetchFixture.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,7 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()
213213

214214
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);
215215

216-
var options = BuildFakeConfigs(BuildSelfCleaningDirectory());
217-
218-
using (var clonedRepo = new Repository(clonedRepoPath, options))
216+
using (var clonedRepo = new Repository(clonedRepoPath))
219217
{
220218
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote));
221219

LibGit2Sharp.Tests/FilterFixture.cs

+4-7
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

+10-15
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/MergeFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ public void MergeCanSpecifyMergeFileFavorOption(MergeFileFavor fileFavorFlag)
678678
const string conflictBranchName = "conflicts";
679679

680680
string path = SandboxMergeTestRepo();
681-
using (var repo = InitIsolatedRepository(path))
681+
using (var repo = new Repository(path))
682682
{
683683
Branch branch = repo.Branches[conflictBranchName];
684684
Assert.NotNull(branch);

0 commit comments

Comments
 (0)