Frage

how do I set multiple values for a config-key? Some sections supports multiple values:

[remote "origin"]
   url = git@github.com:schacon/simplegit-progit.git
   fetch = +refs/heads/master:refs/remotes/origin/master
   fetch = +refs/heads/qa/*:refs/remotes/origin/qa/*

Something like this is not working in gitLib2Sharp:

string[] refSpecs = {"+refs/heads/master:refs/remotes/origin/master", "+refs/heads/qa/*:refs/remotes/origin/qa/*"};
repo.Config.Set( @"remote.origin.fetch", refSpec );   
War es hilfreich?

Lösung

How do I set multiple values for a config-key

This is indeed a currently missing feature in LibGit2Sharp. An issue has just been opened to track this.

However, if what you're after is setting/updating the default refspecs of a remote, the repo.Network.Remotes.Update() method may already fit that need without having to wait for the issue to be fixed.

  • Pull request #567 recently enhanced the Remotes.Update() method to make it cope with refspecs updation. As such, your example could be fulfilled with the following code.
    var fetchSpecs = new string[]
    {
        "+refs/heads/master:refs/remotes/origin/master",
        "+refs/heads/qa/*:refs/remotes/origin/qa/*"
    };

    using (var repo = new Repository(path))
    {
        var remote = repo.Network.Remotes["origin"];
        repo.Network.Remotes.Update(remote, r => r.FetchRefSpecs = fetchSpecs);
    }
  • More or less related, pull request #553 introduced an easy way to enumerate all the refspecs of a remote
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top