Skip to content

Commit 1940bac

Browse files
committed
Initial Rebase implementation
1 parent cad89d0 commit 1940bac

20 files changed

+1649
-10
lines changed

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<Compile Include="DescribeFixture.cs" />
6060
<Compile Include="GlobalSettingsFixture.cs" />
6161
<Compile Include="PatchStatsFixture.cs" />
62+
<Compile Include="RebaseFixture.cs" />
6263
<Compile Include="RefSpecFixture.cs" />
6364
<Compile Include="EqualityFixture.cs" />
6465
<Compile Include="RevertFixture.cs" />
@@ -157,4 +158,4 @@
157158
<Target Name="AfterBuild">
158159
</Target>
159160
-->
160-
</Project>
161+
</Project>

LibGit2Sharp.Tests/RebaseFixture.cs

Lines changed: 574 additions & 0 deletions
Large diffs are not rendered by default.

LibGit2Sharp.Tests/TestHelpers/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public static class Constants
88
public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
99
public static readonly Identity Identity = new Identity("A. U. Thor", "thor@valhalla.asgard.com");
1010
public static readonly Signature Signature = new Signature(Identity, new DateTimeOffset(2011, 06, 16, 10, 58, 27, TimeSpan.FromHours(2)));
11+
public static readonly Signature Signature2 = new Signature("nulltoken", "emeric.fermas@gmail.com", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));
1112

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

LibGit2Sharp/AfterRebaseStepInfo.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace LibGit2Sharp
7+
{
8+
/// <summary>
9+
/// Information about a rebase step that was just completed.
10+
/// </summary>
11+
public class AfterRebaseStepInfo
12+
{
13+
/// <summary>
14+
/// Needed for mocking.
15+
/// </summary>
16+
protected AfterRebaseStepInfo()
17+
{ }
18+
19+
internal AfterRebaseStepInfo(RebaseStepInfo stepInfo, Commit commit)
20+
{
21+
StepInfo = stepInfo;
22+
Commit = commit;
23+
WasPatchAlreadyApplied = false;
24+
}
25+
26+
/// <summary>
27+
/// Constructor to call when the patch has already been applied for this step.
28+
/// </summary>
29+
/// <param name="stepInfo"></param>
30+
internal AfterRebaseStepInfo(RebaseStepInfo stepInfo)
31+
: this (stepInfo, null)
32+
{
33+
WasPatchAlreadyApplied = true;
34+
}
35+
36+
/// <summary>
37+
/// The info on the completed step.
38+
/// </summary>
39+
public virtual RebaseStepInfo StepInfo { get; private set; }
40+
41+
/// <summary>
42+
/// The commit generated by the step, if any.
43+
/// </summary>
44+
public virtual Commit Commit { get; private set; }
45+
46+
/// <summary>
47+
/// Was the changes for this step already applied. If so,
48+
/// <see cref="AfterRebaseStepInfo.Commit"/> will be null.
49+
/// </summary>
50+
public virtual bool WasPatchAlreadyApplied { get; private set; }
51+
}
52+
}

LibGit2Sharp/BeforeRebaseStepInfo.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace LibGit2Sharp
7+
{
8+
/// <summary>
9+
/// Information about a rebase step that is about to be performed.
10+
/// </summary>
11+
public class BeforeRebaseStepInfo
12+
{
13+
/// <summary>
14+
/// Needed for mocking.
15+
/// </summary>
16+
protected BeforeRebaseStepInfo()
17+
{ }
18+
19+
internal BeforeRebaseStepInfo(RebaseStepInfo stepInfo)
20+
{
21+
StepInfo = stepInfo;
22+
}
23+
24+
/// <summary>
25+
/// Information on the step that is about to be performed.
26+
/// </summary>
27+
public virtual RebaseStepInfo StepInfo { get; private set; }
28+
}
29+
}

