예제 #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));
            }
        }
예제 #2
0
        public bool TryAddNote()
        {
            Verify.State.IsTrue(View != null, "Controller is not attached to a view.");

            var revision = View.Revision.Value;
            var message  = View.Message.Value;

            if (!GitControllerUtility.ValidateRefspec(revision, View.Revision, View.ErrorNotifier))
            {
                return(false);
            }
            if (string.IsNullOrWhiteSpace(message))
            {
                View.ErrorNotifier.NotifyError(View.Message,
                                               new UserInputError(
                                                   Resources.ErrInvalidMessage,
                                                   Resources.ErrMessageCannotBeEmpty));
                return(false);
            }
            revision = revision.Trim();
            message  = message.Trim();
            try
            {
                using (View.ChangeCursor(MouseCursor.WaitCursor))
                {
                    var ptr = Repository.GetRevisionPointer(revision);
                    ptr.AddNote(message);
                }
            }
            catch (UnknownRevisionException)
            {
                View.ErrorNotifier.NotifyError(View.Revision,
                                               new UserInputError(
                                                   Resources.ErrInvalidRevisionExpression,
                                                   Resources.ErrRevisionIsUnknown));
                return(false);
            }
            catch (GitException exc)
            {
                GitterApplication.MessageBoxService.Show(
                    View as IWin32Window,
                    exc.Message,
                    Resources.ErrFailedToAddNote,
                    MessageBoxButton.Close,
                    MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
예제 #3
0
        public bool TryCreateTag()
        {
            Verify.State.IsTrue(View != null, "Controller is not attached to a view.");

            var tagName = View.TagName.Value.Trim();
            var refspec = View.Revision.Value.Trim();

            if (!GitControllerUtility.ValidateNewTagName(tagName, Repository, View.TagName, View.ErrorNotifier))
            {
                return(false);
            }
            if (!GitControllerUtility.ValidateRefspec(refspec, View.Revision, View.ErrorNotifier))
            {
                return(false);
            }

            string message   = null;
            bool   signed    = View.Signed.Value;
            bool   annotated = signed || View.Annotated.Value;

            if (annotated)
            {
                message = View.Message.Value;
                if (string.IsNullOrWhiteSpace(message))
                {
                    View.ErrorNotifier.NotifyError(View.Message,
                                                   new UserInputError(
                                                       Resources.ErrNoMessageSpecified,
                                                       Resources.ErrMessageCannotBeEmpty));
                    return(false);
                }
                message = message.Trim();
            }
            string keyId = null;

            if (signed)
            {
                if (View.UseKeyId.Value)
                {
                    keyId = View.KeyId.Value;
                    if (string.IsNullOrWhiteSpace(keyId))
                    {
                        View.ErrorNotifier.NotifyError(View.KeyId,
                                                       new UserInputError(
                                                           Resources.ErrNoKeyIdSpecified,
                                                           Resources.ErrKeyIdCannotBeEmpty));
                        return(false);
                    }
                    keyId = keyId.Trim();
                }
            }
            try
            {
                using (View.ChangeCursor(MouseCursor.WaitCursor))
                {
                    var ptr = Repository.GetRevisionPointer(refspec);
                    if (annotated)
                    {
                        if (signed)
                        {
                            if (keyId == null)
                            {
                                Repository.Refs.Tags.Create(tagName, ptr, message, true);
                            }
                            else
                            {
                                Repository.Refs.Tags.Create(tagName, ptr, message, keyId);
                            }
                        }
                        else
                        {
                            Repository.Refs.Tags.Create(tagName, ptr, message, false);
                        }
                    }
                    else
                    {
                        Repository.Refs.Tags.Create(tagName, ptr);
                    }
                }
            }
            catch (TagAlreadyExistsException)
            {
                View.ErrorNotifier.NotifyError(View.TagName,
                                               new UserInputError(
                                                   Resources.ErrInvalidTagName,
                                                   Resources.ErrTagAlreadyExists));
                return(false);
            }
            catch (UnknownRevisionException)
            {
                View.ErrorNotifier.NotifyError(View.Revision,
                                               new UserInputError(
                                                   Resources.ErrInvalidRevisionExpression,
                                                   Resources.ErrRevisionIsUnknown));
                return(false);
            }
            catch (InvalidTagNameException exc)
            {
                View.ErrorNotifier.NotifyError(View.TagName,
                                               new UserInputError(
                                                   Resources.ErrInvalidTagName,
                                                   exc.Message));
                return(false);
            }
            catch (GitException exc)
            {
                GitterApplication.MessageBoxService.Show(
                    View as IWin32Window,
                    exc.Message,
                    string.Format(Resources.ErrFailedToCreateTag, tagName),
                    MessageBoxButton.Close,
                    MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }