Skip to content

Commit 2480317

Browse files
committed
first pass at wrapping the libgit2 API
1 parent e1e5fe6 commit 2480317

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

LibGit2Sharp.Tests/IndexFixture.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,16 @@ public void RetrievingAssumedUnchangedMarkedIndexEntries()
480480
}
481481
}
482482

483+
[Fact]
484+
public void CanUpdateIndexWhenNothingHappened()
485+
{
486+
var path = SandboxAssumeUnchangedTestRepo();
487+
using (var repo = new Repository(path))
488+
{
489+
repo.Index.Update();
490+
}
491+
}
492+
483493
private static void AddSomeCornerCases(Repository repo)
484494
{
485495
// Turn 1.txt into a directory in the Index

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,18 @@ internal static extern IndexReucEntrySafeHandle git_index_reuc_get_bypath(
612612
IndexSafeHandle handle,
613613
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictFilePathMarshaler))] FilePath path);
614614

615+
internal delegate int git_index_matched_path_cb(
616+
string path,
617+
string matched_pathspec,
618+
IntPtr payload);
619+
620+
[DllImport(libgit2)]
621+
internal static extern int git_index_update_all(
622+
IndexSafeHandle index,
623+
ref GitStrArray pathArray,
624+
git_index_matched_path_cb callback,
625+
IntPtr payload);
626+
615627
[DllImport(libgit2)]
616628
internal static extern int git_index_write(IndexSafeHandle index);
617629

LibGit2Sharp/Core/Proxy.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,30 @@ public static IndexReucEntrySafeHandle git_index_reuc_get_bypath(IndexSafeHandle
11351135
return NativeMethods.git_index_reuc_get_bypath(index, path);
11361136
}
11371137

1138+
public static void git_index_update_all(IndexSafeHandle index, FilePath[] filePaths)
1139+
{
1140+
// maybe not?
1141+
using (ThreadAffinity())
1142+
{
1143+
var array = new GitStrArrayManaged();
1144+
1145+
try
1146+
{
1147+
array = GitStrArrayManaged.BuildFrom(filePaths);
1148+
NativeMethods.git_index_matched_path_cb callback = (path, pathspec, payload) =>
1149+
{
1150+
return 0;
1151+
};
1152+
var res = NativeMethods.git_index_update_all(index, ref array.Array, callback, IntPtr.Zero);
1153+
Ensure.ZeroResult(res);
1154+
}
1155+
finally
1156+
{
1157+
array.Dispose();
1158+
}
1159+
}
1160+
}
1161+
11381162
public static void git_index_write(IndexSafeHandle index)
11391163
{
11401164
using (ThreadAffinity())

LibGit2Sharp/Index.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ public virtual void Add(Blob blob, string indexEntryPath, Mode indexEntryMode)
226226
UpdatePhysicalIndex();
227227
}
228228

229+
public virtual void Update()
230+
{
231+
FilePath defaultPath = "*";
232+
Proxy.git_index_update_all(Handle, new [] { defaultPath });
233+
}
234+
229235
private void UpdatePhysicalIndex()
230236
{
231237
Proxy.git_index_write(handle);

0 commit comments

Comments
 (0)