-
Notifications
You must be signed in to change notification settings - Fork 897
/
Copy pathPull.cs
41 lines (34 loc) · 1.5 KB
/
Pull.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
/// <summary>
/// Fetch changes from the configured upstream remote and branch into the branch pointed at by HEAD.
/// </summary>
public static partial class Commands
{
/// <summary>
/// Fetch changes from the configured upstream remote and branch into the branch pointed at by HEAD.
/// </summary>
/// <param name="repository">The repository.</param>
/// <param name="merger">The signature to use for the merge.</param>
/// <param name="options">The options for fetch and merging.</param>
public static MergeResult Pull(Repository repository, Signature merger, PullOptions options)
{
Ensure.ArgumentNotNull(repository, nameof(repository));
Ensure.ArgumentNotNull(merger, nameof(merger));
options = options ?? new PullOptions();
Branch currentBranch = repository.Head;
if (!currentBranch.IsTracking)
{
throw new LibGit2SharpException("There is no tracking information for the current branch.");
}
if (currentBranch.RemoteName == null)
{
throw new LibGit2SharpException("No upstream remote for the current branch.");
}
Commands.Fetch(repository, currentBranch.RemoteName, Array.Empty<string>(), options.FetchOptions, null);
return repository.MergeFetchedRefs(merger, options.MergeOptions);
}
}
}