Skip to content

Commit

Permalink
Add submodule support to Index.Stage()
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlbyk committed Mar 26, 2013
1 parent 920f5c2 commit e2948a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
21 changes: 21 additions & 0 deletions LibGit2Sharp.Tests/SubmoduleFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ public void CanStageChangeInSubmoduleViaSubmoduleStage(string submodulePath)
}
}

[Theory]
[InlineData("sm_changed_head")]
// [InlineData("sm_changed_head/")] // AmbiguousSpecificationException - Do we want to support this?
public void CanStageChangeInSubmoduleViaIndexStage(string submodulePath)
{
var path = BuildTemporarySubmoduleClone();

using (var repo = new Repository(path))
{
var submodule = repo.Submodules[submodulePath];

var statusBefore = submodule.RetrieveStatus();
Assert.Equal(SubmoduleStatus.WorkDirModified, statusBefore & SubmoduleStatus.WorkDirModified);

repo.Index.Stage(submodulePath);

var statusAfter = submodule.RetrieveStatus();
Assert.Equal(SubmoduleStatus.IndexModified, statusAfter & SubmoduleStatus.IndexModified);
}
}

public string BuildTemporarySubmoduleClone()
{
var submodule = Path.Combine(ResourcesDirectory.FullName, "submodule_wd");
Expand Down
10 changes: 9 additions & 1 deletion LibGit2Sharp/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,15 @@ public virtual void Stage(IEnumerable<string> paths)
}
else
{
AddToIndex(relativePath);
var submodule = repo.Submodules[relativePath];
if (submodule != null)
{
submodule.Stage();
}
else
{
AddToIndex(relativePath);
}
}
}

Expand Down

0 comments on commit e2948a5

Please sign in to comment.