10000 Teach Remote to expose the AutomaticallyPruneOnFetch property · GiTechLab/libgit2sharp@2d5cdda · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d5cdda

Browse files
committed
Teach Remote to expose the AutomaticallyPruneOnFetch property
1 parent 3a3c93c commit 2d5cdda

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

LibGit2Sharp.Tests/RemoteFixture.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,5 +334,43 @@ public void CanNotRenameWhenRemoteWithSameNameExists()
334334
Assert.Throws<NameConflictException>(() => repo.Network.Remotes.Rename("origin", "upstream"));
335335
}
336336
}
337+
338+
[Theory]
339+
[InlineData(null, null, false)]
340+
[InlineData(null, false, false)]
341+
[InlineData(null, true, true)]
342+
[InlineData(false, null, false)]
343+
[InlineData(false, false, false)]
344+
[InlineData(false, true, true)]
345+
[InlineData(true, null, true)]
346+
[InlineData(true, false, false)]
347+
[InlineData(true, true, true)]
348+
public void ShoudlPruneOnFetchReflectsTheConfiguredSetting(bool? fetchPrune, bool? remotePrune, bool expectedFetchPrune)
349+
{
350+
var path = SandboxStandardTestRepo();
351+
var scd = BuildSelfCleaningDirectory();
352+
353+
using (var repo = new Repository(path, BuildFakeConfigs(scd)))
354+
{
355+
Assert.Null(repo.Config.Get<bool>("fetch.prune"));
356+
Assert.Null(repo.Config.Get<bool>("remote.origin.prune"));
357+
358+
SetIfNotNull(repo, "fetch.prune", fetchPrune);
359+
SetIfNotNull(repo, "remote.origin.prune", remotePrune);
360+
361+
var remote = repo.Network.Remotes["origin"];
362+
Assert.Equal(expectedFetchPrune, remote.AutomaticallyPruneOnFetch);
363+
}
364+
}
365+
366+
private void SetIfNotNull(IRepository repo, string configName, bool? value)
367+
{
368+
if (!value.HasValue)
369+
{
370+
return;
371+
}
372+
373+
repo.Config.Set(configName, value.Value);
374+
}
337375
}
338376
}

LibGit2Sharp/Remote.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,31 @@ public static bool IsValidName(string name)
105105
return Proxy.git_remote_is_valid_name(name);
106106
}
107107

108+
/// <summary>
109+
/// Gets the configured behavior regarding the deletion
110+
/// of stale remote tracking branches.
111+
/// <para>
112+
/// If defined, will return the value of the <code>remote.&lt;name&gt;.prune</code> entry.
113+
/// Otherwise return the value of <code>fetch.prune</code>.
114+
/// </para>
115+
/// </summary>
116+
public virtual bool AutomaticallyPruneOnFetch
117+
{
118+
get
119+
{
120+
var remotePrune = repository.Config.Get<bool>("remote", Name, "prune");
121+
122+
if (remotePrune != null)
123+
{
124+
return remotePrune.Value;
125+
}
126+
127+
var fetchPrune = repository.Config.Get<bool>("fetch.prune");
128+
129+
return fetchPrune != null && fetchPrune.Value;
130+
}
131+
}
132+
108133
/// <summary>
109134
/// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="Remote"/>.
110135
/// </summary>

0 commit comments

Comments
 (0)
0