Skip to content

Commit e2948a5

Browse files
committed
Add submodule support to Index.Stage()
Fix #220
1 parent 920f5c2 commit e2948a5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

LibGit2Sharp.Tests/SubmoduleFixture.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,27 @@ public void CanStageChangeInSubmoduleViaSubmoduleStage(string submodulePath)
119119
}
120120
}
121121

122+
[Theory]
123+
[InlineData("sm_changed_head")]
124+
// [InlineData("sm_changed_head/")] // AmbiguousSpecificationException - Do we want to support this?
125+
public void CanStageChangeInSubmoduleViaIndexStage(string submodulePath)
126+
{
127+
var path = BuildTemporarySubmoduleClone();
128+
129+
using (var repo = new Repository(path))
130+
{
131+
var submodule = repo.Submodules[submodulePath];
132+
133+
var statusBefore = submodule.RetrieveStatus();
134+
Assert.Equal(SubmoduleStatus.WorkDirModified, statusBefore & SubmoduleStatus.WorkDirModified);
135+
136+
repo.Index.Stage(submodulePath);
137+
138+
var statusAfter = submodule.RetrieveStatus();
139+
Assert.Equal(SubmoduleStatus.IndexModified, statusAfter & SubmoduleStatus.IndexModified);
140+
}
141+
}
142+
122143
public string BuildTemporarySubmoduleClone()
123144
{
124145
var submodule = Path.Combine(ResourcesDirectory.FullName, "submodule_wd");

LibGit2Sharp/Index.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,15 @@ public virtual void Stage(IEnumerable<string> paths)
172172
}
173173
else
174174
{
175-
AddToIndex(relativePath);
175+
var submodule = repo.Submodules[relativePath];
176+
if (submodule != null)
177+
{
178+
submodule.Stage();
179+
}
180+
else
181+
{
182+
AddToIndex(relativePath);
183+
}
176184
}
177185
}
178186

0 commit comments

Comments
 (0)