8000 Add some auto pruning test coverage upon Fetch() · GiTechLab/libgit2sharp@2c4457e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c4457e

Browse files
committed
Add some auto pruning test coverage upon Fetch()
1 parent c91fb85 commit 2c4457e

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

LibGit2Sharp.Tests/FetchFixture.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
24
using System.Linq;
35
using LibGit2Sharp.Tests.TestHelpers;
46
using Xunit;
@@ -188,5 +190,44 @@ public void CanFetchAllTagsAfterAnInitialClone()
188190
repo.Fetch("origin", new FetchOptions { TagFetchMode = TagFetchMode.All });
189191
}
190192
}
193+
194+
[Fact]
195+
public void FetchHonorsTheFetchPruneConfigurationEntry()
196+
{
197+
var source = SandboxBareTestRepo();
198+
var url = new Uri(Path.GetFullPath(source)).AbsoluteUri;
199+
200+
var scd = BuildSelfCleaningDirectory();
201+
202+
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);
203+
204+
var options = BuildFakeConfigs(BuildSelfCleaningDirectory());
205+
206+
using (var clonedRepo = new Repository(clonedRepoPath, options))
207+
{
208+
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote));
209+
210+
// Drop one of the branches in the remote repository
211+
using (var sourceRepo = new Repository(source))
212+
{
213+
sourceRepo.Branches.Remove("packed-test");
214+
}
215+
216+
// No pruning when the configuration entry isn't defined
217+
Assert.Null(clonedRepo.Config.Get<bool>("fetch.prune"));
218+
clonedRepo.Fetch("origin");
219+
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote));
220+
221+
// No pruning when the configuration entry is set to false
222+
clonedRepo.Config.Set<bool>("fetch.prune", false);
223+
clonedRepo.Fetch("origin");
224+
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote));
225+
226+
// Auto pruning when the configuration entry is set to true
227+
clonedRepo.Config.Set<bool>("fetch.prune", true);
228+
clonedRepo.Fetch("origin");
229+
Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote));
230+
}
231+
}
191232
}
192233
}

0 commit comments

Comments
 (0)
0