Beispiel #1
0
        public bool TryCreateBranch()
        {
            Verify.State.IsTrue(View != null, "Controller is not attached to a view.");

            var branchName = View.BranchName.Value.Trim();
            var refspec    = View.StartingRevision.Value.Trim();
            var checkout   = View.Checkout.Value;
            var orphan     = checkout && View.Orphan.Value && GitFeatures.CheckoutOrphan.IsAvailableFor(Repository);
            var reflog     = View.CreateReflog.Value;
            var existent   = Repository.Refs.Heads.TryGetItem(branchName);

            if (!GitControllerUtility.ValidateBranchName(branchName, View.BranchName, View.ErrorNotifier))
            {
                return(false);
            }
            if (!GitControllerUtility.ValidateRefspec(refspec, View.StartingRevision, View.ErrorNotifier))
            {
                return(false);
            }
            if (existent != null)
            {
                return(TryResetExistingBranch(branchName, refspec, checkout, existent));
            }
            else
            {
                return(TryCreateNewBranch(branchName, refspec, checkout, orphan, reflog));
            }
        }
        public bool TryAddSubmodule()
        {
            Verify.State.IsTrue(View != null, "Controller is not attached to a view.");

            var path = View.Path.Value.Trim();

            if (!GitControllerUtility.ValidateRelativePath(path, View.Path, View.ErrorNotifier))
            {
                return(false);
            }
            var url = View.Url.Value.Trim();

            if (!GitControllerUtility.ValidateUrl(url, View.Url, View.ErrorNotifier))
            {
                return(false);
            }
            string branch = null;

            if (View.UseCustomBranch.Value)
            {
                branch = View.BranchName.Value.Trim();
                if (!GitControllerUtility.ValidateBranchName(branch, View.BranchName, View.ErrorNotifier))
                {
                    return(false);
                }
            }
            try
            {
                using (View.ChangeCursor(MouseCursor.WaitCursor))
                {
                    _repository.Submodules.Create(path, url, branch);
                }
            }
            catch (GitException exc)
            {
                GitterApplication.MessageBoxService.Show(
                    View as IWin32Window,
                    exc.Message,
                    string.Format(Resources.ErrFailedToAddSubmodule, path),
                    MessageBoxButton.Close,
                    MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }