dazinator / FluentGit

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

RefSpec Builder #3

Closed dazinator closed 9 years ago

dazinator commented 9 years ago

Provide a fluent builder for RefSpec's

For example consider the refspec: +refs/heads/*:refs/remotes/origin/*

The format of the refspec is an optional +, followed by <src>:<dst>, where <src> is the pattern for references on the remote side and <dst> is where those references will be written locally. The + tells Git to update the reference even if it isn’t a fast-forward.

So, create a builder API for building that type of string, something like this:

var refSpec = refSpecBuilder.Source("refs/heads/*")                                             
                            .Destination("refs/remotes/origin/*")
                            .ForceUpdateIfFastForwardNotPossible()
                            .ToString();
dazinator commented 9 years ago

The builder has been written. The following (taken from unit test) shows how it is used:

            IRefSpecBuilder builder = new RefSpecBuilder();

            RefSpecInfo spec = builder.Source("refs/heads/*")
                                .Destination("refs/remotes/origin/*")
                                .ForceUpdateIfFastForwardNotPossible()
                                .ToRefSpec();

            Assert.That(spec.Source, Is.EqualTo("refs/heads/*"));
            Assert.That(spec.Destination, Is.EqualTo("refs/remotes/origin/*"));
            Assert.That(spec.ForceUpdateWhenFastForwardNotAllowed);

            Assert.That(spec.ToString(), Is.EqualTo("+refs/heads/*:refs/remotes/origin/*"));

You can also pass the builder in an existing refspec to modify it.