Skip to content

Commit 37713d7

Browse files
committed
Rebase should use Identity instead of Signature
1 parent 6182cb4 commit 37713d7

File tree

7 files changed

+84
-36
lines changed

7 files changed

+84
-36
lines changed

LibGit2Sharp.Tests/RebaseFixture.cs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void CanRebase(string initialBranchName,
6565
},
6666
};
6767

68-
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Signature, options);
68+
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Identity, options);
6969

7070
// Validation:
7171
Assert.Equal(RebaseStatus.Complete, rebaseResult.Status);
@@ -114,7 +114,7 @@ public void CanRebaseBranchOntoItself()
114114
repo.Checkout(topicBranch2Name);
115115
Branch b = repo.Branches[topicBranch2Name];
116116

117-
RebaseResult result = repo.Rebase.Start(b, b, null, Constants.Signature, new RebaseOptions());
117+
RebaseResult result = repo.Rebase.Start(b, b, null, Constants.Identity, new RebaseOptions());
118118
Assert.Equal(0, result.TotalStepCount);
119119
Assert.Equal(RebaseStatus.Complete, result.Status);
120120
Assert.Equal(0, result.CompletedStepCount);
@@ -229,7 +229,7 @@ public void VerifyRebaseDetailed()
229229

230230
};
231231

232-
repo.Rebase.Start(null, upstreamBranch, null, Constants.Signature2, options);
232+
repo.Rebase.Start(null, upstreamBranch, null, Constants.Identity2, options);
233233

234234
Assert.Equal(true, wasCheckoutNotifyCalledForResetingHead);
235235
Assert.Equal(true, wasCheckoutProgressCalledForResetingHead);
@@ -295,7 +295,7 @@ public void CanContinueRebase()
295295
CheckoutNotifyFlags = CheckoutNotifyFlags.Updated,
296296
};
297297

298-
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Signature, options);
298+
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Identity, options);
299299

300300
// Verify that we have a conflict.
301301
Assert.Equal(CurrentOperation.RebaseMerge, repo.Info.CurrentOperation);
@@ -326,7 +326,7 @@ public void CanContinueRebase()
326326

327327
// Clear the flags:
328328
wasCheckoutProgressCalled = false; wasCheckoutNotifyCalled = false;
329-
RebaseResult continuedRebaseResult = repo.Rebase.Continue(Constants.Signature, options);
329+
RebaseResult continuedRebaseResult = repo.Rebase.Continue(Constants.Identity, options);
330330

331331
Assert.NotNull(continuedRebaseResult);
332332
Assert.Equal(RebaseStatus.Complete, continuedRebaseResult.Status);
@@ -358,7 +358,7 @@ public void CanQueryRebaseOperation()
358358
Branch upstream = repo.Branches[conflictBranch1Name];
359359
Branch onto = repo.Branches[conflictBranch1Name];
360360

361-
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Signature, null);
361+
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Identity, null);
362362

363363
// Verify that we have a conflict.
364364
Assert.Equal(RebaseStatus.Conflicts, rebaseResult.Status);
@@ -390,7 +390,7 @@ public void CanAbortRebase()
390390
Branch upstream = repo.Branches[conflictBranch1Name];
391391
Branch onto = repo.Branches[conflictBranch1Name];
392392

393-
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Signature, null);
393+
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Identity, null);
394394

395395
// Verify that we have a conflict.
396396
Assert.Equal(RebaseStatus.Conflicts, rebaseResult.Status);
@@ -436,15 +436,15 @@ public void RebaseWhileAlreadyRebasingThrows()
436436
Branch upstream = repo.Branches[conflictBranch1Name];
437437
Branch onto = repo.Branches[conflictBranch1Name];
438438

439-
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Signature, null);
439+
RebaseResult rebaseResult = repo.Rebase.Start(branch, upstream, onto, Constants.Identity, null);
440440

441441
// Verify that we have a conflict.
442442
Assert.Equal(RebaseStatus.Conflicts, rebaseResult.Status);
443443
Assert.True(repo.RetrieveStatus().IsDirty);
444444
Assert.Equal(CurrentOperation.RebaseMerge, repo.Info.CurrentOperation);
445445

