-
Notifications
You must be signed in to change notification settings - Fork 894
/
Copy pathBranchTrackingDetails.cs
63 lines (57 loc) · 2.15 KB
/
BranchTrackingDetails.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
namespace LibGit2Sharp
{
/// <summary>
/// Tracking information for a <see cref="Branch"/>
/// </summary>
public class BranchTrackingDetails
{
private readonly HistoryDivergence historyDivergence;
/// <summary>
/// Needed for mocking purposes.
/// </summary>
protected BranchTrackingDetails()
{ }
internal BranchTrackingDetails(Repository repo, Branch branch)
{
if (!branch.IsTracking || branch.Tip == null || branch.TrackedBranch.Tip == null)
{
historyDivergence = new NullHistoryDivergence();
return;
}
historyDivergence = repo.ObjectDatabase.CalculateHistoryDivergence(branch.Tip, branch.TrackedBranch.Tip);
}
/// <summary>
/// Gets the number of commits that exist in this local branch but don't exist in the tracked one.
/// <para>
/// This property will return <c>null</c> if this local branch has no upstream configuration
/// or if the upstream branch does not exist
/// </para>
/// </summary>
public virtual int? AheadBy
{
get { return historyDivergence.AheadBy; }
}
/// <summary>
/// Gets the number of commits that exist in the tracked branch but don't exist in this local one.
/// <para>
/// This property will return <c>null</c> if this local branch has no upstream configuration
/// or if the upstream branch does not exist
/// </para>
/// </summary>
public virtual int? BehindBy
{
get { return historyDivergence.BehindBy; }
}
/// <summary>
/// Gets the common ancestor of the local branch and its tracked remote branch.
/// <para>
/// This property will return <c>null</c> if this local branch has no upstream configuration,
/// the upstream branch does not exist, or either branch is an orphan.
/// </para>
/// </summary>
public virtual Commit CommonAncestor
{
get { return historyDivergence.CommonAncestor; }
}
}
}