Skip to content

Overrides for system and global configuration file locations #157

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

Closed
nulltoken opened this issue May 25, 2012 · 3 comments
Closed

Overrides for system and global configuration file locations #157

nulltoken opened this issue May 25, 2012 · 3 comments
Milestone

Comments

@nulltoken
Copy link
Member

By default, LibGit2Sharp searches for configuration files in the following places:

  • System: %PROGRAMFILES%\Git\etc\gitconfig or /etc/gitconfig
  • Global: %USERPROFILE%\.gitconfig or ~/.gitconfig

Beside the automatic probing for those files, providing with the user with a way to select different config files may come handy.

@ghost ghost assigned nulltoken May 25, 2012
@nulltoken
Copy link
Member Author

Proposed client code (in RepositoryOptionsFixture.cs)

[Fact]
public void CanProvideDifferentConfigurationFilesToARepository()
{
    string globalLocation = Path.Combine(newWorkdir, "my-global-config");
    string systemLocation = Path.Combine(newWorkdir, "my-system-config");

    const string name = "Adam 'aroben' Roben";
    const string email = "[email protected]";

    StringBuilder sb = new StringBuilder()
        .AppendLine("[user]")
        .AppendFormat("name = {0}{1}", name, Environment.NewLine)
        .AppendFormat("email = {0}{1}", email, Environment.NewLine);

    File.WriteAllText(globalLocation, sb.ToString());

    var options = new RepositoryOptions {
        GlobalConfigurationLocation = globalLocation,
        SystemConfigurationLocation = systemLocation,
    };

    using (var repo = new Repository(BareTestRepoPath, options))
    {
        Assert.True(repo.Config.HasGlobalConfig);
        Assert.Equal(name, repo.Config.Get<string>("user", "name", null));
        Assert.Equal(email, repo.Config.Get<string>("user", "email", null));

        repo.Config.Set("help.link", "https://twitter.com/xpaulbettsx/status/205761932626636800", ConfigurationLevel.System);
    }

    AssertValueInConfigFile(systemLocation, "xpaulbettsx");
}

@yorah
Copy link
Contributor

yorah commented May 25, 2012

🆒

@nulltoken
Copy link
Member Author

Released as part of v0.9.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants