Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 54a6411

Browse files
Merge pull request #704 from github-for-unity/fixes/right-click-revert
Restoring functionality to revert a commit
2 parents 85d0a91 + aee0c4a commit 54a6411

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,11 @@ public override void OnGUI()
459459
selectedEntry = entry;
460460
BuildTree();
461461
},
462-
entry => { },
463-
entry => { });
462+
entry => { }, entry => {
463+
GenericMenu menu = new GenericMenu();
464+
menu.AddItem(new GUIContent("Revert"), false, RevertCommit);
465+
menu.ShowAsContext();
466+
});
464467

465468
if (requiresRepaint)
466469
Redraw();
@@ -546,6 +549,26 @@ private void HistoryDetailsEntry(GitLogEntry entry)
546549
GUILayout.EndVertical();
547550
}
548551

552+
private void RevertCommit()
553+
{
554+
var dialogTitle = "Revert commit";
555+
var dialogBody = string.Format(@"Are you sure you want to revert the following commit:""{0}""", selectedEntry.Summary);
556+
557+
if (EditorUtility.DisplayDialog(dialogTitle, dialogBody, "Revert", "Cancel"))
558+
{
559+
Repository
560+
.Revert(selectedEntry.CommitID)
561+
.FinallyInUI((success, e) => {
562+
if (!success)
563+
{
564+
EditorUtility.DisplayDialog(dialogTitle,
565+
"Error reverting commit: " + e.Message, Localization.Cancel);
566+
}
567+
})
568+
.Start();
569+
}
570+
}
571+
549572
private void RepositoryTrackingOnStatusChanged(CacheUpdateEvent cacheUpdateEvent)
550573
{
551574
if (!lastAheadBehindChangedEvent.Equals(cacheUpdateEvent))

0 commit comments

Comments
 (0)