8000 Fixup submodule properties · GiTechLab/libgit2sharp@711a41a · GitHub
[go: up one dir, main page]

Skip to content

Commit 711a41a

Browse files
committed
Fixup submodule properties
Fixup drift between LibGit2Sharp and lg2.
1 parent 00f30d8 commit 711a41a

File tree

7 files changed

+61
-10
lines changed

7 files changed

+61
-10
lines changed

LibGit2Sharp.Tests/SubmoduleFixture.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,25 @@ public void CanUpdateSubmoduleAfterCheckout()
289289
Assert.Equal((ObjectId)"5e4963595a9774b90524d35a807169049de8ccad", submodule.WorkDirCommitId);
290290
}
291291
}
292+
293+
[Fact]
294+
public void CanReadSubmoduleProperties()
295+
{
296+
var path = SandboxSubmoduleSmallTestRepo();
297+
string submoduleName = "submodule_target_wd";
298+
299+
using (var repo = new Repository(path))
300+
{
301+
var submodule = repo.Submodules[submoduleName];
302+
303+
Assert.Equal(SubmoduleUpdate.Checkout, submodule.UpdateRule);
304+
Assert.Equal(SubmoduleIgnore.None, submodule.IgnoreRule);
305+
306+
// Libgit2 currently returns No by default, which seems incorrect -
307+
// I would expect OnDemand. For now, just test that we can query
308+
// lg2 for this property.
309+
Assert.Equal(SubmoduleRecurse.No, submodule.FetchRecurseSubmodulesRule);
310+
}
311+
}
292312
}
293313
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ internal static extern SubmoduleUpdate git_submodule_update_strategy(
13971397
SubmoduleSafeHandle submodule);
13981398

13991399
[DllImport(libgit2)]
1400-
internal static extern bool git_submodule_fetch_recurse_submodules(
1400+
internal static extern SubmoduleRecurse git_submodule_fetch_recurse_submodules(
14011401
SubmoduleSafeHandle submodule);
14021402

14031403
[DllImport(libgit2)]

LibGit2Sharp/Core/Proxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2764,7 +2764,7 @@ public static SubmoduleUpdate git_submodule_update_strategy(SubmoduleSafeHandle
27642764
return NativeMethods.git_submodule_update_strategy(submodule);
27652765
}
27662766

2767-
public static bool git_submodule_fetch_recurse_submodules(SubmoduleSafeHandle submodule)
2767+
public static SubmoduleRecurse git_submodule_fetch_recurse_submodules(SubmoduleSafeHandle submodule)
27682768
{
27692769
return NativeMethods.git_submodule_fetch_recurse_submodules(submodule);
27702770
}

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
<Compile Include="Log.cs" />
135135
<Compile Include="LogConfiguration.cs" />
136136
<Compile Include="LogLevel.cs" />
137+
<Compile Include="SubmoduleRecurse.cs" />
137138
<Compile Include="SubmoduleUpdateOptions.cs" />
138139
<Compile Include="UnbornBranchException.cs" />
139140
<Compile Include="LockedFileException.cs" />

LibGit2Sharp/Submodule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Submodule : IEquatable<Submodule>, IBelongToARepository
2121
private readonly ILazy<ObjectId> headCommitId;
2222
private readonly ILazy<ObjectId> indexCommitId;
2323
private readonly ILazy<ObjectId> workdirCommitId;
24-
private readonly ILazy<bool> fetchRecurseSubmodulesRule;
24+
private readonly ILazy<SubmoduleRecurse> fetchRecurseSubmodulesRule;
2525
private readonly ILazy<SubmoduleIgnore> ignoreRule;
2626
private readonly ILazy<SubmoduleUpdate> updateRule;
2727

@@ -85,7 +85,7 @@ internal Submodule(Repository repo, string name, string path, string url)
8585
/// Note that at this time, LibGit2Sharp does not honor this setting and the
8686
/// fetch functionality current ignores submodules.
8787
/// </summary>
88-
public virtual bool FetchRecurseSubmodulesRule { get { return fetchRecurseSubmodulesRule.Value; } }
88+
public virtual SubmoduleRecurse FetchRecurseSubmodulesRule { get { return fetchRecurseSubmodulesRule.Value; } }
8989

9090
/// <summary>
9191
/// The ignore rule of the submodule.

LibGit2Sharp/SubmoduleRecurse.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
namespace LibGit2Sharp
2+
{
3+
/// <summary>
4+
/// Submodule recurse rule options.
5+
/// </summary>
6+
public enum SubmoduleRecurse
7+
{
8+
/// <summary>
9+
/// Reset to the value in the config.
10+
/// </summary>
11+
Reset = -1,
12+
/// <summary>
13+
/// Do not recurse into submodules.
14+
/// </summary>
15+
No = 0,
16+
/// <summary>
17+
/// Recurse into submodules.
18+
/// </summary>
19+
Yes = 1,
20+
/// <summary>
21+
/// Recurse into submodules only when commit not already in local clone.
22+
/// </summary>
23+
OnDemand = 2,
24+
}
25+
}

LibGit2Sharp/SubmoduleUpdate.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,27 @@ public enum SubmoduleUpdate
88
/// <summary>
99
/// Reset to the last saved update rule.
1010
/// </summary>
11-
Default = -1,
11+
Reset = -1,
1212
/// <summary>
13-
/// Checkout the commit recorded in the superproject.
13+
/// Only used when you don't want to specify any particular update
14+
/// rule.
1415
/// </summary>
15-
Checkout = 0,
16+
Unspecified = 0,
17+
/// <summary>
18+
/// This is the default - checkout the commit recorded in the superproject.
19+
/// </summary>
20+
Checkout = 1,
1621
/// <summary>
1722
/// Rebase the current branch of the submodule onto the commit recorded in the superproject.
1823
/// </summary>
19-
Rebase = 1,
24+
Rebase = 2,
2025
/// <summary>
2126
/// Merge the commit recorded in the superproject into the current branch of the submodule.
2227
/// </summary>
23-
Merge = 2,
28+
Merge = 3,
2429
/// <summary>
2530
/// Do not update the submodule.
2631
/// </summary>
27-
None = 3,
32+
None = 4,
2833
}
2934
}

0 commit comments

Comments
 (0)
0