LibGit2Sharp/Core/GitOid.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,13 @@ public static implicit operator ObjectId(GitOid? oid)
2727
{
2828
return oid == null ? null : new ObjectId(oid.Value);
2929
}
30+
31+
/// <summary>
32+
/// Static convenience property to return an id (all zeros).
33+
/// </summary>
34+
public static GitOid Empty
35+
{
36+
get { return new GitOid(); }
37+
}
3038
}
3139
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibGit2Sharp.Core
5+
{
6+
[StructLayout(LayoutKind.Sequential)]
7+
internal class GitRebaseOperation
8+
{
9+
internal RebaseStepOperation type;
10+
internal GitOid id;
11+
internal IntPtr exec;
12+
}
13+
}

LibGit2Sharp/Core/GitRebaseOptions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibGit2Sharp.Core
5+
{
6+
[StructLayout(LayoutKind.Sequential)]
7+
struct GitRebaseOptions
8+
{
9+
public uint version;
10+
11+
public int quiet;
12+
13+
public IntPtr rewrite_notes_ref;
14+
}
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using LibGit2Sharp.Core.Handles;
2+
3+
namespace LibGit2Sharp.Core
4+
{
5+
internal class RebaseSafeHandle : SafeHandleBase
6+
{
7+
protected override bool ReleaseHandleImpl()
8+
{
9+
Proxy.git_rebase_free(handle);
10+
return true;
11+
}
12+
}
13+
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,62 @@ internal static extern int git_branch_remote_name(
191191
RepositorySafeHandle repo,
192192
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string canonical_branch_name);
193193

194+
[DllImport(libgit2)]
195+
internal static extern int git_rebase_init(
196+
out RebaseSafeHandle rebase,
197+
RepositorySafeHandle repo,
198+
GitAnnotatedCommitHandle branch,
199+
GitAnnotatedCommitHandle upstream,
200+
GitAnnotatedCommitHandle onto,
201+
ref GitRebaseOptions options);
202+
203+
[DllImport(libgit2)]
204+
internal static extern int git_rebase_open(
205+
out RebaseSafeHandle rebase,
206+
RepositorySafeHandle repo);
207+
208+
[DllImport(libgit2)]
209+
internal static extern UIntPtr git_rebase_operation_entrycount(
210+
RebaseSafeHandle rebase);
211+
212+
[DllImport(libgit2)]
213+
internal static extern UIntPtr git_rebase_operation_current(
214+
RebaseSafeHandle rebase);
215+
216+
[DllImport(libgit2)]
217+
internal static extern IntPtr git_rebase_operation_byindex(
218+
RebaseSafeHandle rebase,
219+
UIntPtr index);
220+
221+
[DllImport(libgit2)]
222+
internal static extern int git_rebase_next(
223+
out IntPtr operation,
224+
RebaseSafeHandle rebase,
225+
ref GitCheckoutOpts options);
226+
227+
[DllImport(libgit2)]
228+
internal static extern int git_rebase_commit(
229+
ref GitOid id,
230+
RebaseSafeHandle rebase,
231+
SignatureSafeHandle author,
232+
SignatureSafeHandle committer,
233+
IntPtr message_encoding,
234+
IntPtr message);
235+
236+
[DllImport(libgit2)]
237+
internal static extern int git_rebase_abort(
238+
RebaseSafeHandle rebase);
239+
240+
[DllImport(libgit2)]
241+
internal static extern int git_rebase_finish(
242+
RebaseSafeHandle repo,
243+
SignatureSafeHandle signature,
244+
ref GitRebaseOptions options);
245+
246+
[DllImport(libgit2)]
247+
internal static extern void git_rebase_free(
248+
IntPtr rebase);
249+
194250
[DllImport(libgit2)]
195251
internal static extern int git_remote_rename(
196252
ref GitStrArray problems,
@@ -202,7 +258,6 @@ internal delegate int git_remote_rename_problem_cb(
202258
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))] string problematic_refspec,
203259
IntPtr payload);
204260

205-
206261
[DllImport(libgit2)]
207262
internal static extern int git_branch_upstream_name(
208263
GitBuf buf,

0 commit comments

Comments
 (0)