예제 #1
0
        private bool HandlePushOnExit(ref bool isError, FormProcess form)
        {
            if (!isError)
            {
                return(false);
            }

            // there is no way to pull to not current branch
            if (_selectedBranch != _currentBranchName)
            {
                return(false);
            }

            // auto pull from URL not supported. See https://github.com/gitextensions/gitextensions/issues/1887
            if (!PushToRemote.Checked)
            {
                return(false);
            }

            // auto pull only if current branch was rejected
            var isRejected = new Regex(Regex.Escape("! [rejected] ") + ".*" + Regex.Escape(_currentBranchName) + ".*", RegexOptions.Compiled);

            if (isRejected.IsMatch(form.GetOutputString()) && !Module.IsBareRepository())
            {
                IWin32Window owner = form.Owner;
                (var onRejectedPullAction, var forcePush) = AskForAutoPullOnPushRejectedAction(owner);

                if (forcePush)
                {
                    if (!form.ProcessArguments.Contains(" -f ") && !form.ProcessArguments.Contains(" --force"))
                    {
                        Trace.Assert(form.ProcessArguments.StartsWith("push "), "Arguments should start with 'push' command");

                        string forceArg = GitVersion.Current.SupportPushForceWithLease ? " --force-with-lease" : " -f";
                        form.ProcessArguments = form.ProcessArguments.Insert("push".Length, forceArg);
                    }

                    form.Retry();
                    return(true);
                }

                if (onRejectedPullAction == AppSettings.PullAction.Default)
                {
                    onRejectedPullAction = AppSettings.DefaultPullAction;
                }

                if (onRejectedPullAction == AppSettings.PullAction.None)
                {
                    return(false);
                }

                if (onRejectedPullAction != AppSettings.PullAction.Merge && onRejectedPullAction != AppSettings.PullAction.Rebase)
                {
                    form.AppendOutput(Environment.NewLine +
                                      "Automatical pull can only be performed, when the default pull action is either set to Merge or Rebase." +
                                      Environment.NewLine + Environment.NewLine);
                    return(false);
                }

                if (IsRebasingMergeCommit())
                {
                    form.AppendOutput(Environment.NewLine +
                                      "Can not perform automatical pull, when the pull action is set to Rebase " + Environment.NewLine +
                                      "and one of the commits that are about to be rebased is a merge commit." +
                                      Environment.NewLine + Environment.NewLine);
                    return(false);
                }

                UICommands.StartPullDialogAndPullImmediately(
                    out var pullCompleted,
                    owner,
                    _selectedRemoteBranchName,
                    _selectedRemote.Name,
                    onRejectedPullAction);

                if (pullCompleted)
                {
                    form.Retry();
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        private bool HandlePushOnExit(ref bool isError, FormProcess form)
        {
            if (!isError)
            {
                return(false);
            }

            // there is no way to pull to not current branch
            if (_selectedBranch != _currentBranchName)
            {
                return(false);
            }

            // auto pull from URL not supported. See https://github.com/gitextensions/gitextensions/issues/1887
            if (!PushToRemote.Checked)
            {
                return(false);
            }

            // auto pull only if current branch was rejected
            Regex isRejected = new Regex(Regex.Escape("! [rejected] ") + ".*" + Regex.Escape(_currentBranchName) + ".*", RegexOptions.Compiled);

            if (isRejected.IsMatch(form.GetOutputString()) && !Module.IsBareRepository())
            {
                bool         forcePush = false;
                IWin32Window owner     = form.Owner;
                if (AppSettings.AutoPullOnPushRejectedAction == null)
                {
                    bool   cancel      = false;
                    string destination = _NO_TRANSLATE_Remotes.Text;
                    string buttons     = _pullRepositoryButtons.Text;
                    switch (Module.LastPullAction)
                    {
                    case AppSettings.PullAction.Fetch:
                    case AppSettings.PullAction.FetchAll:
                        buttons = string.Format(buttons, _pullActionFetch.Text);
                        break;

                    case AppSettings.PullAction.Merge:
                        buttons = string.Format(buttons, _pullActionMerge.Text);
                        break;

                    case AppSettings.PullAction.Rebase:
                        buttons = string.Format(buttons, _pullActionRebase.Text);
                        break;

                    default:
                        buttons = string.Format(buttons, _pullActionNone.Text);
                        break;
                    }

                    int idx = PSTaskDialog.cTaskDialog.ShowCommandBox(owner,
                                                                      string.Format(_pullRepositoryCaption.Text, destination),
                                                                      _pullRepositoryMainInstruction.Text,
                                                                      _pullRepository.Text,
                                                                      "",
                                                                      "",
                                                                      _dontShowAgain.Text,
                                                                      buttons,
                                                                      true,
                                                                      0,
                                                                      0);
                    bool rememberDecision = PSTaskDialog.cTaskDialog.VerificationChecked;
                    switch (idx)
                    {
                    case 0:
                        if (rememberDecision)
                        {
                            AppSettings.AutoPullOnPushRejectedAction = AppSettings.PullAction.Default;
                        }

                        break;

                    case 1:
                        AppSettings.FormPullAction = AppSettings.PullAction.Rebase;
                        if (rememberDecision)
                        {
                            AppSettings.AutoPullOnPushRejectedAction = AppSettings.FormPullAction;
                        }

                        break;

                    case 2:
                        AppSettings.FormPullAction = AppSettings.PullAction.Merge;
                        if (rememberDecision)
                        {
                            AppSettings.AutoPullOnPushRejectedAction = AppSettings.FormPullAction;
                        }

                        break;

                    case 3:
                        forcePush = true;
                        break;

                    default:
                        cancel = true;
                        if (rememberDecision)
                        {
                            AppSettings.AutoPullOnPushRejectedAction = AppSettings.PullAction.None;
                        }

                        break;
                    }

                    if (cancel)
                    {
                        return(false);
                    }
                }

                if (forcePush)
                {
                    if (!form.ProcessArguments.Contains(" -f ") && !form.ProcessArguments.Contains(" --force"))
                    {
                        Trace.Assert(form.ProcessArguments.StartsWith("push "), "Arguments should start with 'push' command");

                        string forceArg = GitCommandHelpers.VersionInUse.SupportPushForceWithLease ? " --force-with-lease" : " -f";
                        form.ProcessArguments = form.ProcessArguments.Insert("push".Length, forceArg);
                    }

                    form.Retry();
                    return(true);
                }

                if (AppSettings.AutoPullOnPushRejectedAction == AppSettings.PullAction.None)
                {
                    return(false);
                }

                if (AppSettings.AutoPullOnPushRejectedAction == AppSettings.PullAction.Default)
                {
                    if (Module.LastPullAction == AppSettings.PullAction.None)
                    {
                        return(false);
                    }

                    Module.LastPullActionToFormPullAction();
                }

                if (AppSettings.FormPullAction == AppSettings.PullAction.Fetch)
                {
                    form.AppendOutput(Environment.NewLine +
                                      "Can not perform auto pull, when merge option is set to fetch.");
                    return(false);
                }

                if (IsRebasingMergeCommit())
                {
                    form.AppendOutput(Environment.NewLine +
                                      "Can not perform auto pull, when merge option is set to rebase " + Environment.NewLine +
                                      "and one of the commits that are about to be rebased is a merge.");
                    return(false);
                }

                UICommands.StartPullDialog(owner, true, _selectedRemoteBranchName, _selectedRemote.Name, out var pullCompleted, false);
                if (pullCompleted)
                {
                    form.Retry();
                    return(true);
                }
            }

            return(false);
        }
예제 #3
0
        private bool HandlePushOnExit(ref bool isError, FormProcess form)
        {
            if (!isError)
                return false;

            //there is no way to pull to not current branch
            if (_selectedBranch != _currentBranch)
                return false;

            //auto pull from URL not supported. See https://github.com/gitextensions/gitextensions/issues/1887
            if (!PushToRemote.Checked)
                return false;

            //auto pull only if current branch was rejected
            Regex IsRejected = new Regex(Regex.Escape("! [rejected] ") + ".*" + Regex.Escape(_currentBranch) + ".*", RegexOptions.Compiled);

            if (IsRejected.IsMatch(form.GetOutputString()) && !Module.IsBareRepository())
            {
                bool forcePush = false;
                IWin32Window owner = form;
                if (AppSettings.AutoPullOnPushRejectedAction == null)
                {
                    bool cancel = false;
                    string destination = PushToRemote.Checked ? _NO_TRANSLATE_Remotes.Text : PushDestination.Text;
                    string buttons = _pullRepositoryButtons.Text;
                    switch (Module.LastPullAction)
                    {
                        case AppSettings.PullAction.Fetch:
                        case AppSettings.PullAction.FetchAll:
                            buttons = string.Format(buttons, _pullActionFetch.Text);
                            break;
                        case AppSettings.PullAction.Merge:
                            buttons = string.Format(buttons, _pullActionMerge.Text);
                            break;
                        case AppSettings.PullAction.Rebase:
                            buttons = string.Format(buttons, _pullActionRebase.Text);
                            break;
                        default:
                            buttons = string.Format(buttons, _pullActionNone.Text);
                            break;
                    }
                    int idx = PSTaskDialog.cTaskDialog.ShowCommandBox(owner,
                                    String.Format(_pullRepositoryCaption.Text, destination),
                                    _pullRepositoryMainInstruction.Text,
                                    _pullRepository.Text,
                                    "",
                                    "",
                                    _dontShowAgain.Text,
                                    buttons,
                                    true,
                                    0,
                                    0);
                    bool rememberDecision = PSTaskDialog.cTaskDialog.VerificationChecked;
                    switch (idx)
                    {
                        case 0:
                            if (rememberDecision)
                            {
                                AppSettings.AutoPullOnPushRejectedAction = AppSettings.PullAction.Default;
                            }
                            break;
                        case 1:
                            AppSettings.FormPullAction = AppSettings.PullAction.Rebase;
                            if (rememberDecision)
                            {
                                AppSettings.AutoPullOnPushRejectedAction = AppSettings.FormPullAction;
                            }
                            break;
                        case 2:
                            AppSettings.FormPullAction = AppSettings.PullAction.Merge;
                            if (rememberDecision)
                            {
                                AppSettings.AutoPullOnPushRejectedAction = AppSettings.FormPullAction;
                            }
                            break;
                        case 3:
                            forcePush = true;
                            break;
                        default:
                            cancel = true;
                            if (rememberDecision)
                            {
                                AppSettings.AutoPullOnPushRejectedAction = AppSettings.PullAction.None;
                            }
                            break;
                    }
                    if (cancel)
                        return false;
                }

                if (forcePush)
                {
                    if (!form.ProcessArguments.Contains(" -f ") && !form.ProcessArguments.Contains(" --force"))
                    {
                        if (GitCommandHelpers.VersionInUse.SupportPushForceWithLease)
                            form.ProcessArguments = form.ProcessArguments.Replace("push", "push --force-with-lease");
                        else
                            form.ProcessArguments = form.ProcessArguments.Replace("push", "push -f");
                    }
                    form.Retry();
                    return true;
                }

                if (AppSettings.AutoPullOnPushRejectedAction == AppSettings.PullAction.None)
                    return false;

                if (AppSettings.AutoPullOnPushRejectedAction == AppSettings.PullAction.Default)
                {
                    if (Module.LastPullAction == AppSettings.PullAction.None)
                    {
                        return false;
                    }

                    Module.LastPullActionToFormPullAction();
                }

                if (AppSettings.FormPullAction == AppSettings.PullAction.Fetch)
                {
                    form.AppendOutput(Environment.NewLine +
                        "Can not perform auto pull, when merge option is set to fetch.");
                    return false;
                }

                if (IsRebasingMergeCommit())
                {
                    form.AppendOutput(Environment.NewLine +
                        "Can not perform auto pull, when merge option is set to rebase " + Environment.NewLine +
                        "and one of the commits that are about to be rebased is a merge.");
                    return false;
                }

                bool pullCompleted;
                UICommands.StartPullDialog(owner, true, _selectedRemoteBranchName, _selectedBranchRemote, out pullCompleted, false);
                if (pullCompleted)
                {
                    form.Retry();
                    return true;
                }
            }

            return false;
        }