dazinator / FluentGit

A fluent API for managing Git repositories in .NET.
0 stars 0 forks source link

Provide fluent API for remotes. #1

Open dazinator opened 9 years ago

dazinator commented 9 years ago

Fluent API should allow:

  1. Iterating all remotes. done.
  2. Creating new remotes. done.
  3. Updating an existing remote. done.
  4. Deleting an existing remote.
  5. Should allow modifying the default refspecs for Fetch and (done) Push commands that are subsequently done against the remote. This ties in with #3
dazinator commented 9 years ago

Updating remotes looks like this:


  var repo = new FluentRepo()
                                .Load(GitRepoPath)
                                .UpdateRemote(r => r.Name == "fluentgit",
                                    u =>
                                        u.ChangeUrlTo("https://github.com/libgit2/libgit2sharp.git")
                                         .ChangeRefSpecs()
                                            .Add("+refs/heads/master:refs/remotes/fluentgit/master")
                                        // can alternatively use RefSpecBuilder to build refspec strings:
                                            .Add(b =>
                                             b.Source("refs/heads/master")
                                              .Destination("refs/other/fluentgit/master")
                                              .ForceUpdateIfFastForwardNotPossible())

                                            .AddIfNotExists("+refs/heads/*:refs/remotes/fluentgit/*")
                                            .Remove("+refs/heads/somebranch:refs/remotes/somebranch"))

                                .UpdateRemoteIfExists(r => r.Url == "non existing url",
                                    u =>
                                        // as the remote doesn't exist in this case, none of the below updates will execute.
                                        u.ChangeUrlTo("http://someurl.com")
                                         .ChangeRefSpecs()
                                            .Add("+whatever/*:whatever/*")
                                            .Remove("+blah/*:blah/*"));