446446
Assert.Throws<LibGit2SharpException>(() =>
447-
repo.Rebase.Start(branch, upstream, onto, Constants.Signature, null));
447+
repo.Rebase.Start(branch, upstream, onto, Constants.Identity, null));
448448
}
449449
}
450450

@@ -460,7 +460,7 @@ public void RebaseOperationsWithoutRebasingThrow()
460460
repo.Checkout(topicBranch1Name);
461461

462462
Assert.Throws<NotFoundException>(() =>
463-
repo.Rebase.Continue(Constants.Signature, new RebaseOptions()));
463+
repo.Rebase.Continue(Constants.Identity, new RebaseOptions()));
464464

465465
Assert.Throws<NotFoundException>(() =>
466466
repo.Rebase.Abort());
@@ -520,15 +520,22 @@ public void CanRebaseHandlePatchAlreadyApplied()
520520
}
521521
};
522522

523-
repo.Rebase.Start(null, upstreamBranch, null, Constants.Signature2, options);
523+
repo.Rebase.Start(null, upstreamBranch, null, Constants.Identity2, options);
524+
ObjectId secondCommitExpectedTreeId = new ObjectId("ac04bf04980c9be72f64ba77fd0d9088a40ed681");
525+
Signature secondCommitAuthorSignature = Constants.Signature;
526+
Identity secondCommitCommiterIdentity = Constants.Identity2;
524527

525-
List<CompletedRebaseStepInfo> expectedRebaseResults = new List<CompletedRebaseStepInfo>()
526-
{
527-
new CompletedRebaseStepInfo(null, true),
528-
new CompletedRebaseStepInfo(repo.Lookup<Commit>("ebdea37ecf583fb7fa5c806a1c00b82f3987fbaa"), false),
529-
};
528+
Assert.Equal(2, rebaseResults.Count);
529+
Assert.True(rebaseResults[0].WasPatchAlreadyApplied);
530+
531+
Assert.False(rebaseResults[1].WasPatchAlreadyApplied);
532+
Assert.NotNull(rebaseResults[1].Commit);
530533

531-
Assert.Equal<CompletedRebaseStepInfo>(expectedRebaseResults, rebaseResults, new CompletedRebaseStepInfoEqualityComparer());
534+
// This is the expected tree ID of the new commit.
535+
Assert.True(ObjectId.Equals(secondCommitExpectedTreeId, rebaseResults[1].Commit.Tree.Id));
536+
Assert.True(Signature.Equals(secondCommitAuthorSignature, rebaseResults[1].Commit.Author));
537+
Assert.Equal<string>(secondCommitCommiterIdentity.Name, rebaseResults[1].Commit.Committer.Name, StringComparer.Ordinal);
538+
Assert.Equal<string>(secondCommitCommiterIdentity.Email, rebaseResults[1].Commit.Committer.Email, StringComparer.Ordinal);
532539
}
533540
}
534541

LibGit2Sharp.Tests/TestHelpers/Constants.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ public static class Constants
1111
public static readonly string TemporaryReposPath = BuildPath();
1212
public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
1313
public static readonly Identity Identity = new Identity("A. U. Thor", "thor@valhalla.asgard.com");
14+
public static readonly Identity Identity2 = new Identity("nulltoken", "emeric.fermas@gmail.com");
15+
1416
public static readonly Signature Signature = new Signature(Identity, new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
15-
public static readonly Signature Signature2 = new Signature("nulltoken", "emeric.fermas@gmail.com", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));
17+
public static readonly Signature Signature2 = new Signature(Identity2, DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));
1618

1719
// Populate these to turn on live credential tests: set the
1820
// PrivateRepoUrl to the URL of a repository that requires

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,12 @@ internal static extern int git_signature_new(
13941394
long time,
13951395
int offset);
13961396

1397+
[DllImport(libgit2)]
1398+
internal static extern int git_signature_now(
1399+
out SignatureSafeHandle signature,
1400+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string name,
1401+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string email);
1402+
13971403
[DllImport(libgit2)]
13981404
internal static extern int git_signature_dup(out IntPtr dest, IntPtr sig);
13991405

