8000 Introduce Repository.MergeFetchedRefs · GiTechLab/libgit2sharp@4d41aba · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d41aba

Browse files
Edward Thomsonnulltoken
Edward Thomson
authored andcommitted
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 2d5cdda commit 4d41aba

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-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
@@ -222,6 +222,18 @@ public interface IRepository : IDisposable
222222
/// <returns>The <see cref="MergeResult"/> of the merge.</returns>
223223
MergeResult Merge(string committish, Signature merger, MergeOptions options);
224224

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

LibGit2Sharp/Network.cs

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

308308
Fetch(currentBranch.Remote, options.FetchOptions);
309-
return repository.MergeFetchHeads(merger, options.MergeOptions);
309+
return repository.MergeFetchedRefs(merger, options.MergeOptions);
310310
}
311311

312312
/// <summary>

LibGit2Sharp/Repository.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,12 +1040,16 @@ public MergeResult Merge(string committish, Signature merger, MergeOptions optio
10401040
}
10411041

10421042
/// <summary>
1043-
/// Merge the current fetch heads into the branch pointed at by HEAD.
1043+
/// Merge the reference that was recently fetched. This will merge
1044+
/// the branch on the fetched remote that corresponded to the
1045+
/// current local branch when we did the fetch. This is the
1046+
/// second step in performing a pull operation (after having
1047+
/// performed said fetch).
10441048
/// </summary>
10451049
/// <param name="merger">The <see cref="Signature"/> of who is performing the merge.</param>
10461050
/// <param name="options">Specifies optional parameters controlling merge behavior; if null, the defaults are used.</param>
10471051
/// <returns>The <see cref="MergeResult"/> of the merge.</returns>
1048-
internal MergeResult MergeFetchHeads(Signature merger, MergeOptions options)
1052+
public MergeResult MergeFetchedRefs(Signature merger, MergeOptions options)
10491053
{
10501054
Ensure.ArgumentNotNull(merger, "merger");
10511055

0 commit comments

Comments
 (0)
0