private bool HandlePushOnExit(ref bool isError, FormProcess form) { if (isError) { //auto pull only if current branch was rejected Regex IsRejected = new Regex(Regex.Escape("! [rejected] ") + ".*" + Regex.Escape(_currentBranch) + ".*" + Regex.Escape(" (non-fast-forward)"), RegexOptions.Compiled); if (Settings.AutoPullOnRejected && IsRejected.IsMatch(form.OutputString.ToString())) { if (Settings.PullMerge == Settings.PullAction.Fetch) { form.AppendOutputLine(Environment.NewLine + "Can not perform auto pull, when merge option is set to fetch."); } else if (IsRebasingMergeCommit()) { form.AppendOutputLine(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."); } else { bool pullCompleted; UICommands.StartPullDialog(this, true, out pullCompleted); if (pullCompleted) { form.Retry(); return(true); } } } } return(false); }
public void Pull() { bool pullCompleted = false; var remoteBranchInfo = GetRemoteBranchInfo(); UICommands.StartPullDialog(this.TreeViewNode.TreeView, pullOnShow: false, remoteBranch: remoteBranchInfo.BranchName, remote: remoteBranchInfo.Remote, pullCompleted: out pullCompleted, fetchAll: false); }
private void PullClick(object sender, EventArgs e) { UICommands.StartPullDialog(this); }
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); }
private bool HandlePushOnExit(ref bool isError, FormProcess form) { if (!isError) { return(false); } //auto pull only if current branch was rejected Regex IsRejected = new Regex(Regex.Escape("! [rejected] ") + ".*" + Regex.Escape(_currentBranch) + ".*" + Regex.Escape(" (non-fast-forward)"), RegexOptions.Compiled); if (IsRejected.IsMatch(form.GetOutputString())) { IWin32Window owner = form; if (Settings.AutoPullOnPushRejectedAction == null) { bool cancel = false; int idx = PSTaskDialog.cTaskDialog.ShowCommandBox(owner, _pullRepositoryCaption.Text, _pullRepositoryMainInstruction.Text, _pullRepository.Text, "", "", _dontShowAgain.Text, _pullRepositoryButtons.Text, true, 0, 0); bool rememberDecision = PSTaskDialog.cTaskDialog.VerificationChecked; switch (idx) { case 0: if (rememberDecision) { Settings.AutoPullOnPushRejectedAction = Settings.PullAction.Default; } if (Module.LastPullAction == Settings.PullAction.None) { return(false); } Module.LastPullActionToFormPullAction(); break; case 1: Settings.FormPullAction = Settings.PullAction.Rebase; if (rememberDecision) { Settings.AutoPullOnPushRejectedAction = Settings.FormPullAction; } break; case 2: Settings.FormPullAction = Settings.PullAction.Merge; if (rememberDecision) { Settings.AutoPullOnPushRejectedAction = Settings.FormPullAction; } break; default: cancel = true; if (rememberDecision) { Settings.AutoPullOnPushRejectedAction = Settings.PullAction.None; } break; } if (cancel) { return(false); } } if (Settings.AutoPullOnPushRejectedAction == Settings.PullAction.None) { return(false); } if (Settings.FormPullAction == Settings.PullAction.Fetch) { form.AppendOutputLine(Environment.NewLine + "Can not perform auto pull, when merge option is set to fetch."); return(false); } if (IsRebasingMergeCommit()) { form.AppendOutputLine(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, out pullCompleted); if (pullCompleted) { form.Retry(); return(true); } } return(false); }
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; int idx = PSTaskDialog.cTaskDialog.ShowCommandBox(owner, String.Format(_pullRepositoryCaption.Text, destination), _pullRepositoryMainInstruction.Text, _pullRepository.Text, "", "", _dontShowAgain.Text, _pullRepositoryButtons.Text, true, 0, 0); bool rememberDecision = PSTaskDialog.cTaskDialog.VerificationChecked; switch (idx) { case 0: if (rememberDecision) { AppSettings.AutoPullOnPushRejectedAction = AppSettings.PullAction.Default; } if (Module.LastPullAction == AppSettings.PullAction.None) { return(false); } Module.LastPullActionToFormPullAction(); 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 = form.ProcessArguments.Replace("push", "push -f"); } form.Retry(); return(true); } if (AppSettings.AutoPullOnPushRejectedAction == AppSettings.PullAction.None) { return(false); } if (AppSettings.FormPullAction == AppSettings.PullAction.Fetch) { form.AppendOutputLine(Environment.NewLine + "Can not perform auto pull, when merge option is set to fetch."); return(false); } if (IsRebasingMergeCommit()) { form.AppendOutputLine(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, null, _selectedBranchRemote, out pullCompleted, false); if (pullCompleted) { form.Retry(); return(true); } } return(false); }