Skip to content

Commit

Permalink
Merge pull request #1258 from libgit2/cmn/prune
Browse files Browse the repository at this point in the history
Expose the prune option for fetching
  • Loading branch information
Edward Thomson committed Feb 15, 2016
2 parents 327dbff + 4ecd3e8 commit b46ee5e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
35 changes: 35 additions & 0 deletions LibGit2Sharp.Tests/NetworkFixture.cs
Expand Up @@ -263,5 +263,40 @@ public void CanMergeFetchedRefs()
Assert.Equal(mergeResult.Status, MergeStatus.NonFastForward);
}
}

[Fact]
public void CanPruneRefs()
{
string url = "https://github.com/libgit2/TestGitRepository";

var scd = BuildSelfCleaningDirectory();
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

var scd2 = BuildSelfCleaningDirectory();
string clonedRepoPath2 = Repository.Clone(url, scd2.DirectoryPath);


using (var repo = new Repository(clonedRepoPath))
{
repo.Network.Remotes.Add("pruner", "file://" + clonedRepoPath2);
var remote = repo.Network.Remotes["pruner"];
repo.Network.Fetch(remote);
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);

// Remove the branch from the source repository
using (var repo2 = new Repository(clonedRepoPath2))
{
repo2.Refs.Remove("refs/heads/master");
}

// and by default we don't prune it
repo.Network.Fetch(remote);
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);

// but we do when asked by the user
repo.Network.Fetch(remote, new FetchOptions { Prune = true} );
Assert.Null(repo.Refs["refs/remotes/pruner/master"]);
}
}
}
}
9 changes: 9 additions & 0 deletions LibGit2Sharp/FetchOptions.cs
Expand Up @@ -16,5 +16,14 @@ public sealed class FetchOptions : FetchOptionsBase
/// retrieved during this fetch will be retrieved as well).</para>
/// </summary>
public TagFetchMode? TagFetchMode { get; set; }

/// <summary>
/// Specifies the pruning behaviour for the fetch operation
/// <para>
/// If not set, the configuration's setting will take effect. If true, the branches which no longer
/// exist on the remote will be removed from the remote-tracking branches.
/// </para>
/// </summary>
public bool? Prune { get; set; }
}
}
9 changes: 9 additions & 0 deletions LibGit2Sharp/Network.cs
Expand Up @@ -206,6 +206,15 @@ private static void DoFetch(FetchOptions options, RemoteSafeHandle remoteHandle,
fetchOptions.download_tags = options.TagFetchMode.Value;
}

if (options.Prune.HasValue)
{
fetchOptions.Prune = options.Prune.Value ? FetchPruneStrategy.Prune : FetchPruneStrategy.NoPrune;
}
else
{
fetchOptions.Prune = FetchPruneStrategy.FromConfigurationOrDefault;
}

Proxy.git_remote_fetch(remoteHandle, refspecs, fetchOptions, logMessage);
}

Expand Down

0 comments on commit b46ee5e

Please sign in to comment.