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
35 changes: 35 additions & 0 deletions LibGit2Sharp.Tests/NetworkFixture.cs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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