Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Dahlby <dahlbyk@gmail.com>2013-02-04 06:16:11 +0400
committernulltoken <emeric.fermas@gmail.com>2013-04-11 21:39:47 +0400
commit795cb759ec61e870865b1be51d91b20d1d68ceca (patch)
tree98bb9ac424ff6b158b74e0cb155a08a233412280
parent2764e9d4598fe3b0c393aa21e3dc03b1e51591a8 (diff)
Add Submodule bindings
-rw-r--r--LibGit2Sharp/Core/Handles/SubmoduleSafeHandle.cs6
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs65
-rw-r--r--LibGit2Sharp/Core/Proxy.cs103
-rw-r--r--LibGit2Sharp/LibGit2Sharp.csproj5
-rw-r--r--LibGit2Sharp/SubmoduleExtensions.cs27
-rw-r--r--LibGit2Sharp/SubmoduleIgnore.cs30
-rw-r--r--LibGit2Sharp/SubmoduleStatus.cs90
-rw-r--r--LibGit2Sharp/SubmoduleUpdate.cs29
8 files changed, 355 insertions, 0 deletions
diff --git a/LibGit2Sharp/Core/Handles/SubmoduleSafeHandle.cs b/LibGit2Sharp/Core/Handles/SubmoduleSafeHandle.cs
new file mode 100644
index 00000000..822cc5fd
--- /dev/null
+++ b/LibGit2Sharp/Core/Handles/SubmoduleSafeHandle.cs
@@ -0,0 +1,6 @@
+namespace LibGit2Sharp.Core.Handles
+{
+ internal class SubmoduleSafeHandle : NotOwnedSafeHandleBase
+ {
+ }
+}
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 227f22e4..705ff77f 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -1015,6 +1015,71 @@ namespace LibGit2Sharp.Core
internal static extern int git_status_foreach(RepositorySafeHandle repo, git_status_cb cb, IntPtr payload);
[DllImport(libgit2)]
+ internal static extern int git_submodule_lookup(
+ out SubmoduleSafeHandle reference,
+ RepositorySafeHandle repo,
+ [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string name);
+
+ internal delegate int submodule_callback(
+ IntPtr sm,
+ IntPtr name,
+ IntPtr payload);
+
+ [DllImport(libgit2)]
+ internal static extern int git_submodule_foreach(
+ RepositorySafeHandle repo,
+ submodule_callback callback,
+ IntPtr payload);
+
+ [DllImport(libgit2)]
+ internal static extern int git_submodule_add_to_index(
+ SubmoduleSafeHandle submodule,
+ bool write_index);
+
+ [DllImport(libgit2)]
+ internal static extern int git_submodule_save(
+ SubmoduleSafeHandle submodule);
+
+ [DllImport(libgit2)]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8NoCleanupMarshaler))]
+ internal static extern string git_submodule_path(
+ SubmoduleSafeHandle submodule);
+
+ [DllImport(libgit2)]
+ [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8NoCleanupMarshaler))]
+ internal static extern string git_submodule_url(
+ SubmoduleSafeHandle submodule);
+
+ [DllImport(libgit2)]
+ internal static extern OidSafeHandle git_submodule_index_id(
+ SubmoduleSafeHandle submodule);
+
+ [DllImport(libgit2)]
+ internal static extern OidSafeHandle git_submodule_head_id(
+ SubmoduleSafeHandle submodule);
+
+ [DllImport(libgit2)]
+ internal static extern OidSafeHandle git_submodule_wd_id(
+ SubmoduleSafeHandle submodule);
+
+ [DllImport(libgit2)]
+ internal static extern SubmoduleIgnore git_submodule_ignore(
+ SubmoduleSafeHandle submodule);
+
+ [DllImport(libgit2)]
+ internal static extern SubmoduleUpdate git_submodule_update(
+ SubmoduleSafeHandle submodule);
+
+ [DllImport(libgit2)]
+ internal static extern bool git_submodule_fetch_recurse_submodules(
+ SubmoduleSafeHandle submodule);
+
+ [DllImport(libgit2)]
+ internal static extern int git_submodule_status(
+ out SubmoduleStatus status,
+ SubmoduleSafeHandle submodule);
+
+ [DllImport(libgit2)]
internal static extern int git_tag_create(
out GitOid oid,
RepositorySafeHandle repo,
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index c6c2975e..35bd9bea 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -1912,6 +1912,109 @@ namespace LibGit2Sharp.Core
#endregion
+ #region git_submodule_
+
+ /// <summary>
+ /// Returns a handle to the corresponding submodule,
+ /// or an invalid handle if a submodule is not found.
+ /// </summary>
+ public static SubmoduleSafeHandle git_submodule_lookup(RepositorySafeHandle repo, string name)
+ {
+ using (ThreadAffinity())
+ {
+ SubmoduleSafeHandle reference;
+ var res = NativeMethods.git_submodule_lookup(out reference, repo, name);
+
+ switch (res)
+ {
+ case (int)GitErrorCode.NotFound:
+ case (int)GitErrorCode.Exists:
+ case (int)GitErrorCode.OrphanedHead:
+ return null;
+
+ default:
+ Ensure.ZeroResult(res);
+ return reference;
+ }
+ }
+ }
+
+ public static ICollection<TResult> git_submodule_foreach<TResult>(RepositorySafeHandle repo, Func<IntPtr, IntPtr, TResult> resultSelector)
+ {
+ return git_foreach(resultSelector, c => NativeMethods.git_submodule_foreach(repo, (x, y, p) => c(x, y, p), IntPtr.Zero));
+ }
+
+ public static void git_submodule_add_to_index(SubmoduleSafeHandle submodule, bool write_index)
+ {
+ using (ThreadAffinity())
+ {
+ var res = NativeMethods.git_submodule_add_to_index(submodule, write_index);
+ Ensure.ZeroResult(res);
+ }
+ }
+
+ public static void git_submodule_save(SubmoduleSafeHandle submodule)
+ {
+ using (ThreadAffinity())
+ {
+ var res = NativeMethods.git_submodule_save(submodule);
+ Ensure.ZeroResult(res);
+ }
+ }
+
+ public static string git_submodule_path(SubmoduleSafeHandle submodule)
+ {
+ return NativeMethods.git_submodule_path(submodule);
+ }
+
+ public static string git_submodule_url(SubmoduleSafeHandle submodule)
+ {
+ return NativeMethods.git_submodule_url(submodule);
+ }
+
+ public static ObjectId git_submodule_index_id(SubmoduleSafeHandle submodule)
+ {
+ return NativeMethods.git_submodule_index_id(submodule).MarshalAsObjectId();
+ }
+
+ public static ObjectId git_submodule_head_id(SubmoduleSafeHandle submodule)
+ {
+ return NativeMethods.git_submodule_head_id(submodule).MarshalAsObjectId();
+ }
+
+ public static ObjectId git_submodule_wd_id(SubmoduleSafeHandle submodule)
+ {
+ return NativeMethods.git_submodule_wd_id(submodule).MarshalAsObjectId();
+ }
+
+ public static SubmoduleIgnore git_submodule_ignore(SubmoduleSafeHandle submodule)
+ {
+ return NativeMethods.git_submodule_ignore(submodule);
+ }
+
+ public static SubmoduleUpdate git_submodule_update(SubmoduleSafeHandle submodule)
+ {
+ return NativeMethods.git_submodule_update(submodule);
+ }
+
+ public static bool git_submodule_fetch_recurse_submodules(SubmoduleSafeHandle submodule)
+ {
+ return NativeMethods.git_submodule_fetch_recurse_submodules(submodule);
+ }
+
+ public static SubmoduleStatus git_submodule_status(SubmoduleSafeHandle submodule)
+ {
+ using (ThreadAffinity())
+ {
+ SubmoduleStatus status;
+ var res = NativeMethods.git_submodule_status(out status, submodule);
+ Ensure.ZeroResult(res);
+ return status;
+ }
+ }
+
+ #endregion
+
#region git_tag_
public static ObjectId git_tag_create(
diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj
index b88853e1..3d6ab133 100644
--- a/LibGit2Sharp/LibGit2Sharp.csproj
+++ b/LibGit2Sharp/LibGit2Sharp.csproj
@@ -76,6 +76,7 @@
<Compile Include="ReflogCollection.cs" />
<Compile Include="Core\PathCase.cs" />
<Compile Include="MatchedPathsAggregator.cs" />
+ <Compile Include="Core\Handles\SubmoduleSafeHandle.cs" />
<Compile Include="Network.cs" />
<Compile Include="Core\GitRemoteHead.cs" />
<Compile Include="ReflogEntry.cs" />
@@ -84,6 +85,10 @@
<Compile Include="OrphanedHeadException.cs" />
<Compile Include="StashCollection.cs" />
<Compile Include="ExplicitPathsOptions.cs" />
+ <Compile Include="SubmoduleExtensions.cs" />
+ <Compile Include="SubmoduleIgnore.cs" />
+ <Compile Include="SubmoduleStatus.cs" />
+ <Compile Include="SubmoduleUpdate.cs" />
<Compile Include="UnmergedIndexEntriesException.cs" />
<Compile Include="Commit.cs" />
<Compile Include="CommitLog.cs" />
diff --git a/LibGit2Sharp/SubmoduleExtensions.cs b/LibGit2Sharp/SubmoduleExtensions.cs
new file mode 100644
index 00000000..1c77d1b0
--- /dev/null
+++ b/LibGit2Sharp/SubmoduleExtensions.cs
@@ -0,0 +1,27 @@
+namespace LibGit2Sharp
+{
+ /// <summary>
+ /// Extensions related to submodules
+ /// </summary>
+ public static class SubmoduleExtensions
+ {
+ private const SubmoduleStatus UnmodifiedMask = ~(SubmoduleStatus.InConfig | SubmoduleStatus.InHead | SubmoduleStatus.InIndex | SubmoduleStatus.InWorkDir);
+ private const SubmoduleStatus WorkDirDirtyMask = SubmoduleStatus.WorkDirFilesIndexDirty | SubmoduleStatus.WorkDirFilesModified | SubmoduleStatus.WorkDirFilesUntracked;
+
+ /// <summary>
+ /// The submodule is unmodified.
+ /// </summary>
+ public static bool IsUnmodified(this SubmoduleStatus @this)
+ {
+ return (@this & UnmodifiedMask) == SubmoduleStatus.Unmodified;
+ }
+
+ /// <summary>
+ /// The submodule working directory is dirty.
+ /// </summary>
+ public static bool IsWorkingDirectoryDirty(this SubmoduleStatus @this)
+ {
+ return (@this & WorkDirDirtyMask) != SubmoduleStatus.Unmodified;
+ }
+ }
+}
diff --git a/LibGit2Sharp/SubmoduleIgnore.cs b/LibGit2Sharp/SubmoduleIgnore.cs
new file mode 100644
index 00000000..53123893
--- /dev/null
+++ b/LibGit2Sharp/SubmoduleIgnore.cs
@@ -0,0 +1,30 @@
+namespace LibGit2Sharp
+{
+ /// <summary>
+ /// Values that could be specified for how closely to examine the
+ /// working directory when getting submodule status.
+ /// </summary>
+ public enum SubmoduleIgnore
+ {
+ /// <summary>
+ /// Reset to the last saved ignore rule.
+ /// </summary>
+ Default = -1,
+ /// <summary>
+ /// Any change or untracked == dirty
+ /// </summary>
+ None = 0,
+ /// <summary>
+ /// Dirty if tracked files change
+ /// </summary>
+ Untracked = 1,
+ /// <summary>
+ /// Only dirty if HEAD moved
+ /// </summary>
+ Dirty = 2,
+ /// <summary>
+ /// Never dirty
+ /// </summary>
+ All = 3,
+ }
+}
diff --git a/LibGit2Sharp/SubmoduleStatus.cs b/LibGit2Sharp/SubmoduleStatus.cs
new file mode 100644
index 00000000..af4e81a8
--- /dev/null
+++ b/LibGit2Sharp/SubmoduleStatus.cs
@@ -0,0 +1,90 @@
+using System;
+
+namespace LibGit2Sharp
+{
+ /// <summary>
+ /// Calculated status of a submodule in the working directory considering the current <see cref = "Repository.Index" /> and the <see cref="Repository.Head" />.
+ /// </summary>
+ [Flags]
+ public enum SubmoduleStatus
+ {
+ /// <summary>
+ /// No submodule changes detected.
+ /// </summary>
+ Unmodified = 0,
+
+ /// <summary>
+ /// Superproject head contains submodule.
+ /// </summary>
+ /// <remarks>Can be returned even if ignore is set to "ALL".</remarks>
+ InHead = (1 << 0),
+ /// <summary>
+ /// Superproject index contains submodule.
+ /// </summary>
+ /// <remarks>Can be returned even if ignore is set to "ALL".</remarks>
+ InIndex = (1 << 1),
+ /// <summary>
+ /// Superproject gitmodules has submodule.
+ /// </summary>
+ /// <remarks>Can be returned even if ignore is set to "ALL".</remarks>
+ InConfig = (1 << 2),
+ /// <summary>
+ /// Superproject working directory has submodule.
+ /// </summary>
+ /// <remarks>Can be returned even if ignore is set to "ALL".</remarks>
+ InWorkDir = (1 << 3),
+
+ /// <summary>
+ /// Submodule is in index, but not in head.
+ /// </summary>
+ /// <remarks>Can be returned unless ignore is set to "ALL".</remarks>
+ IndexAdded = (1 << 4),
+ /// <summary>
+ /// Submodule is in head, but not in index.
+ /// </summary>
+ /// <remarks>Can be returned unless ignore is set to "ALL".</remarks>
+ IndexDeleted = (1 << 5),
+ /// <summary>
+ /// Submodule in index and head don't match.
+ /// </summary>
+ /// <remarks>Can be returned unless ignore is set to "ALL".</remarks>
+ IndexModified = (1 << 6),
+ /// <summary>
+ /// Submodule in working directory is not initialized.
+ /// </summary>
+ /// <remarks>Can be returned unless ignore is set to "ALL".</remarks>
+ WorkDirUninitialized = (1 << 7),
+ /// <summary>
+ /// Submodule is in working directory, but not index.
+ /// </summary>
+ /// <remarks>Can be returned unless ignore is set to "ALL".</remarks>
+ WorkDirAdded = (1 << 8),
+ /// <summary>
+ /// Submodule is in index, but not working directory.
+ /// </summary>
+ /// <remarks>Can be returned unless ignore is set to "ALL".</remarks>
+ WorkDirDeleted = (1 << 9),
+ /// <summary>
+ /// Submodule in index and working directory head don't match.
+ /// </summary>
+ /// <remarks>Can be returned unless ignore is set to "ALL".</remarks>
+ WorkDirModified = (1 << 10),
+
+ /// <summary>
+ /// Submodule working directory index is dirty.
+ /// </summary>
+ /// <remarks>Can only be returned if ignore is "NONE" or "UNTRACKED".</remarks>
+ WorkDirFilesIndexDirty = (1 << 11),
+ /// <summary>
+ /// Submodule working directory has modified files.
+ /// </summary>
+ /// <remarks>Can only be returned if ignore is "NONE" or "UNTRACKED".</remarks>
+ WorkDirFilesModified = (1 << 12),
+
+ /// <summary>
+ /// Working directory contains untracked files.
+ /// </summary>
+ /// <remarks>Can only be returned if ignore is "NONE".</remarks>
+ WorkDirFilesUntracked = (1 << 13),
+ }
+}
diff --git a/LibGit2Sharp/SubmoduleUpdate.cs b/LibGit2Sharp/SubmoduleUpdate.cs
new file mode 100644
index 00000000..d03e3b05
--- /dev/null
+++ b/LibGit2Sharp/SubmoduleUpdate.cs
@@ -0,0 +1,29 @@
+namespace LibGit2Sharp
+{
+ /// <summary>
+ /// Submodule update rule options.
+ /// </summary>
+ public enum SubmoduleUpdate
+ {
+ /// <summary>
+ /// Reset to the last saved update rule.
+ /// </summary>
+ Default = -1,
+ /// <summary>
+ /// Checkout the commit recorded in the superproject.
+ /// </summary>
+ Checkout = 0,
+ /// <summary>
+ /// Rebase the current branch of the submodule onto the commit recorded in the superproject.
+ /// </summary>
+ Rebase = 1,
+ /// <summary>
+ /// Merge the commit recorded in the superproject into the current branch of the submodule.
+ /// </summary>
+ Merge = 2,
+ /// <summary>
+ /// Do not update the submodule.
+ /// </summary>
+ None = 3,
+ }
+}