Skip to content

Commit 815086d

Browse files
committed
Bind git_checkout_tree()
1 parent c04e3b1 commit 815086d

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

LibGit2Sharp/Core/GitCheckoutOpts.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibGit2Sharp.Core
5+
{
6+
internal delegate int skipped_notify_cb(
7+
IntPtr skipped_file,
8+
ref GitOid blob_oid,
9+
int file_mode,
10+
IntPtr payload);
11+
12+
[StructLayout(LayoutKind.Sequential)]
13+
internal class GitCheckoutOpts
14+
{
15+
public CheckoutStrategy checkout_strategy;
16+
public int DisableFilters;
17+
public int DirMode;
18+
public int FileMode;
19+
public int FileOpenFlags;
20+
public skipped_notify_cb skippedNotifyCb;
21+
public IntPtr NotifyPayload;
22+
public UnSafeNativeMethods.git_strarray paths;
23+
}
24+
25+
[Flags]
26+
internal enum CheckoutStrategy
27+
{
28+
GIT_CHECKOUT_DEFAULT = (1 << 0),
29+
GIT_CHECKOUT_OVERWRITE_MODIFIED = (1 << 1),
30+
GIT_CHECKOUT_CREATE_MISSING = (1 << 2),
31+
GIT_CHECKOUT_REMOVE_UNTRACKED = (1 << 3),
32+
}
33+
}

LibGit2Sharp/Core/GitIndexerStats.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace LibGit2Sharp.Core
4+
{
5+
[StructLayout(LayoutKind.Sequential)]
6+
internal class GitIndexerStats
7+
{
8+
public int Total;
9+
public int Processed;
10+
public int Received;
11+
}
12+
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ internal static extern int git_branch_tracking(
142142
out ReferenceSafeHandle reference,
143143
ReferenceSafeHandle branch);
144144

145+
[DllImport(libgit2)]
146+
internal static extern int git_checkout_tree(
147+
RepositorySafeHandle repo,
148+
GitObjectSafeHandle treeish,
149+
GitCheckoutOpts opts,
150+
GitIndexerStats stats);
151+
145152
[DllImport(libgit2)]
146153
internal static extern IntPtr git_commit_author(GitObjectSafeHandle commit);
147154

LibGit2Sharp/Core/Proxy.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,24 @@ public static ReferenceSafeHandle git_branch_tracking(ReferenceSafeHandle branch
166166

167167
#endregion
168168

169+
#region git_checkout_
170+
171+
public static void git_checkout_tree(
172+
RepositorySafeHandle repo,
173+
ObjectId treeId,
174+
GitCheckoutOpts opts,
175+
GitIndexerStats stats)
176+
{
177+
using (ThreadAffinity())
178+
using (var osw = new ObjectSafeWrapper(treeId, repo))
179+
{
180+
int res = NativeMethods.git_checkout_tree(repo, osw.ObjectPtr, opts, stats);
181+
Ensure.Success(res);
182+
}
183+
}
184+
185+
#endregion
186+
169187
#region git_commit_
170188

171189
public static Signature git_commit_author(GitObjectSafeHandle obj)

0 commit comments

Comments
 (0)