Skip to content

Commit 716190a

Browse files
committed
Submodule.Stage() > SubmoduleCollection.TryStage()
1 parent 5444d12 commit 716190a

File tree

4 files changed

+14
-44
lines changed

4 files changed

+14
-44
lines changed

LibGit2Sharp.Tests/SubmoduleFixture.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,6 @@ public void CanEnumerateRepositorySubmodules()
107107
}
108108
}
109109

110-
[Theory]
111-
[InlineData("sm_changed_head")]
112-
[InlineData("sm_changed_head/")]
113-
public void CanStageChangeInSubmoduleViaSubmoduleStage(string submodulePath)
114-
{
115-
var path = BuildTemporarySubmoduleClone();
116-
117-
using (var repo = new Repository(path))
118-
{
119-
var submodule = repo.Submodules[submodulePath];
120-
121-
var statusBefore = submodule.RetrieveStatus();
122-
Assert.Equal(SubmoduleStatus.WorkDirModified, statusBefore & SubmoduleStatus.WorkDirModified);
123-
124-
submodule.Stage();
125-
126-
var statusAfter = submodule.RetrieveStatus();
127-
Assert.Equal(SubmoduleStatus.IndexModified, statusAfter & SubmoduleStatus.IndexModified);
128-
}
129-
}
130-
131110
[Theory]
132111
[InlineData("sm_changed_head")]
133112
// [InlineData("sm_changed_head/")] // AmbiguousSpecificationException - Do we want to support this?

LibGit2Sharp/Index.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,9 @@ public virtual void Stage(IEnumerable<string> paths)
170170
{
171171
RemoveFromIndex(relativePath);
172172
}
173-
else
173+
else if (!repo.Submodules.TryStage(relativePath, true))
174174
{
175-
var submodule = repo.Submodules[relativePath];
176-
if (submodule != null)
177-
{
178-
submodule.Stage();
179-
}
180-
else
181-
{
182-
AddToIndex(relativePath);
183-
}
175+
AddToIndex(relativePath);
184176
}
185177
}
186178

LibGit2Sharp/Submodule.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,6 @@ public virtual SubmoduleUpdate UpdateRule
9494
get { return Proxy.git_submodule_update(handle); }
9595
}
9696

97-
/// <summary>
98-
/// Add current submodule HEAD commit to index of superproject.
99-
/// </summary>
100-
public virtual void Stage()
101-
{
102-
Stage(true);
103-
}
104-
105-
internal virtual void Stage(bool writeIndex)
106-
{
107-
Proxy.git_submodule_add_to_index(handle, writeIndex);
108-
}
109-
11097
/// <summary>
11198
/// Retrieves the state of this submodule in the working directory compared to the staging area and the latest commmit.
11299
/// </summary>

LibGit2Sharp/SubmoduleCollection.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ IEnumerator IEnumerable.GetEnumerator()
6363
return GetEnumerator();
6464
}
6565

66+
internal bool TryStage(string relativePath, bool writeIndex)
67+
{
68+
using (var handle = Proxy.git_submodule_lookup(repo.Handle, relativePath))
69+
{
70+
if (handle == null)
71+
return false;
72+
73+
Proxy.git_submodule_add_to_index(handle, writeIndex);
74+
return true;
75+
}
76+
}
77+
6678
private string DebuggerDisplay
6779
{
6880
get

0 commit comments

Comments
 (0)