Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions LibGit2Sharp.Tests/RemoteFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,43 @@ public void CanNotRenameWhenRemoteWithSameNameExists()
Assert.Throws<NameConflictException>(() => 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<bool>("fetch.prune"));
Assert.Null(repo.Config.Get<bool>("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);
}
}
}
25 changes: 25 additions & 0 deletions LibGit2Sharp/Remote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,31 @@ public static bool IsValidName(string name)
return Proxy.git_remote_is_valid_name(name);
}

/// <summary>
/// Gets the configured behavior regarding the deletion
/// of stale remote tracking branches.
/// <para>
/// If defined, will return the value of the <code>remote.&lt;name&gt;.prune</code> entry.
/// Otherwise return the value of <code>fetch.prune</code>.
/// </para>
/// </summary>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Add some description about the logic when we reach an agreement (also consider fetch.prune or not?)

public virtual bool AutomaticallyPruneOnFetch
{
get
{
var remotePrune = repository.Config.Get<bool>("remote", Name, "prune");

if (remotePrune != null)
{
return remotePrune.Value;
}

var fetchPrune = repository.Config.Get<bool>("fetch.prune");

return fetchPrune != null && fetchPrune.Value;
}
}

/// <summary>
/// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="Remote"/>.
/// </summary>
Expand Down