|
1 |
| -using System.Collections.Generic; |
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
2 | 4 | using System.Linq;
|
3 | 5 | using LibGit2Sharp.Tests.TestHelpers;
|
4 | 6 | using Xunit;
|
@@ -188,5 +190,44 @@ public void CanFetchAllTagsAfterAnInitialClone()
|
188 | 190 | repo.Fetch("origin", new FetchOptions { TagFetchMode = TagFetchMode.All });
|
189 | 191 | }
|
190 | 192 | }
|
| 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 | + } |
191 | 232 | }
|
192 | 233 | }
|
0 commit comments