LibGit2Sharp/Core/Proxy.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,14 +1612,14 @@ public static GitRebaseOperation git_rebase_next(RebaseSafeHandle rebase)
16121612

16131613
public static GitRebaseCommitResult git_rebase_commit(
16141614
RebaseSafeHandle rebase,
1615-
Signature author,
1616-
Signature committer)
1615+
Identity author,
1616+
Identity committer)
16171617
{
16181618
Ensure.ArgumentNotNull(rebase, "rebase");
16191619
Ensure.ArgumentNotNull(committer, "committer");
16201620

1621-
using (SignatureSafeHandle committerHandle = committer.BuildHandle())
1622-
using (SignatureSafeHandle authorHandle = author.SafeBuildHandle())
1621+
using (SignatureSafeHandle committerHandle = committer.BuildNowSignatureHandle())
1622+
using (SignatureSafeHandle authorHandle = author.SafeBuildNowSignatureHandle())
16231623
{
16241624
GitRebaseCommitResult commitResult = new GitRebaseCommitResult();
16251625

@@ -1667,12 +1667,12 @@ public static void git_rebase_abort(
16671667

16681668
public static void git_rebase_finish(
16691669
RebaseSafeHandle rebase,
1670-
Signature signature)
1670+
Identity committer)
16711671
{
16721672
Ensure.ArgumentNotNull(rebase, "rebase");
1673-
Ensure.ArgumentNotNull(signature, "signature");
1673+
Ensure.ArgumentNotNull(committer, "committer");
16741674

1675-
using (var signatureHandle = signature.BuildHandle())
1675+
using (var signatureHandle = committer.BuildNowSignatureHandle())
16761676
{
16771677
int result = NativeMethods.git_rebase_finish(rebase, signatureHandle);
16781678
Ensure.ZeroResult(result);
@@ -2567,8 +2567,16 @@ public static SignatureSafeHandle git_signature_new(string name, string email, D
25672567
SignatureSafeHandle handle;
25682568

25692569
int res = NativeMethods.git_signature_new(out handle, name, email, when.ToSecondsSinceEpoch(),
2570-
(int)when.Offset.TotalMinutes);
2570+
(int)when.Offset.TotalMinutes);
2571+
Ensure.ZeroResult(res);
25712572

2573+
return handle;
2574+
}
2575+
2576+
public static SignatureSafeHandle git_signature_now(string name, string email)
2577+
{
2578+
SignatureSafeHandle handle;
2579+
int res = NativeMethods.git_signature_now(out handle, name, email);
25722580
Ensure.ZeroResult(res);
25732581

25742582
return handle;

LibGit2Sharp/Identity.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using LibGit2Sharp.Core;
2+
using LibGit2Sharp.Core.Handles;
23

34
namespace LibGit2Sharp
45
{
@@ -41,5 +42,29 @@ public string Name
4142
{
4243
get { return _name; }
4344
}
45+
46+
internal SignatureSafeHandle BuildNowSignatureHandle()
47+
{
48+
return Proxy.git_signature_now(Name, Email);
49+
}
50+
}
51+
52+
internal static class IdentityHelpers
53+
{
54+
/// <summary>
55+
/// Build the handle for the Indentity with the current time, or return a handle
56+
/// to an empty signature.
57+
/// </summary>
58+
/// <param name="identity"></param>
59+
/// <returns></returns>
60+
public static SignatureSafeHandle SafeBuildNowSignatureHandle(this Identity identity)
61+
{
62+
if (identity == null)
63+
{
64+
return new SignatureSafeHandle();
65+
}
66+
67+
return identity.BuildNowSignatureHandle();
68+
}
4469
}
4570
}

LibGit2Sharp/Rebase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ internal Rebase(Repository repo)
7070
/// <param name="branch">The branch to rebase.</param>
7171
/// <param name="upstream">The starting commit to rebase.</param>
7272
/// <param name="onto">The branch to rebase onto.</param>
73-
/// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
73+
/// <param name="committer">The <see cref="Identity"/> of who added the change to the repository.</param>
7474
/// <param name="options">The <see cref="RebaseOptions"/> that specify the rebase behavior.</param>
7575
/// <returns>true if completed successfully, false if conflicts encountered.</returns>
76-
public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, Signature committer, RebaseOptions options)
76+
public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, Identity committer, RebaseOptions options)
7777
{
7878
Ensure.ArgumentNotNull(upstream, "upstream");
7979

@@ -132,9 +132,9 @@ public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, S
132132
/// <summary>
133133
/// Continue the current rebase.
134134
/// </summary>
135-
/// <param name="committer">The <see cref="Signature"/> of who added the change to the repository.</param>
135+
/// <param name="committer">The <see cref="Identity"/> of who added the change to the repository.</param>
136136
/// <param name="options">The <see cref="RebaseOptions"/> that specify the rebase behavior.</param>
137-
public virtual RebaseResult Continue(Signature committer, RebaseOptions options)
137+
public virtual RebaseResult Continue(Identity committer, RebaseOptions options)
138138
{
139139
Ensure.ArgumentNotNull(committer, "committer");
140140

LibGit2Sharp/RebaseOperationImpl.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ internal class RebaseOperationImpl
1515
/// </summary>
1616
/// <param name="rebaseOperationHandle">Handle to the rebase operation.</param>
1717
/// <param name="repository">Repository in which rebase operation is being run.</param>
18-
/// <param name="committer">Committer signature to use for the rebased commits.</param>
18+
/// <param name="committer">Committer Identity to use for the rebased commits.</param>
1919
/// <param name="options">Options controlling rebase behavior.</param>
20-
/// <returns>RebaseResult - describing the result of the rebase operation.</returns>
20+
/// <returns>RebaseResult that describes the result of the rebase operation.</returns>
2121
public static RebaseResult Run(RebaseSafeHandle rebaseOperationHandle,
2222
Repository repository,
23-
Signature committer,
23+
Identity committer,
2424
RebaseOptions options)
2525
{
2626
Ensure.ArgumentNotNull(rebaseOperationHandle, "rebaseOperationHandle");
@@ -53,7 +53,7 @@ public static RebaseResult Run(RebaseSafeHandle rebaseOperationHandle,
5353
return rebaseResult;
5454
}
5555

56-
private static RebaseResult CompleteRebase(RebaseSafeHandle rebaseOperationHandle, Signature committer, RebaseResult rebaseResult)
56+
private static RebaseResult CompleteRebase(RebaseSafeHandle rebaseOperationHandle, Identity committer, RebaseResult rebaseResult)
5757
{
5858
long totalStepCount = Proxy.git_rebase_operation_entrycount(rebaseOperationHandle);
5959
GitRebaseOptions gitRebaseOptions = new GitRebaseOptions()
@@ -80,7 +80,7 @@ private static RebaseResult CompleteRebase(RebaseSafeHandle rebaseOperationHandl
8080
/// <param name="options"></param>
8181
/// <param name="stepToApplyInfo"></param>
8282
/// <returns></returns>
83-
private static RebaseResult RunRebaseStep(RebaseSafeHandle rebaseOperationHandle, Repository repository, Signature committer, RebaseOptions options, RebaseStepInfo stepToApplyInfo)
83+
private static RebaseResult RunRebaseStep(RebaseSafeHandle rebaseOperationHandle, Repository repository, Identity committer, RebaseOptions options, RebaseStepInfo stepToApplyInfo)
8484
{
8585
RebaseStepResult rebaseStepResult = null;
8686
RebaseResult rebaseSequenceResult = null;
@@ -145,7 +145,7 @@ private static RebaseResult RunRebaseStep(RebaseSafeHandle rebaseOperationHandle
145145
return rebaseSequenceResult;
146146
}
147147

148-
private static RebaseStepResult ApplyPickStep(RebaseSafeHandle rebaseOperationHandle, Repository repository, Signature committer, RebaseOptions options, RebaseStepInfo stepToApplyInfo)
148+
private static RebaseStepResult ApplyPickStep(RebaseSafeHandle rebaseOperationHandle, Repository repository, Identity committer, RebaseOptions options, RebaseStepInfo stepToApplyInfo)
149149
{
150150
RebaseStepResult rebaseStepResult;
151151

0 commit comments

Comments
 (0)