8000 Make Index.Unstage() work against an orphaned Head · rlazev/libgit2sharp@90dc807 · GitHub
[go: up one dir, main page]

Skip to content

Commit 90dc807

Browse files
phkelleynulltoken
authored andcommitted
Make Index.Unstage() work against an orphaned Head
Fix libgit2#257
1 parent 9fdb4bd commit 90dc807

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

LibGit2Sharp/Index.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,24 @@ public virtual void Unstage(string path)
211211
/// <param name = "paths">The collection of paths of the files within the working directory.</param>
212212
public virtual void Unstage(IEnumerable<string> paths)
213213
{
214-
repo.Reset("HEAD", paths);
214+
Commit commit = repo.Lookup("HEAD",
215+
GitObjectType.Any,
216+
LookUpOptions.DereferenceResultToCommit) as Commit;
217+
218+
if (null != commit)
219+
{
220+
repo.Reset("HEAD", paths);
221+
}
222+
else
223+
{
224+
// HEAD doesn't exist, so all these staged paths must be Added.
225+
foreach (String path in paths)
226+
{
227+
RemoveFromIndex(path);
228+
}
229+
230+
UpdatePhysicalIndex();
231+
}
215232
}
216233

217234
/// <summary>

0 commit comments

Comments
 (0)
0