Skip to content

Commit e4a3907

Browse files
committed
Rebase progress / results should return the commit, instead of just the id
1 parent 339a9c7 commit e4a3907

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

LibGit2Sharp.Tests/RebaseFixture.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void CanRebase(string initialBranchName,
5050
int beforeStepCallCount = 0;
5151
int afterStepCallCount = 0;
5252

53-
List<ObjectId> PreRebaseCommits = new List<ObjectId>();
53+
List<Commit> PreRebaseCommits = new List<Commit>();
5454
List<CompletedRebaseStepInfo> PostRebaseResults = new List<CompletedRebaseStepInfo>();
5555
ObjectId expectedParentId = upstream.Tip.Id;
5656

@@ -59,12 +59,12 @@ public void CanRebase(string initialBranchName,
5959
RebaseStepStarting = x =>
6060
{
6161
beforeStepCallCount++;
62-
PreRebaseCommits.Add(x.StepInfo.ID);
62+
PreRebaseCommits.Add(x.StepInfo.Commit);
6363
},
6464
RebaseStepCompleted = x =>
6565
{
6666
afterStepCallCount++;
67-
PostRebaseResults.Add(new CompletedRebaseStepInfo(x.CommitId, x.WasPatchAlreadyApplied));
67+
PostRebaseResults.Add(new CompletedRebaseStepInfo(x.Commit, x.WasPatchAlreadyApplied));
6868
},
6969
};
7070

@@ -88,31 +88,31 @@ public void CanRebase(string initialBranchName,
8888
Until = expectedUntilCommit,
8989
SortBy = CommitSortStrategies.Reverse | CommitSortStrategies.Topological,
9090
};
91-
Assert.Equal(repo.Commits.QueryBy(sourceCommitFilter).Select(c => c.Id), PreRebaseCommits);
91+
Assert.Equal(repo.Commits.QueryBy(sourceCommitFilter), PreRebaseCommits);
9292

9393
// Verify the chain of commits that resulted from the rebase.
9494
Commit expectedParent = expectedOntoCommit;
9595
foreach(CompletedRebaseStepInfo stepInfo in PostRebaseResults)
9696
{
97-
Commit rebasedCommit = repo.Lookup<Commit>(stepInfo.ObjectId);
97+
Commit rebasedCommit = stepInfo.Commit;
9898
Assert.Equal(expectedParent.Id, rebasedCommit.Parents.First().Id);
9999
Assert.False(stepInfo.WasPatchAlreadyApplied);
100100
expectedParent = rebasedCommit;
101101
}
102102

103-
Assert.Equal(repo.Head.Tip.Id, PostRebaseResults.Last().ObjectId);
103+
Assert.Equal(repo.Head.Tip, PostRebaseResults.Last().Commit);
104104
}
105105
}
106106

107107
private class CompletedRebaseStepInfo
108108
{
109-
public CompletedRebaseStepInfo(ObjectId objectId, bool wasPatchAlreadyApplied)
109+
public CompletedRebaseStepInfo(Commit commit, bool wasPatchAlreadyApplied)
110110
{
111-
ObjectId = objectId;
111+
Commit = commit;
112112
WasPatchAlreadyApplied = wasPatchAlreadyApplied;
113113
}
114114

115-
public ObjectId ObjectId { get; set; }
115+
public Commit Commit { get; set; }
116116

117117
public bool WasPatchAlreadyApplied { get; set; }
118118
}
@@ -133,16 +133,16 @@ bool IEqualityComparer<CompletedRebaseStepInfo>.Equals(CompletedRebaseStepInfo x
133133
}
134134

135135
return x.WasPatchAlreadyApplied == y.WasPatchAlreadyApplied &&
136-
ObjectId.Equals(x.ObjectId, y.ObjectId);
136+
ObjectId.Equals(x.Commit, y.Commit);
137137
}
138138

