Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 3, 2023. It is now read-only.

Commit 4305267

Browse files
author
Edward Thomson
committed
Introduce Repository.MergeFetchedRefs
Make `Repository.MergeFetchHeads` public (with a slightly less scary sounding name) so that a consumer may perform the mechanics of a `Pull` in two steps.
1 parent db0b052 commit 4305267

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

LibGit2Sharp.Tests/NetworkFixture.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,33 @@ public void PullWithoutMergeBranchThrows()
228228
}
229229
}
230230

231+
[Fact]
232+
public void CanMergeFetchedRefs()
233+
{
234+
string url = "https://github.com/libgit2/TestGitRepository";
235+
236+
var scd = BuildSelfCleaningDirectory();
237+
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);
238+
239+
using (var repo = new Repository(clonedRepoPath))
240+
{
241+
repo.Reset(ResetMode.Hard, "HEAD~1");
242+
243+
Assert.False(repo.RetrieveStatus().Any());
244+
Assert.Equal(repo.Lookup<Commit>("refs/remotes/origin/master~1"), repo.Head.Tip);
245+
246+
repo.Network.Fetch(repo.Head.Remote);
247+
248+
MergeOptions mergeOptions = new MergeOptions()
249+
{
250+
FastForwardStrategy = FastForwardStrategy.NoFastFoward
251+
};
252+
253+
MergeResult mergeResult = repo.MergeFetchedRefs(Constants.Signature, mergeOptions);
254+
Assert.Equal(mergeResult.Status, MergeStatus.NonFastForward);
255+
}
256+
}
257+
231258
/*
232259
* git ls-remote http://github.com/libgit2/TestGitRepository
233260
* 49322bb17d3acc9146f98c97d078513228bbf3c0 HEAD

LibGit2Sharp/IRepository.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,18 @@ public interface IRepository : IDisposable
223223
/// <returns>The <see cref="MergeResult"/> of the merge.</returns>
224224
MergeResult Merge(string committish, Signature merger, MergeOptions options);
225225

226+
/// <summary>
227+
/// Merge the reference that was recently fetched. This will merge
228+
/// the branch on the fetched remote that corresponded to the
229+
/// current local branch when we did the fetch. This is the
230+
/// second step in performing a pull operation (after having
231+
/// performed said fetch).
232+
/// </summary>
233+
/// <param name="merger">The <see cref="Signature"/> of who is performing the merge.</param>
234+
/// <param name="options">Specifies optional parameters controlling merge behavior; if null, the defaults are used.</param>
235+
/// <returns>The <see cref="MergeResult"/> of the merge.</returns>
236+
MergeResult MergeFetchedRefs(Signature merger, MergeOptions options);
237+
226238
/// <summary>
227239
/// Cherry picks changes from the commit into the branch pointed at by HEAD.
228240
/// </summary>

LibGit2Sharp/Network.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public virtual MergeResult Pull(Signature merger, PullOptions options)
344344
}
345345

346346
Fetch(currentBranch.Remote, options.FetchOptions);
347-
return repository.MergeFetchHeads(merger, options.MergeOptions);
347+
return repository.MergeFetchedRefs(merger, options.MergeOptions);
348348
}
349349

350350
/// <summary>

LibGit2Sharp/Repository.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,12 +1030,15 @@ public MergeResult Merge(string committish, Signature merger, MergeOptions optio
10301030
}
10311031

10321032
/// <summary>
1033-
/// Merge the current fetch heads into the branch pointed at by HEAD.
1033+
/// the branch on the fetched remote that corresponded to the
1034+
/// current local branch when we did the fetch. This is the
1035+
/// second step in performing a pull operation (after having
1036+
/// performed said fetch).
10341037
/// </summary>
10351038
/// <param name="merger">The <see cref="Signature"/> of who is performing the merge.</param>
10361039
/// <param name="options">Specifies optional parameters controlling merge behavior; if null, the defaults are used.</param>
10371040
/// <returns>The <see cref="MergeResult"/> of the merge.</returns>
1038-
internal MergeResult MergeFetchHeads(Signature merger, MergeOptions options)
1041+
public MergeResult MergeFetchedRefs(Signature merger, MergeOptions options)
10391042
{
10401043
Ensure.ArgumentNotNull(merger, "merger");
10411044

0 commit comments

Comments
 (0)