Skip to content

Obsolete the config paths in RepositoryOptions #1274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

### Changes

- Obsolete the config paths in RepositoryOptions

### Fixes

## v0.22 - ([diff](https://github.com/libgit2/libgit2sharp/compare/v0.21.1...v0.22))
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/AttributesFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AttributesFixture : BaseFixture
[Fact]
public void StagingHonorsTheAttributesFiles()
{
using (var repo = InitIsolatedRepository())
using (var repo = new Repository(InitNewRepository()))
{
CreateAttributesFile(repo);

Expand Down
10 changes: 4 additions & 6 deletions LibGit2Sharp.Tests/BranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,10 @@ public void QueryRemoteForRemoteBranch()
[Fact]
public void QueryUnresolvableRemoteForRemoteBranch()
{
var path = SandboxStandardTestRepo();

var fetchRefSpecs = new string[] { "+refs/heads/notfound/*:refs/remotes/origin/notfound/*" };

using (var repo = InitIsolatedRepository(path))
var path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
// Update the remote config such that the remote for a
// remote branch cannot be resolved
Expand All @@ -472,12 +471,11 @@ public void QueryUnresolvableRemoteForRemoteBranch()
[Fact]
public void QueryAmbigousRemoteForRemoteBranch()
{
var path = SandboxStandardTestRepo();

const string fetchRefSpec = "+refs/heads/*:refs/remotes/origin/*";
const string url = "http://github.com/libgit2/TestGitRepository";

using (var repo = InitIsolatedRepository(path))
var path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
// Add a second remote so that it is ambiguous which remote
// the remote-tracking branch tracks.
Expand Down
5 changes: 2 additions & 3 deletions LibGit2Sharp.Tests/CommitFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,10 @@ public void DirectlyAccessingAnUnknownTreeEntryOfTheCommitReturnsNull()
public void CanCommitWithSignatureFromConfig()
{
string repoPath = InitNewRepository();
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };

using (var repo = new Repository(repoPath, options))
using (var repo = new Repository(repoPath))
{
CreateConfigurationWithDummyUser(repo, Constants.Identity);
string dir = repo.Info.Path;
Assert.True(Path.IsPathRooted(dir));
Assert.True(Directory.Exists(dir));
Expand Down
45 changes: 13 additions & 32 deletions LibGit2Sharp.Tests/ConfigurationFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,8 @@ public void CanUnsetAnEntryFromTheLocalConfiguration()
[Fact]
public void CanUnsetAnEntryFromTheGlobalConfiguration()
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

var options = BuildFakeConfigs(scd);

string path = SandboxBareTestRepo();
using (var repo = new Repository(path, options))
using (var repo = new Repository(path))
{
Assert.True(repo.Config.HasConfig(ConfigurationLevel.Global));
Assert.Equal(42, repo.Config.Get<int>("Wow.Man-I-am-totally-global").Value);
Expand Down Expand Up @@ -143,12 +139,10 @@ public void CanReadStringValue()
[Fact]
public void CanEnumerateGlobalConfig()
{
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };

var path = SandboxStandardTestRepoGitDir();
using (var repo = new Repository(path, options))
using (var repo = new Repository(path))
{
CreateConfigurationWithDummyUser(repo, Constants.Identity);
var entry = repo.Config.FirstOrDefault<ConfigurationEntry<string>>(e => e.Key == "user.name");
Assert.NotNull(entry);
Assert.Equal(Constants.Signature.Name, entry.Value);
Expand Down Expand Up @@ -200,16 +194,14 @@ public void CanFindInLocalConfig()
[Fact]
public void CanFindInGlobalConfig()
{
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };

var path = SandboxStandardTestRepoGitDir();
using (var repo = new Repository(path, options))
using (var repo = new Repository(path))
{
var matches = repo.Config.Find(@"\.name", ConfigurationLevel.Global);
var matches = repo.Config.Find("-rocks", ConfigurationLevel.Global);

Assert.NotNull(matches);
Assert.Equal(new[] { "user.name" },
Assert.Equal(new[] { "woot.this-rocks" },
matches.Select(m => m.Key).ToArray());
}
}
Expand Down Expand Up @@ -331,12 +323,8 @@ public void SettingUnsupportedTypeThrows()
[Fact]
public void CanGetAnEntryFromASpecificStore()
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

var options = BuildFakeConfigs(scd);

string path = SandboxStandardTestRepo();
using (var repo = new Repository(path, options))
using (var repo = new Repository(path))
{
Assert.True(repo.Config.HasConfig(ConfigurationLevel.Local));
Assert.True(repo.Config.HasConfig(ConfigurationLevel.Global));
Expand All @@ -356,12 +344,8 @@ public void CanGetAnEntryFromASpecificStore()
[Fact]
public void CanTellIfASpecificStoreContainsAKey()
{
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

var options = BuildFakeConfigs(scd);

string path = SandboxBareTestRepo();
using (var repo = new Repository(path, options))
using (var repo = new Repository(path))
{
Assert.True(repo.Config.HasConfig(ConfigurationLevel.System));

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

string globalConfigPath = CreateConfigurationWithDummyUser(Constants.Identity);
var options = new RepositoryOptions { GlobalConfigurationLocation = globalConfigPath };

using (var repo = new Repository(path, options))
using (var repo = new Repository(path))
{
repo.Config.Set("my.key", "local");
repo.Config.Set("my.key", "mouse", ConfigurationLevel.Global);
}

using (var config = Configuration.BuildFrom(localConfigurationPathProvider(path), globalConfigPath))
var globalPath = Path.Combine(GlobalSettings.GetConfigSearchPaths(ConfigurationLevel.Global).Single(), ".gitconfig");
using (var config = Configuration.BuildFrom(localConfigurationPathProvider(path), globalPath))
{
Assert.Equal("local", config.Get<string>("my.key").Value);
Assert.Equal("mouse", config.Get<string>("my.key", ConfigurationLevel.Global).Value);
Expand All @@ -418,11 +400,10 @@ public void PassingANonExistingLocalConfigurationFileToBuildFromthrowss()
public void CannotBuildAProperSignatureFromConfigWhenFullIdentityCannotBeFoundInTheConfig(string name, string email)
{
string repoPath = InitNewRepository();
string configPath = CreateConfigurationWithDummyUser(name, email);
var options = new RepositoryOptions { GlobalConfigurationLocation = configPath };

using (var repo = new Repository(repoPath, options))
using (var repo = new Repository(repoPath))
{
CreateConfigurationWithDummyUser(repo, name, email);
Assert.Equal(name, repo.Config.GetValueOrDefault<string>("user.name"));
Assert.Equal(email, repo.Config.GetValueOrDefault<string>("user.email"));

Expand Down
31 changes: 6 additions & 25 deletions LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,12 +1044,9 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
repo.Config.Unset("core.filemode");
}

SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

var options = BuildFakeSystemConfigFilemodeOption(scd, true);

using (var repo = new Repository(path, options))
using (var repo = new Repository(path))
{
SetFilemode(repo, true);
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });

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

options = BuildFakeSystemConfigFilemodeOption(scd, false);

using (var repo = new Repository(path, options))
using (var repo = new Repository(path))
{
SetFilemode(repo, false);
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });

Assert.Equal(0, changes.Count());
}
}

private RepositoryOptions BuildFakeSystemConfigFilemodeOption(
SelfCleaningDirectory scd,
bool value)
void SetFilemode(Repository repo, bool value)
{
Directory.CreateDirectory(scd.DirectoryPath);

var options = new RepositoryOptions
{
SystemConfigurationLocation = Path.Combine(
scd.RootedDirectoryPath, "fake-system.config")
};

StringBuilder sb = new StringBuilder()
.AppendFormat("[core]{0}", Environment.NewLine)
.AppendFormat("filemode = {1}{0}", Environment.NewLine, value);
Touch("", options.SystemConfigurationLocation, sb.ToString());

return options;
repo.Config.Set("core.filemode", value);
}

[Fact]
Expand Down
31 changes: 6 additions & 25 deletions LibGit2Sharp.Tests/DiffWorkdirToIndexFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,9 @@ public void ComparingReliesOnProvidedConfigEntriesIfAny()
repo.Config.Unset("core.filemode", ConfigurationLevel.Local);
}

SelfCleaningDirectory scd = BuildSelfCleaningDirectory();

var options = BuildFakeSystemConfigFilemodeOption(scd, true);

using (var repo = new Repository(path, options))
using (var repo = new Repository(path))
{
SetFilemode(repo, true);
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });

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

options = BuildFakeSystemConfigFilemodeOption(scd, false);

using (var repo = new Repository(path, options))
using (var repo = new Repository(path))
{
SetFilemode(repo, false);
var changes = repo.Diff.Compare<TreeChanges>(new[] { file });

Assert.Equal(0, changes.Count());
}
}

private RepositoryOptions BuildFakeSystemConfigFilemodeOption(
SelfCleaningDirectory scd,
bool value)
void SetFilemode(Repository repo, bool value)
{
Directory.CreateDirectory(scd.DirectoryPath);

var options = new RepositoryOptions
{
SystemConfigurationLocation = Path.Combine(
scd.RootedDirectoryPath, "fake-system.config")
};

StringBuilder sb = new StringBuilder()
.AppendFormat("[core]{0}", Environment.NewLine)
.AppendFormat("filemode = {1}{0}", Environment.NewLine, value);
File.WriteAllText(options.SystemConfigurationLocation, sb.ToString());

return options;
repo.Config.Set("core.filemode", value);
}

[Fact]
Expand Down
4 changes: 1 addition & 3 deletions LibGit2Sharp.Tests/FetchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()

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

var options = BuildFakeConfigs(BuildSelfCleaningDirectory());

using (var clonedRepo = new Repository(clonedRepoPath, options))
using (var clonedRepo = new Repository(clonedRepoPath))
{
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote));

Expand Down
11 changes: 4 additions & 7 deletions LibGit2Sharp.Tests/FilterFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,9 @@ public void CanFilterLargeFiles()
string attributesPath = Path.Combine(Directory.GetParent(repoPath).Parent.FullName, ".gitattributes");
FileInfo attributesFile = new FileInfo(attributesPath);

string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };

using (Repository repo = new Repository(repoPath, repositoryOptions))
using (Repository repo = new Repository(repoPath))
{
CreateConfigurationWithDummyUser(repo, Constants.Identity);
File.WriteAllText(attributesPath, "*.blob filter=test");
repo.Stage(attributesFile.Name);
repo.Stage(contentFile.Name);
Expand Down Expand Up @@ -421,9 +419,8 @@ private static FileInfo StageNewFile(IRepository repo, string contents = "null")

private Repository CreateTestRepository(string path)
{
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
var repository = new Repository(path, repositoryOptions);
var repository = new Repository(path);
CreateConfigurationWithDummyUser(repository, Constants.Identity);
CreateAttributesFile(repository, "* filter=test");
return repository;
}
Expand Down
25 changes: 10 additions & 15 deletions LibGit2Sharp.Tests/FilterSubstitutionCipherFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public void SmugdeIsNotCalledForFileWhichDoesNotMatchAnAttributeEntry()

string repoPath = InitNewRepository();
string fileName = Guid.NewGuid() + ".rot13";
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
using (var repo = new Repository(repoPath, repositoryOptions))
using (var repo = new Repository(repoPath))
{
CreateConfigurationWithDummyUser(repo, Constants.Identity);
CreateAttributesFile(repo, "*.rot13 filter=rot13");

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

string repoPath = InitNewRepository();
string fileName = Guid.NewGuid() + ".rot13";
string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
using (var repo = new Repository(repoPath, repositoryOptions))
using (var repo = new Repository(repoPath))
{
CreateConfigurationWithDummyUser(repo, Constants.Identity);
CreateAttributesFile(repo, "*.rot13 filter=rot13");

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

string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
using (var repo = new Repository(repoPath, repositoryOptions))
using (var repo = new Repository(repoPath))
{
CreateConfigurationWithDummyUser(repo, Constants.Identity);
CreateAttributesFile(repo, attributeFileEntry);

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

string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
using (var repo = new Repository(repoPath, repositoryOptions))
using (var repo = new Repository(repoPath))
{
CreateConfigurationWithDummyUser(repo, Constants.Identity);
CreateAttributesFile(repo, attributeEntry);

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

string configPath = CreateConfigurationWithDummyUser(Constants.Identity);
var repositoryOptions = new RepositoryOptions { GlobalConfigurationLocation = configPath };
using (var repo = new Repository(repoPath, repositoryOptions))
using (var repo = new Repository(repoPath))
{
CreateConfigurationWithDummyUser(repo, Constants.Identity);
CreateAttributesFile(repo, attributeEntry);

CommitOnBranchAndReturnDatabaseBlob(repo, fileName, decodedInput);
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp.Tests/MergeFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ public void MergeCanSpecifyMergeFileFavorOption(MergeFileFavor fileFavorFlag)
const string conflictBranchName = "conflicts";

string path = SandboxMergeTestRepo();
using (var repo = InitIsolatedRepository(path))
using (var repo = new Repository(path))
{
Branch branch = repo.Branches[conflictBranchName];
Assert.NotNull(branch);
Expand Down
Loading