139139
int IEqualityComparer<CompletedRebaseStepInfo>.GetHashCode(CompletedRebaseStepInfo obj)
140140
{
141141
int hashCode = obj.WasPatchAlreadyApplied.GetHashCode();
142142

143-
if (obj.ObjectId != null)
143+
if (obj.Commit != null)
144144
{
145-
hashCode += obj.ObjectId.GetHashCode();
145+
hashCode += obj.Commit.GetHashCode();
146146
}
147147

148148
return hashCode;
@@ -449,7 +449,7 @@ public void CanRebaseHandlePatchAlreadyApplied()
449449
{
450450
RebaseStepCompleted = x =>
451451
{
452-
rebaseResults.Add(new CompletedRebaseStepInfo(x.CommitId, x.WasPatchAlreadyApplied));
452+
rebaseResults.Add(new CompletedRebaseStepInfo(x.Commit, x.WasPatchAlreadyApplied));
453453
}
454454
};
455455

@@ -458,7 +458,7 @@ public void CanRebaseHandlePatchAlreadyApplied()
458458
List<CompletedRebaseStepInfo> expectedRebaseResults = new List<CompletedRebaseStepInfo>()
459459
{
460460
new CompletedRebaseStepInfo(null, true),
461-
new CompletedRebaseStepInfo(new ObjectId("ebdea37ecf583fb7fa5c806a1c00b82f3987fbaa"), false),
461+
new CompletedRebaseStepInfo(repo.Lookup<Commit>("ebdea37ecf583fb7fa5c806a1c00b82f3987fbaa"), false),
462462
};
463463

464464
Assert.Equal<CompletedRebaseStepInfo>(expectedRebaseResults, rebaseResults, new CompletedRebaseStepInfoEqualityComparer());

LibGit2Sharp/AfterRebaseStepInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public class AfterRebaseStepInfo
1616
protected AfterRebaseStepInfo()
1717
{ }
1818

19-
internal AfterRebaseStepInfo(RebaseStepInfo stepInfo, ObjectId commitId)
19+
internal AfterRebaseStepInfo(RebaseStepInfo stepInfo, Commit commit)
2020
{
2121
StepInfo = stepInfo;
22-
CommitId = commitId;
22+
Commit = commit;
2323
WasPatchAlreadyApplied = false;
2424
}
2525

@@ -39,13 +39,13 @@ internal AfterRebaseStepInfo(RebaseStepInfo stepInfo)
3939
public virtual RebaseStepInfo StepInfo { get; private set; }
4040

4141
/// <summary>
42-
/// The ID of the commit generated by the step, if any.
42+
/// The commit generated by the step, if any.
4343
/// </summary>
44-
public virtual ObjectId CommitId { get; private set; }
44+
public virtual Commit Commit { get; private set; }
4545

4646
/// <summary>
4747
/// Was the changes for this step already applied. If so,
48-
/// <see cref="AfterRebaseStepInfo.CommitId"/> will be null.
48+
/// <see cref="AfterRebaseStepInfo.Commit"/> will be null.
4949
/// </summary>
5050
public virtual bool WasPatchAlreadyApplied { get; private set; }
5151
}

LibGit2Sharp/Rebase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
184184
GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebase, currentStepIndex);
185185

186186
var stepInfo = new RebaseStepInfo(gitRebasestepInfo.type,
187-
new ObjectId(gitRebasestepInfo.id),
187+
repository.Lookup<Commit>(new ObjectId(gitRebasestepInfo.id)),
188188
LaxUtf8NoCleanupMarshaler.FromNative(gitRebasestepInfo.exec),
189189
currentStepIndex,
190190
totalStepCount);
@@ -195,7 +195,7 @@ public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
195195
}
196196
else
197197
{
198-
options.RebaseStepCompleted(new AfterRebaseStepInfo(stepInfo, new ObjectId(rebaseCommitResult.CommitId)));
198+
options.RebaseStepCompleted(new AfterRebaseStepInfo(stepInfo, repository.Lookup<Commit>(new ObjectId(rebaseCommitResult.CommitId))));
199199
}
200200
}
201201

@@ -257,7 +257,7 @@ public virtual RebaseStepInfo GetCurrentStepInfo()
257257
long totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseHandle);
258258
GitRebaseOperation gitRebasestepInfo = Proxy.git_rebase_operation_byindex(rebaseHandle, currentStepIndex);
259259
var stepInfo = new RebaseStepInfo(gitRebasestepInfo.type,
260-
gitRebasestepInfo.id,
260+
repository.Lookup<Commit>(new ObjectId(gitRebasestepInfo.id)),
261261
LaxUtf8NoCleanupMarshaler.FromNative(gitRebasestepInfo.exec),
262262
currentStepIndex,
263263
totalStepCount);

LibGit2Sharp/RebaseOperationImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static RebaseResult Run(RebaseSafeHandle rebaseOperationHandle,
6262
else
6363
{
6464
RebaseStepInfo stepInfo = new RebaseStepInfo(rebaseOperationReport.type,
65-
new ObjectId(rebaseOperationReport.id),
65+
repository.Lookup<Commit>(new ObjectId(rebaseOperationReport.id)),
6666
LaxUtf8NoCleanupMarshaler.FromNative(rebaseOperationReport.exec),
6767
currentStepIndex,
6868
totalStepCount);
@@ -89,7 +89,7 @@ public static RebaseResult Run(RebaseSafeHandle rebaseOperationHandle,
8989
}
9090
else
9191
{
92-
options.RebaseStepCompleted(new AfterRebaseStepInfo(stepInfo, new ObjectId(rebase_commit_result.CommitId)));
92+
options.RebaseStepCompleted(new AfterRebaseStepInfo(stepInfo, repository.Lookup<Commit>(new ObjectId(rebase_commit_result.CommitId))));
9393
}
9494
}
9595
}

LibGit2Sharp/RebaseStepInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public class RebaseStepInfo
1717
protected RebaseStepInfo()
1818
{ }
1919

20-
internal RebaseStepInfo(RebaseStepOperation type, ObjectId id, string exec, long stepIndex, long totalStepCount)
20+
internal RebaseStepInfo(RebaseStepOperation type, Commit commit, string exec, long stepIndex, long totalStepCount)
2121
{
2222
Type = type;
23-
ID = id;
23+
Commit = commit;
2424
Exec = exec;
2525
CurrentStep = stepIndex;
2626
TotalStepCount = totalStepCount;
@@ -34,7 +34,7 @@ internal RebaseStepInfo(RebaseStepOperation type, ObjectId id, string exec, long
3434
/// <summary>
3535
/// The object ID the step is operating on.
3636
/// </summary>
37-
public virtual ObjectId ID { get; private set; }
37+
public virtual Commit Commit { get; private set; }
3838

3939
/// <summary>
4040
/// Command to execute, if any.

0 commit comments

Comments
 (0)