Example #1
0
        private void CheckoutRemoteBranch(string branch)
        {
            var indexOfFirstSlash = branch.IndexOf('/');
            var originName        = branch.Substring(0, indexOfFirstSlash);
            var branchName        = branch.Substring(indexOfFirstSlash + 1);

            if (Repository.LocalBranches.Any(localBranch => localBranch.Name == branchName))
            {
                EditorUtility.DisplayDialog(WarningCheckoutBranchExistsTitle,
                                            String.Format(WarningCheckoutBranchExistsMessage, branchName), WarningCheckoutBranchExistsOK);
            }
            else
            {
                var confirmCheckout = EditorUtility.DisplayDialog(ConfirmCheckoutBranchTitle,
                                                                  String.Format(ConfirmCheckoutBranchMessage, branch, originName), ConfirmCheckoutBranchOK,
                                                                  ConfirmCheckoutBranchCancel);

                if (confirmCheckout)
                {
                    Repository.CreateBranch(branchName, branch)
                    .FinallyInUI((success, e) =>
                    {
                        if (success)
                        {
                            UsageTracker.IncrementBranchesViewButtonCheckoutRemoteBranch();
                            Redraw();
                        }
                        else
                        {
                            EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
                                                        String.Format(Localization.SwitchBranchFailedDescription, branch), Localization.Ok);
                        }
                    }).Start();
                }
            }
        }