Skip to content
Snippets Groups Projects
Commit bf8a2ae6 authored by Stanley Goldman's avatar Stanley Goldman
Browse files

Adding warning message if branch already exists

parent 089d0107
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,12 @@ namespace GitHub.Unity
private const string ConfirmSwitchOK = "Switch";
private const string ConfirmSwitchCancel = "Cancel";
private const string ConfirmCheckoutBranchTitle = "Confirm branch checkout";
private const string ConfirmCheckoutBranchMessage = "Checkout branch {0}?";
private const string ConfirmCheckoutBranchMessage = "Checkout branch {0} from {1}?";
private const string ConfirmCheckoutBranchOK = "Checkout";
private const string ConfirmCheckoutBranchCancel = "Cancel";
private const string WarningCheckoutBranchExistsTitle = "Branch already exists";
private const string WarningCheckoutBranchExistsMessage = "Branch {0} already exists";
private const string WarningCheckoutBranchExistsOK = "Ok";
private const string NewBranchCancelButton = "x";
private const string NewBranchConfirmButton = "Create";
private const string FavoritesSetting = "Favorites";
......@@ -668,32 +671,53 @@ namespace GitHub.Unity
.FinallyInUI((success, e) =>
{
if (success)
{
Refresh();
}
else
{
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
Localization.Ok);
Localization.Ok);
}
}).Start();
}
}
else if (node.Type == NodeType.RemoteBranch)
{
if (EditorUtility.DisplayDialog(ConfirmCheckoutBranchTitle, String.Format(ConfirmCheckoutBranchMessage, node.Name), ConfirmCheckoutBranchOK, ConfirmCheckoutBranchCancel))
var indexOfFirstSlash = selectedNode.Name.IndexOf('/');
var originName = selectedNode.Name.Substring(0, indexOfFirstSlash);
var branchName = selectedNode.Name.Substring(indexOfFirstSlash + 1);
if (Repository.LocalBranches.Any(localBranch => localBranch.Name == branchName))
{
GitClient.CreateBranch(selectedNode.Name.Substring(selectedNode.Name.IndexOf('/') + 1), selectedNode.Name)
.FinallyInUI((success, e) =>
{
if (success)
Refresh();
else
EditorUtility.DisplayDialog(WarningCheckoutBranchExistsTitle,
String.Format(WarningCheckoutBranchExistsMessage, branchName),
WarningCheckoutBranchExistsOK);
}
else
{
var confirmCheckout = EditorUtility.DisplayDialog(ConfirmCheckoutBranchTitle,
String.Format(ConfirmCheckoutBranchMessage, node.Name, originName),
ConfirmCheckoutBranchOK, ConfirmCheckoutBranchCancel);
if (confirmCheckout)
{
GitClient.CreateBranch(branchName, selectedNode.Name)
.FinallyInUI((success, e) =>
{
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
Localization.Ok);
}
}).Start();
if (success)
{
Refresh();
}
else
{
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
Localization.Ok);
}
}).Start();
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment