From 2d5cddac4d39075ebe5252b263154f7327b4ce79 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Wed, 11 Feb 2015 23:01:02 +0100 Subject: [PATCH] Teach Remote to expose the AutomaticallyPruneOnFetch property --- LibGit2Sharp.Tests/RemoteFixture.cs | 38 +++++++++++++++++++++++++++++ LibGit2Sharp/Remote.cs | 25 +++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/LibGit2Sharp.Tests/RemoteFixture.cs b/LibGit2Sharp.Tests/RemoteFixture.cs index 47d51390f..1cab21f28 100644 --- a/LibGit2Sharp.Tests/RemoteFixture.cs +++ b/LibGit2Sharp.Tests/RemoteFixture.cs @@ -334,5 +334,43 @@ public void CanNotRenameWhenRemoteWithSameNameExists() Assert.Throws(() => repo.Network.Remotes.Rename("origin", "upstream")); } } + + [Theory] + [InlineData(null, null, false)] + [InlineData(null, false, false)] + [InlineData(null, true, true)] + [InlineData(false, null, false)] + [InlineData(false, false, false)] + [InlineData(false, true, true)] + [InlineData(true, null, true)] + [InlineData(true, false, false)] + [InlineData(true, true, true)] + public void ShoudlPruneOnFetchReflectsTheConfiguredSetting(bool? fetchPrune, bool? remotePrune, bool expectedFetchPrune) + { + var path = SandboxStandardTestRepo(); + var scd = BuildSelfCleaningDirectory(); + + using (var repo = new Repository(path, BuildFakeConfigs(scd))) + { + Assert.Null(repo.Config.Get("fetch.prune")); + Assert.Null(repo.Config.Get("remote.origin.prune")); + + SetIfNotNull(repo, "fetch.prune", fetchPrune); + SetIfNotNull(repo, "remote.origin.prune", remotePrune); + + var remote = repo.Network.Remotes["origin"]; + Assert.Equal(expectedFetchPrune, remote.AutomaticallyPruneOnFetch); + } + } + + private void SetIfNotNull(IRepository repo, string configName, bool? value) + { + if (!value.HasValue) + { + return; + } + + repo.Config.Set(configName, value.Value); + } } } diff --git a/LibGit2Sharp/Remote.cs b/LibGit2Sharp/Remote.cs index 7884342be..2aa5da7b7 100644 --- a/LibGit2Sharp/Remote.cs +++ b/LibGit2Sharp/Remote.cs @@ -105,6 +105,31 @@ public static bool IsValidName(string name) return Proxy.git_remote_is_valid_name(name); } + /// + /// Gets the configured behavior regarding the deletion + /// of stale remote tracking branches. + /// + /// If defined, will return the value of the remote.<name>.prune entry. + /// Otherwise return the value of fetch.prune. + /// + /// + public virtual bool AutomaticallyPruneOnFetch + { + get + { + var remotePrune = repository.Config.Get("remote", Name, "prune"); + + if (remotePrune != null) + { + return remotePrune.Value; + } + + var fetchPrune = repository.Config.Get("fetch.prune"); + + return fetchPrune != null && fetchPrune.Value; + } + } + /// /// Determines whether the specified is equal to the current . ///