Skip to content

Commit e210b9b

Browse files
committed
Teach Repository.Reset to append to the Reflog
1 parent 7eba13d commit e210b9b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

LibGit2Sharp.Tests/ResetHeadFixture.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ private void AssertSoftReset(Func<Branch, string> branchIdentifierRetriever, boo
102102

103103
string branchIdentifier = branchIdentifierRetriever(branch);
104104
repo.Checkout(branchIdentifier);
105+
var oldHeadSha = repo.Head.Tip.Sha;
105106
Assert.Equal(shouldHeadBeDetached, repo.Info.IsHeadDetached);
106107

107108
string expectedHeadName = expectedHeadNameRetriever(branch);
@@ -115,12 +116,16 @@ private void AssertSoftReset(Func<Branch, string> branchIdentifierRetriever, boo
115116

116117
Assert.Equal(FileStatus.Staged, repo.Index.RetrieveStatus("a.txt"));
117118

119+
AssertReflogEntryIsCreated(repo.Refs.Log(repo.Refs.Head), tag.Target.Sha, string.Format("reset: moving to {0}", tag.Target.Sha), oldHeadSha);
120+
118121
/* Reset --soft the Head to a commit through its sha */
119122
repo.Reset(ResetOptions.Soft, branch.Tip.Sha);
120123
Assert.Equal(expectedHeadName, repo.Head.Name);
121124
Assert.Equal(branch.Tip.Sha, repo.Head.Tip.Sha);
122125

123126
Assert.Equal(FileStatus.Unaltered, repo.Index.RetrieveStatus("a.txt"));
127+
128+
AssertReflogEntryIsCreated(repo.Refs.Log(repo.Refs.Head), branch.Tip.Sha, string.Format("reset: moving to {0}", branch.Tip.Sha), tag.Target.Sha);
124129
}
125130
}
126131

@@ -158,6 +163,9 @@ public void MixedResetRefreshesTheIndex()
158163
repo.Reset(ResetOptions.Mixed, tag.CanonicalName);
159164

160165
Assert.Equal(FileStatus.Modified, repo.Index.RetrieveStatus("a.txt"));
166+
167+
AssertReflogEntryIsCreated(repo.Refs.Log(repo.Refs.Head), tag.Target.Sha, string.Format("reset: moving to {0}", tag.Target.Sha));
168+
161169
}
162170
}
163171

LibGit2Sharp.Tests/ResetIndexFixture.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ public void ResetTheIndexWithTheHeadUnstagesEverything()
6767
RepositoryStatus oldStatus = repo.Index.RetrieveStatus();
6868
Assert.Equal(3, oldStatus.Where(IsStaged).Count());
6969

70+
var reflogEntriesCount = repo.Refs.Log(repo.Refs.Head).Count();
71+
7072
repo.Reset();
7173

7274
RepositoryStatus newStatus = repo.Index.RetrieveStatus();
7375
Assert.Equal(0, newStatus.Where(IsStaged).Count());
76+
77+
// Assert that no reflog entry is created
78+
Assert.Equal(reflogEntriesCount, repo.Refs.Log(repo.Refs.Head).Count());
7479
}
7580
}
7681

LibGit2Sharp/Repository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ public void Reset(ResetOptions resetOptions, Commit commit)
727727
Ensure.ArgumentNotNull(commit, "commit");
728728

729729
Proxy.git_reset(handle, commit.Id, resetOptions);
730+
731+
Refs.Log(Refs.Head).Append(commit.Id, string.Format("reset: moving to {0}", commit.Sha));
730732
}
731733

732734
/// <summary>

0 commit comments

Comments
 (0)