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

Commit 7541813

Browse files
Adding confirmation before checking out a remote branch
1 parent c922648 commit 7541813

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

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

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class BranchesView : Subview
1515
private const string ConfirmSwitchMessage = "Switch branch to {0}?";
1616
private const string ConfirmSwitchOK = "Switch";
1717
private const string ConfirmSwitchCancel = "Cancel";
18+
private const string ConfirmCheckoutBranchTitle = "Confirm branch checkout";
19+
private const string ConfirmCheckoutBranchMessage = "Checkout branch {0}?";
20+
private const string ConfirmCheckoutBranchOK = "Checkout";
21+
private const string ConfirmCheckoutBranchCancel = "Cancel";
1822
private const string NewBranchCancelButton = "x";
1923
private const string NewBranchConfirmButton = "Create";
2024
private const string FavoritesSetting = "Favorites";
@@ -649,37 +653,41 @@ private void OnTreeNodeGUI(BranchTreeNode node)
649653

650654
if (Event.current.clickCount > 1 && mode == BranchesMode.Default)
651655
{
652-
if (node.Type == NodeType.LocalBranch &&
653-
EditorUtility.DisplayDialog(ConfirmSwitchTitle, String.Format(ConfirmSwitchMessage, node.Name), ConfirmSwitchOK,
654-
ConfirmSwitchCancel))
656+
if (node.Type == NodeType.LocalBranch)
655657
{
656-
GitClient.SwitchBranch(node.Name)
657-
.FinallyInUI((success, e) =>
658-
{
659-
if (success)
660-
Refresh();
661-
else
658+
if (EditorUtility.DisplayDialog(ConfirmSwitchTitle, String.Format(ConfirmSwitchMessage, node.Name), ConfirmSwitchOK, ConfirmSwitchCancel))
659+
{
660+
GitClient.SwitchBranch(node.Name)
661+
.FinallyInUI((success, e) =>
662662
{
663-
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
664-
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
665-
Localization.Ok);
666-
}
667-
}).Start();
663+
if (success)
664+
Refresh();
665+
else
666+
{
667+
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
668+
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
669+
Localization.Ok);
670+
}
671+
}).Start();
672+
}
668673
}
669674
else if (node.Type == NodeType.RemoteBranch)
670675
{
671-
GitClient.CreateBranch(selectedNode.Name.Substring(selectedNode.Name.IndexOf('/') + 1), selectedNode.Name)
672-
.FinallyInUI((success, e) =>
673-
{
674-
if (success)
675-
Refresh();
676-
else
676+
if (EditorUtility.DisplayDialog(ConfirmCheckoutBranchTitle, String.Format(ConfirmCheckoutBranchMessage, node.Name), ConfirmCheckoutBranchOK, ConfirmCheckoutBranchCancel))
677+
{
678+
GitClient.CreateBranch(selectedNode.Name.Substring(selectedNode.Name.IndexOf('/') + 1), selectedNode.Name)
679+
.FinallyInUI((success, e) =>
677680
{
678-
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
679-
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
680-
Localization.Ok);
681-
}
682-
}).Start();
681+
if (success)
682+
Refresh();
683+
else
684+
{
685+
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
686+
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
687+
Localization.Ok);
688+
}
689+
}).Start();
690+
}
683691
}
684692
}
685693
}

0 commit comments

Comments
 (0)