private void Clone(IHostedRepository repo) { string targetDir = GetTargetDir(); if (targetDir == null) return; string repoSrc = repo.CloneReadWriteUrl; string cmd = GitCommandHelpers.CloneCmd(repoSrc, targetDir, false, string.Empty, null); var formProcess = new FormProcess(Settings.GitCommand, cmd); formProcess.ShowDialog(); if (formProcess.ErrorOccurred()) return; Repositories.RepositoryHistory.AddMostRecentRepository(targetDir); Settings.WorkingDir = targetDir; if (_addRemoteAsTB.Text.Trim().Length > 0 && !string.IsNullOrEmpty(repo.ParentReadOnlyUrl)) { var error = GitCommandHelpers.AddRemote(_addRemoteAsTB.Text.Trim(), repo.ParentReadOnlyUrl); if (!string.IsNullOrEmpty(error)) MessageBox.Show(this, error, _strCouldNotAddRemote.Text); } Close(); }
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); }
private static bool RunScript(IWin32Window owner, GitModule module, ScriptInfo scriptInfo, RevisionGrid revisionGrid) { if (scriptInfo.AskConfirmation && MessageBox.Show(owner, string.Format("Do you want to execute '{0}'?", scriptInfo.Name), "Script", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return(false); } string originalCommand = scriptInfo.Command; string argument = scriptInfo.Arguments; string command = OverrideCommandWhenNecessary(originalCommand); IReadOnlyList <GitRevision> allSelectedRevisions = Array.Empty <GitRevision>(); GitRevision selectedRevision = null; GitRevision currentRevision = null; var selectedLocalBranches = new List <IGitRef>(); var selectedRemoteBranches = new List <IGitRef>(); var selectedRemotes = new List <string>(); var selectedBranches = new List <IGitRef>(); var selectedTags = new List <IGitRef>(); var currentLocalBranches = new List <IGitRef>(); var currentRemoteBranches = new List <IGitRef>(); var currentRemote = ""; var currentBranches = new List <IGitRef>(); var currentTags = new List <IGitRef>(); foreach (string option in Options) { if (string.IsNullOrEmpty(argument) || !argument.Contains(option)) { continue; } if (option.StartsWith("{c") && currentRevision == null) { currentRevision = GetCurrentRevision(module, revisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision); if (currentLocalBranches.Count == 1) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, currentLocalBranches[0].Name)); } else { currentRemote = module.GetCurrentRemote(); if (string.IsNullOrEmpty(currentRemote)) { currentRemote = module.GetSetting(string.Format(SettingKeyString.BranchRemote, AskToSpecify(currentLocalBranches, "Current Revision Branch"))); } } } else if (option.StartsWith("{s") && selectedRevision == null && revisionGrid != null) { allSelectedRevisions = revisionGrid.GetSelectedRevisions(); allSelectedRevisions.Reverse(); // Put first clicked revisions first selectedRevision = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags); } string remote; string url; switch (option) { case "{sHashes}": argument = argument.Replace(option, string.Join(" ", allSelectedRevisions.Select(revision => revision.Guid).ToArray())); break; case "{sTag}": if (selectedTags.Count == 1) { argument = argument.Replace(option, selectedTags[0].Name); } else if (selectedTags.Count != 0) { argument = argument.Replace(option, AskToSpecify(selectedTags, "Selected Revision Tag")); } else { argument = argument.Replace(option, ""); } break; case "{sBranch}": if (selectedBranches.Count == 1) { argument = argument.Replace(option, selectedBranches[0].Name); } else if (selectedBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(selectedBranches, "Selected Revision Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sLocalBranch}": if (selectedLocalBranches.Count == 1) { argument = argument.Replace(option, selectedLocalBranches[0].Name); } else if (selectedLocalBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(selectedLocalBranches, "Selected Revision Local Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sRemoteBranch}": if (selectedRemoteBranches.Count == 1) { argument = argument.Replace(option, selectedRemoteBranches[0].Name); } else if (selectedRemoteBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(selectedRemoteBranches, "Selected Revision Remote Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sRemote}": if (selectedRemotes.Count == 0) { argument = argument.Replace(option, ""); break; } remote = selectedRemotes.Count == 1 ? selectedRemotes[0] : AskToSpecify(selectedRemotes, "Selected Revision Remote"); argument = argument.Replace(option, remote); break; case "{sRemoteUrl}": if (selectedRemotes.Count == 0) { argument = argument.Replace(option, ""); break; } remote = selectedRemotes.Count == 1 ? selectedRemotes[0] : AskToSpecify(selectedRemotes, "Selected Revision Remote"); url = module.GetSetting(string.Format(SettingKeyString.RemoteUrl, remote)); argument = argument.Replace(option, url); break; case "{sRemotePathFromUrl}": if (selectedRemotes.Count == 0) { argument = argument.Replace(option, ""); break; } remote = selectedRemotes.Count == 1 ? selectedRemotes[0] : AskToSpecify(selectedRemotes, "Selected Revision Remote"); url = module.GetSetting(string.Format(SettingKeyString.RemoteUrl, remote)); argument = argument.Replace(option, GetRemotePath(url)); break; case "{sHash}": argument = argument.Replace(option, selectedRevision.Guid); break; case "{sMessage}": argument = argument.Replace(option, selectedRevision.Subject); break; case "{sAuthor}": argument = argument.Replace(option, selectedRevision.Author); break; case "{sCommitter}": argument = argument.Replace(option, selectedRevision.Committer); break; case "{sAuthorDate}": argument = argument.Replace(option, selectedRevision.AuthorDate.ToString()); break; case "{sCommitDate}": argument = argument.Replace(option, selectedRevision.CommitDate.ToString()); break; case "{cTag}": if (currentTags.Count == 1) { argument = argument.Replace(option, currentTags[0].Name); } else if (currentTags.Count != 0) { argument = argument.Replace(option, AskToSpecify(currentTags, "Current Revision Tag")); } else { argument = argument.Replace(option, ""); } break; case "{cBranch}": if (currentBranches.Count == 1) { argument = argument.Replace(option, currentBranches[0].Name); } else if (currentBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(currentBranches, "Current Revision Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cLocalBranch}": if (currentLocalBranches.Count == 1) { argument = argument.Replace(option, currentLocalBranches[0].Name); } else if (currentLocalBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(currentLocalBranches, "Current Revision Local Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cRemoteBranch}": if (currentRemoteBranches.Count == 1) { argument = argument.Replace(option, currentRemoteBranches[0].Name); } else if (currentRemoteBranches.Count != 0) { argument = argument.Replace(option, AskToSpecify(currentRemoteBranches, "Current Revision Remote Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cHash}": argument = argument.Replace(option, currentRevision.Guid); break; case "{cMessage}": argument = argument.Replace(option, currentRevision.Subject); break; case "{cAuthor}": argument = argument.Replace(option, currentRevision.Author); break; case "{cCommitter}": argument = argument.Replace(option, currentRevision.Committer); break; case "{cAuthorDate}": argument = argument.Replace(option, currentRevision.AuthorDate.ToString()); break; case "{cCommitDate}": argument = argument.Replace(option, currentRevision.CommitDate.ToString()); break; case "{cDefaultRemote}": if (string.IsNullOrEmpty(currentRemote)) { argument = argument.Replace(option, ""); break; } argument = argument.Replace(option, currentRemote); break; case "{cDefaultRemoteUrl}": if (string.IsNullOrEmpty(currentRemote)) { argument = argument.Replace(option, ""); break; } url = module.GetSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote)); argument = argument.Replace(option, url); break; case "{cDefaultRemotePathFromUrl}": if (string.IsNullOrEmpty(currentRemote)) { argument = argument.Replace(option, ""); break; } url = module.GetSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote)); argument = argument.Replace(option, GetRemotePath(url)); break; case "{UserInput}": using (SimplePrompt prompt = new SimplePrompt()) { prompt.ShowDialog(); argument = argument.Replace(option, prompt.UserInput); } break; case "{WorkingDir}": argument = argument.Replace(option, module.WorkingDir); break; } } command = ExpandCommandVariables(command, module); if (scriptInfo.IsPowerShell) { PowerShellHelper.RunPowerShell(command, argument, module.WorkingDir, scriptInfo.RunInBackground); return(false); } if (command.StartsWith(PluginPrefix)) { command = command.Replace(PluginPrefix, ""); foreach (var plugin in Plugin.LoadedPlugins.Plugins) { if (plugin.Description.ToLower().Equals(command, StringComparison.CurrentCultureIgnoreCase)) { var eventArgs = new GitUIEventArgs(owner, revisionGrid.UICommands, argument); return(plugin.Execute(eventArgs)); } } return(false); } if (!scriptInfo.RunInBackground) { FormProcess.ShowStandardProcessDialog(owner, command, argument, module.WorkingDir, null, true); } else { if (originalCommand.Equals("{openurl}", StringComparison.CurrentCultureIgnoreCase)) { Process.Start(argument); } else { module.RunExternalCmdDetached(command, argument); } } return(!scriptInfo.RunInBackground); }
private DialogResult EvaluateProcessDialogResults(IWin32Window owner, FormProcess process, bool stashed) { try { if (EvaluateResultsBasedOnSettings(stashed, process)) return DialogResult.OK; } finally { if (stashed) { bool? messageBoxResult = Settings.AutoPopStashAfterPull; if (messageBoxResult == null) { DialogResult res = PSTaskDialog.cTaskDialog.MessageBox( this, _applyShashedItemsAgainCaption.Text, "", _applyShashedItemsAgain.Text, "", "", _dontShowAgain.Text, PSTaskDialog.eTaskDialogButtons.YesNo, PSTaskDialog.eSysIcons.Question, PSTaskDialog.eSysIcons.Question); messageBoxResult = (res == DialogResult.Yes); if (PSTaskDialog.cTaskDialog.VerificationChecked) Settings.AutoPopStashAfterPull = messageBoxResult; } if (ShouldStashPop(messageBoxResult ?? false, process, true)) { FormProcess.ShowDialog(owner, Module, "stash pop"); MergeConflictHandler.HandleMergeConflicts(UICommands, owner, false); } } ScriptManager.RunEventScripts(Module, ScriptEvent.AfterPull); } return DialogResult.No; }
private bool ShouldStashPop(bool messageBoxResult, FormProcess process, bool stashed) { return stashed && process != null && !process.ErrorOccurred() && !Module.InTheMiddleOfConflictedMerge() && !Module.InTheMiddleOfRebase() && messageBoxResult; }
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 (Settings.AutoPullOnRejected && IsRejected.IsMatch(form.GetOutputString())) { 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(form.Owner ?? form, true, out pullCompleted); if (pullCompleted) { form.Retry(); return true; } } } return false; }
private void _fetchBtn_Click(object sender, EventArgs e) { if (_currentPullRequestInfo == null) return; var localBranchName = string.Format("pr/n{0}_{1}", _currentPullRequestInfo.Id, _currentPullRequestInfo.Owner); var cmd = string.Format("fetch --no-tags --progress {0} {1}:{2}", _currentPullRequestInfo.HeadRepo.CloneReadOnlyUrl, _currentPullRequestInfo.HeadRef, localBranchName); var formProcess = new FormProcess(Settings.GitCommand, cmd); formProcess.ShowDialog(this); if (formProcess.ErrorOccurred) return; Close(); }
private void ShowFilesClick(object sender, EventArgs e) { FormProcess.ShowDialog(this, string.Format("add --dry-run{0} \"{1}\"", force.Checked ? " -f" : "", Filter.Text), false); }
private static CommandStatus RunScript(IWin32Window owner, IGitModule module, ScriptInfo scriptInfo, IGitUICommands uiCommands, RevisionGridControl revisionGrid, Action <string> showError) { if (scriptInfo.AskConfirmation && MessageBox.Show(owner, $"Do you want to execute '{scriptInfo.Name}'?", "Script", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return(false); } string originalCommand = scriptInfo.Command; (string argument, bool abort) = ScriptOptionsParser.Parse(scriptInfo.Arguments, module, owner, revisionGrid); if (abort) { showError($"There must be a revision in order to substitute the argument option(s) for the script to run."); return(false); } string command = OverrideCommandWhenNecessary(originalCommand); command = ExpandCommandVariables(command, module); if (scriptInfo.IsPowerShell) { PowerShellHelper.RunPowerShell(command, argument, module.WorkingDir, scriptInfo.RunInBackground); // 'RunPowerShell' always runs the script detached (yet). // Hence currently, it does not make sense to set 'needsGridRefresh' to '!scriptInfo.RunInBackground'. return(new CommandStatus(executed: true, needsGridRefresh: false)); } if (command.StartsWith(PluginPrefix)) { command = command.Replace(PluginPrefix, ""); lock (PluginRegistry.Plugins) { foreach (var plugin in PluginRegistry.Plugins) { if (plugin.Description.ToLower().Equals(command, StringComparison.CurrentCultureIgnoreCase)) { var eventArgs = new GitUIEventArgs(owner, uiCommands); return(new CommandStatus(executed: true, needsGridRefresh: plugin.Execute(eventArgs))); } } } return(false); } if (command.StartsWith(NavigateToPrefix)) { if (revisionGrid == null) { return(false); } command = command.Replace(NavigateToPrefix, string.Empty); if (!string.IsNullOrEmpty(command)) { var revisionRef = new Executable(command, module.WorkingDir).GetOutputLines(argument).FirstOrDefault(); if (revisionRef != null) { revisionGrid.GoToRef(revisionRef, true); } } return(new CommandStatus(executed: true, needsGridRefresh: false)); } if (!scriptInfo.RunInBackground) { FormProcess.ShowStandardProcessDialog(owner, command, argument, module.WorkingDir, null, true); } else { if (originalCommand.Equals("{openurl}", StringComparison.CurrentCultureIgnoreCase)) { Process.Start(argument); } else { new Executable(command, module.WorkingDir).Start(argument); } } return(new CommandStatus(executed: true, needsGridRefresh: !scriptInfo.RunInBackground)); }
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 void OkClick(object sender, EventArgs e) { // Ok button set as the "AcceptButton" for the form // if the user hits [Enter] at any point, we need to trigger BranchNameTextBox Leave event Ok.Focus(); string commitGuid = commitPickerSmallControl1.SelectedCommitHash; if (commitGuid == null) { MessageBox.Show(this, _noRevisionSelected.Text, Text); DialogResult = DialogResult.None; return; } var branchName = BranchNameTextBox.Text.Trim(); if (branchName.IsNullOrWhiteSpace()) { MessageBox.Show(_branchNameIsEmpty.Text, Text); DialogResult = DialogResult.None; return; } if (!Module.CheckBranchFormat(branchName)) { MessageBox.Show(string.Format(_branchNameIsNotValud.Text, branchName), Text); DialogResult = DialogResult.None; return; } try { var originalHash = Module.GetCurrentCheckout(); string cmd; if (Orphan.Checked) { cmd = GitCommandHelpers.CreateOrphanCmd(branchName, commitGuid); } else { cmd = GitCommandHelpers.BranchCmd(branchName, commitGuid, chkbxCheckoutAfterCreate.Checked); } bool wasSuccessFul = FormProcess.ShowDialog(this, cmd); if (Orphan.Checked && wasSuccessFul && ClearOrphan.Checked) {// orphan AND orphan creation success AND clear cmd = GitCommandHelpers.RemoveCmd(); FormProcess.ShowDialog(this, cmd); } if (wasSuccessFul && chkbxCheckoutAfterCreate.Checked && !string.Equals(commitGuid, originalHash, StringComparison.OrdinalIgnoreCase)) { UICommands.UpdateSubmodules(this); } DialogResult = wasSuccessFul ? DialogResult.OK : DialogResult.None; } catch (Exception ex) { Trace.WriteLine(ex.Message); } }
internal static bool RunScript(IWin32Window owner, GitModule aModule, ScriptInfo scriptInfo, RevisionGrid revisionGrid) { string originalCommand = scriptInfo.Command; string argument = scriptInfo.Arguments; string command = OverrideCommandWhenNecessary(originalCommand); GitRevision selectedRevision = null; GitRevision currentRevision = null; var selectedLocalBranches = new List <GitRef>(); var selectedRemoteBranches = new List <GitRef>(); var selectedRemotes = new List <string>(); var selectedBranches = new List <GitRef>(); var selectedTags = new List <GitRef>(); var currentLocalBranches = new List <GitRef>(); var currentRemoteBranches = new List <GitRef>(); var currentRemote = ""; var currentBranches = new List <GitRef>(); var currentTags = new List <GitRef>(); foreach (string option in Options) { if (string.IsNullOrEmpty(argument) || !argument.Contains(option)) { continue; } if (option.StartsWith("{c") || selectedRevision != null) { currentRevision = GetCurrentRevision(aModule, revisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision, option); if (currentLocalBranches.Count == 1) { currentRemote = aModule.GetSetting(string.Format("branch.{0}.remote", currentLocalBranches[0].Name)); } else { currentRemote = aModule.GetCurrentRemote(); if (string.IsNullOrEmpty(currentRemote)) { currentRemote = aModule.GetSetting(string.Format("branch.{0}.remote", askToSpecify(currentLocalBranches, "Current Revision Branch"))); } } } else if (revisionGrid != null) { selectedRevision = CalculateSelectedRevision(revisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags); } string remote; string url; switch (option) { case "{sTag}": if (selectedTags.Count == 1) { argument = argument.Replace(option, selectedTags[0].Name); } else if (selectedTags.Count != 0) { argument = argument.Replace(option, askToSpecify(selectedTags, "Selected Revision Tag")); } else { argument = argument.Replace(option, ""); } break; case "{sBranch}": if (selectedBranches.Count == 1) { argument = argument.Replace(option, selectedBranches[0].Name); } else if (selectedBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(selectedBranches, "Selected Revision Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sLocalBranch}": if (selectedLocalBranches.Count == 1) { argument = argument.Replace(option, selectedLocalBranches[0].Name); } else if (selectedLocalBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(selectedLocalBranches, "Selected Revision Local Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sRemoteBranch}": if (selectedRemoteBranches.Count == 1) { argument = argument.Replace(option, selectedRemoteBranches[0].Name); } else if (selectedRemoteBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(selectedRemoteBranches, "Selected Revision Remote Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sRemote}": if (selectedRemotes.Count == 0) { argument = argument.Replace(option, ""); break; } if (selectedRemotes.Count == 1) { remote = selectedRemotes[0]; } else { remote = askToSpecify(selectedRemotes, "Selected Revision Remote"); } argument = argument.Replace(option, remote); break; case "{sRemoteUrl}": if (selectedRemotes.Count == 0) { argument = argument.Replace(option, ""); break; } if (selectedRemotes.Count == 1) { remote = selectedRemotes[0]; } else { remote = askToSpecify(selectedRemotes, "Selected Revision Remote"); } url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, remote)); argument = argument.Replace(option, url); break; case "{sRemotePathFromUrl}": if (selectedRemotes.Count == 0) { argument = argument.Replace(option, ""); break; } if (selectedRemotes.Count == 1) { remote = selectedRemotes[0]; } else { remote = askToSpecify(selectedRemotes, "Selected Revision Remote"); } url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, remote)); argument = argument.Replace(option, GetRemotePath(url)); break; case "{sHash}": argument = argument.Replace(option, selectedRevision.Guid); break; case "{sMessage}": argument = argument.Replace(option, selectedRevision.Message); break; case "{sAuthor}": argument = argument.Replace(option, selectedRevision.Author); break; case "{sCommitter}": argument = argument.Replace(option, selectedRevision.Committer); break; case "{sAuthorDate}": argument = argument.Replace(option, selectedRevision.AuthorDate.ToString()); break; case "{sCommitDate}": argument = argument.Replace(option, selectedRevision.CommitDate.ToString()); break; case "{cTag}": if (currentTags.Count == 1) { argument = argument.Replace(option, currentTags[0].Name); } else if (currentTags.Count != 0) { argument = argument.Replace(option, askToSpecify(currentTags, "Current Revision Tag")); } else { argument = argument.Replace(option, ""); } break; case "{cBranch}": if (currentBranches.Count == 1) { argument = argument.Replace(option, currentBranches[0].Name); } else if (currentBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(currentBranches, "Current Revision Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cLocalBranch}": if (currentLocalBranches.Count == 1) { argument = argument.Replace(option, currentLocalBranches[0].Name); } else if (currentLocalBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(currentLocalBranches, "Current Revision Local Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cRemoteBranch}": if (currentRemoteBranches.Count == 1) { argument = argument.Replace(option, currentRemoteBranches[0].Name); } else if (currentRemoteBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(currentRemoteBranches, "Current Revision Remote Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cHash}": argument = argument.Replace(option, currentRevision.Guid); break; case "{cMessage}": argument = argument.Replace(option, currentRevision.Message); break; case "{cAuthor}": argument = argument.Replace(option, currentRevision.Author); break; case "{cCommitter}": argument = argument.Replace(option, currentRevision.Committer); break; case "{cAuthorDate}": argument = argument.Replace(option, currentRevision.AuthorDate.ToString()); break; case "{cCommitDate}": argument = argument.Replace(option, currentRevision.CommitDate.ToString()); break; case "{cDefaultRemote}": if (string.IsNullOrEmpty(currentRemote)) { argument = argument.Replace(option, ""); break; } argument = argument.Replace(option, currentRemote); break; case "{cDefaultRemoteUrl}": if (string.IsNullOrEmpty(currentRemote)) { argument = argument.Replace(option, ""); break; } url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote)); argument = argument.Replace(option, url); break; case "{cDefaultRemotePathFromUrl}": if (string.IsNullOrEmpty(currentRemote)) { argument = argument.Replace(option, ""); break; } url = aModule.GetPathSetting(string.Format(SettingKeyString.RemoteUrl, currentRemote)); argument = argument.Replace(option, GetRemotePath(url)); break; case "{UserInput}": using (SimplePrompt Prompt = new SimplePrompt()) { Prompt.ShowDialog(); argument = argument.Replace(option, Prompt.UserInput); } break; } } if (!scriptInfo.RunInBackground) { FormProcess.ShowDialog(owner, command, argument, aModule.WorkingDir, null, true); } else { if (originalCommand.Equals("{openurl}", StringComparison.CurrentCultureIgnoreCase)) { Process.Start(argument); } else { aModule.RunExternalCmdDetached(command, argument); } } return(!scriptInfo.RunInBackground); }
internal static void RunScript(ScriptInfo scriptInfo, RevisionGrid RevisionGrid) { string command = scriptInfo.Command; string argument = scriptInfo.Arguments; command = OverrideCommandWhenNecessary(command); GitRevision selectedRevision = null; GitRevision currentRevision = null; var selectedLocalBranches = new List <GitHead>(); var selectedRemoteBranches = new List <GitHead>(); var selectedRemotes = new List <string>(); var selectedBranches = new List <GitHead>(); var selectedTags = new List <GitHead>(); var currentLocalBranches = new List <GitHead>(); var currentRemoteBranches = new List <GitHead>(); var currentBranches = new List <GitHead>(); var currentTags = new List <GitHead>(); foreach (string option in Options) { if (string.IsNullOrEmpty(argument) || !argument.Contains(option)) { continue; } if (!option.StartsWith("{s") || selectedRevision != null) { currentRevision = GetCurrentRevision(RevisionGrid, currentTags, currentLocalBranches, currentRemoteBranches, currentBranches, currentRevision, option); } else { selectedRevision = CalculateSelectedRevision(RevisionGrid, selectedRemoteBranches, selectedRemotes, selectedLocalBranches, selectedBranches, selectedTags); } switch (option) { case "{sTag}": if (selectedTags.Count == 1) { argument = argument.Replace(option, selectedTags[0].Name); } else if (selectedTags.Count != 0) { argument = argument.Replace(option, askToSpecify(selectedTags, "Selected Revision Tag")); } else { argument = argument.Replace(option, ""); } break; case "{sBranch}": if (selectedBranches.Count == 1) { argument = argument.Replace(option, selectedBranches[0].Name); } else if (selectedBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(selectedBranches, "Selected Revision Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sLocalBranch}": if (selectedLocalBranches.Count == 1) { argument = argument.Replace(option, selectedLocalBranches[0].Name); } else if (selectedLocalBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(selectedLocalBranches, "Selected Revision Local Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sRemoteBranch}": if (selectedRemoteBranches.Count == 1) { argument = argument.Replace(option, selectedRemoteBranches[0].Name); } else if (selectedRemoteBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(selectedRemoteBranches, "Selected Revision Remote Branch")); } else { argument = argument.Replace(option, ""); } break; case "{sRemote}": if (selectedRemotes.Count == 1) { argument = argument.Replace(option, selectedRemotes[0]); } else if (selectedRemotes.Count != 0) { argument = argument.Replace(option, askToSpecify(selectedRemotes, "Selected Revision Remote")); } else { argument = argument.Replace(option, ""); } break; case "{sHash}": argument = argument.Replace(option, selectedRevision.Guid); break; case "{sMessage}": argument = argument.Replace(option, selectedRevision.Message); break; case "{sAuthor}": argument = argument.Replace(option, selectedRevision.Author); break; case "{sCommitter}": argument = argument.Replace(option, selectedRevision.Committer); break; case "{sAuthorDate}": argument = argument.Replace(option, selectedRevision.AuthorDate.ToString()); break; case "{sCommitDate}": argument = argument.Replace(option, selectedRevision.CommitDate.ToString()); break; case "{cTag}": if (currentTags.Count == 1) { argument = argument.Replace(option, currentTags[0].Name); } else if (currentTags.Count != 0) { argument = argument.Replace(option, askToSpecify(currentTags, "Current Revision Tag")); } else { argument = argument.Replace(option, ""); } break; case "{cBranch}": if (currentBranches.Count == 1) { argument = argument.Replace(option, currentBranches[0].Name); } else if (currentBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(currentBranches, "Current Revision Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cLocalBranch}": if (currentLocalBranches.Count == 1) { argument = argument.Replace(option, currentLocalBranches[0].Name); } else if (currentLocalBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(currentLocalBranches, "Current Revision Local Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cRemoteBranch}": if (currentRemoteBranches.Count == 1) { argument = argument.Replace(option, currentRemoteBranches[0].Name); } else if (currentRemoteBranches.Count != 0) { argument = argument.Replace(option, askToSpecify(currentRemoteBranches, "Current Revision Remote Branch")); } else { argument = argument.Replace(option, ""); } break; case "{cHash}": argument = argument.Replace(option, currentRevision.Guid); break; case "{cMessage}": argument = argument.Replace(option, currentRevision.Message); break; case "{cAuthor}": argument = argument.Replace(option, currentRevision.Author); break; case "{cCommitter}": argument = argument.Replace(option, currentRevision.Committer); break; case "{cAuthorDate}": argument = argument.Replace(option, currentRevision.AuthorDate.ToString()); break; case "{cCommitDate}": argument = argument.Replace(option, currentRevision.CommitDate.ToString()); break; case "{cDefaultRemote}": if (currentBranches.Count == 1) { argument = argument.Replace(option, GitModule.Current.GetSetting(string.Format("branch.{0}.remote", currentBranches[0].Name))); } else if (currentBranches.Count != 0) { argument = argument.Replace(option, GitModule.Current.GetSetting(string.Format("branch.{0}.remote", askToSpecify( currentBranches, "Current Revision Branch")))); } else { argument = argument.Replace(option, ""); } break; case "{UserInput}": using (SimplePrompt Prompt = new SimplePrompt()) { Prompt.ShowDialog(); argument = argument.Replace(option, Prompt.UserInput); } break; } } FormProcess.ShowDialog(null, command, argument); }
private void Preview_Click(object sender, EventArgs e) { var cleanUpCmd = GitCommandHelpers.CleanUpCmd(true, RemoveDirectories.Checked, RemoveNonIgnored.Checked, RemoveIngnored.Checked, GetPathArgumentFromGui()); PreviewOutput.Text = FormProcess.ReadDialog(this, cleanUpCmd); }
private void _addAsRemoteAndFetch_Click(object sender, EventArgs e) { if (_currentPullRequestInfo == null) return; var remoteName = _currentPullRequestInfo.Owner; var remoteUrl = _currentPullRequestInfo.HeadRepo.CloneReadOnlyUrl; var remoteRef = _currentPullRequestInfo.HeadRef; var existingRepo = _hostedRemotes.FirstOrDefault(el => el.Name == remoteName); if (existingRepo != null) { if (existingRepo.GetHostedRepository().CloneReadOnlyUrl != remoteUrl) { MessageBox.Show(this, string.Format("ERROR: Remote with name {0} already exists but it does not point to the same repository!\r\nDetails: Is {1} expected {2}", remoteName, existingRepo.GetHostedRepository().CloneReadOnlyUrl, remoteUrl)); return; } } else { var error = GitCommandHelpers.AddRemote(remoteName, remoteUrl); if (!string.IsNullOrEmpty(error)) { MessageBox.Show(this, error, string.Format("Could not add remote with name {0} and URL {1}", remoteName, remoteUrl)); return; } } var cmd = string.Format("fetch --no-tags --progress {0} {1}:{0}/{1}", remoteName, remoteRef); var formProcess = new FormProcess(Settings.GitCommand, cmd); formProcess.ShowDialog(); if (formProcess.ErrorOccurred()) return; cmd = string.Format("checkout {0}/{1}", remoteName, remoteRef); formProcess = new FormProcess(Settings.GitCommand, cmd); formProcess.ShowDialog(); Close(); }
private static CommandStatus RunScriptInternal(IWin32Window owner, IGitModule module, string?scriptKey, IGitUICommands uiCommands, RevisionGridControl?revisionGrid) { if (string.IsNullOrEmpty(scriptKey)) { return(false); } ScriptInfo?scriptInfo = ScriptManager.GetScript(scriptKey); if (scriptInfo is null) { throw new UserExternalOperationException($"{TranslatedStrings.ScriptErrorCantFind}: '{scriptKey}'", new ExternalOperationException(workingDirectory: module.WorkingDir)); } if (string.IsNullOrEmpty(scriptInfo.Command)) { return(false); } string?arguments = scriptInfo.Arguments; if (!string.IsNullOrEmpty(arguments) && revisionGrid is null) { string?optionDependingOnSelectedRevision = ScriptOptionsParser.Options.FirstOrDefault(option => ScriptOptionsParser.DependsOnSelectedRevision(option) && ScriptOptionsParser.Contains(arguments, option)); if (optionDependingOnSelectedRevision is not null) { throw new UserExternalOperationException($"{TranslatedStrings.ScriptText}: '{scriptKey}'{Environment.NewLine}'{optionDependingOnSelectedRevision}' {TranslatedStrings.ScriptErrorOptionWithoutRevisionGridText}", new ExternalOperationException(scriptInfo.Command, arguments, module.WorkingDir)); } } if (scriptInfo.AskConfirmation && MessageBox.Show(owner, $"{TranslatedStrings.ScriptConfirmExecute}: '{scriptInfo.Name}'?", TranslatedStrings.ScriptText, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return(false); } string?originalCommand = scriptInfo.Command; (string?argument, bool abort) = ScriptOptionsParser.Parse(scriptInfo.Arguments, module, owner, revisionGrid); if (abort) { throw new UserExternalOperationException($"{TranslatedStrings.ScriptText}: '{scriptKey}'{Environment.NewLine}{TranslatedStrings.ScriptErrorOptionWithoutRevisionText}", new ExternalOperationException(scriptInfo.Command, arguments, module.WorkingDir)); } string command = OverrideCommandWhenNecessary(originalCommand); command = ExpandCommandVariables(command, module); if (scriptInfo.IsPowerShell) { PowerShellHelper.RunPowerShell(command, argument, module.WorkingDir, scriptInfo.RunInBackground); // 'RunPowerShell' always runs the script detached (yet). // Hence currently, it does not make sense to set 'needsGridRefresh' to '!scriptInfo.RunInBackground'. return(new CommandStatus(executed: true, needsGridRefresh: false)); } if (command.StartsWith(PluginPrefix)) { command = command.Replace(PluginPrefix, string.Empty); lock (PluginRegistry.Plugins) { foreach (var plugin in PluginRegistry.Plugins) { if (string.Equals(plugin.Name, command, StringComparison.CurrentCultureIgnoreCase)) { GitUIEventArgs eventArgs = new(owner, uiCommands); return(new CommandStatus(executed: true, needsGridRefresh: plugin.Execute(eventArgs))); } } } return(false); } if (command.StartsWith(NavigateToPrefix)) { if (revisionGrid is null) { return(false); } command = command.Replace(NavigateToPrefix, string.Empty); if (!string.IsNullOrEmpty(command)) { ExecutionResult result = new Executable(command, module.WorkingDir).Execute(argument); string revisionRef = result.StandardOutput.Split('\n').FirstOrDefault(); if (revisionRef is not null) { revisionGrid.GoToRef(revisionRef, true); } } return(new CommandStatus(executed: true, needsGridRefresh: false)); } if (!scriptInfo.RunInBackground) { bool success = FormProcess.ShowDialog(owner, argument, module.WorkingDir, null, true, process: command); if (!success) { return(false); } } else { if (originalCommand.Equals("{openurl}", StringComparison.CurrentCultureIgnoreCase)) { OsShellUtil.OpenUrlInDefaultBrowser(argument); } else { // It is totally valid to have a command without an argument, e.g.: // Command : myscript.cmd // Arguments: <blank> new Executable(command, module.WorkingDir).Start(argument ?? string.Empty); } } return(new CommandStatus(executed: true, needsGridRefresh: !scriptInfo.RunInBackground)); }
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; }
public DialogResult PullChanges(IWin32Window owner) { if (!ShouldPullChanges()) { return(DialogResult.No); } UpdateSettingsDuringPull(); DialogResult dr = ShouldRebaseMergeCommit(); if (dr != DialogResult.Yes) { return(dr); } if (!Fetch.Checked && Branches.Text.IsNullOrWhiteSpace() && Module.IsDetachedHead()) { int idx = PSTaskDialog.cTaskDialog.ShowCommandBox(owner, _notOnBranchCaption.Text, _notOnBranchMainInstruction.Text, _notOnBranch.Text, _notOnBranchButtons.Text, true); switch (idx) { case 0: if (!UICommands.StartCheckoutBranch(owner, new[] { "" })) { return(DialogResult.Cancel); } break; case -1: return(DialogResult.Cancel); } } if (PullFromUrl.Checked && Directory.Exists(comboBoxPullSource.Text)) { Repositories.RepositoryHistory.AddMostRecentRepository(comboBoxPullSource.Text); } var source = CalculateSource(); string curLocalBranch; string curRemoteBranch; if (!CalculateLocalBranch(source, out curLocalBranch, out curRemoteBranch)) { return(DialogResult.No); } ScriptManager.RunEventScripts(this, ScriptEvent.BeforePull); var stashed = CalculateStashedValue(owner); using (FormProcess process = CreateFormProcess(source, curLocalBranch, curRemoteBranch)) { ShowProcessDialogBox(owner, source, process); try { bool aborted = process != null && process.DialogResult == DialogResult.Abort; if (!aborted && !Fetch.Checked) { if (!ErrorOccurred) { if (!InitModules()) { UICommands.UpdateSubmodules(owner); } } else { CheckMergeConflictsOnError(owner); } } } finally { if (stashed) { PopStash(owner); } ScriptManager.RunEventScripts(this, ScriptEvent.AfterPull); } return(DialogResult.OK); } }
private void _addAsRemoteAndFetch_Click(object sender, EventArgs e) { if (_currentPullRequestInfo == null) return; var remoteName = _currentPullRequestInfo.Owner; var remoteUrl = _currentPullRequestInfo.HeadRepo.CloneReadOnlyUrl; var remoteRef = _currentPullRequestInfo.HeadRef; var existingRepo = _hostedRemotes.FirstOrDefault(el => el.Name == remoteName); if (existingRepo != null) { if (existingRepo.GetHostedRepository().CloneReadOnlyUrl != remoteUrl) { MessageBox.Show(this, string.Format(_strRemoteAlreadyExist.Text, remoteName, existingRepo.GetHostedRepository().CloneReadOnlyUrl, remoteUrl)); return; } } else { var error = Settings.Module.AddRemote(remoteName, remoteUrl); if (!string.IsNullOrEmpty(error)) { MessageBox.Show(this, error, string.Format(_strCouldNotAddRemote.Text, remoteName, remoteUrl)); return; } } var cmd = string.Format("fetch --no-tags --progress {0} {1}:{0}/{1}", remoteName, remoteRef); var formProcess = new FormProcess(Settings.GitCommand, cmd); formProcess.ShowDialog(this); if (formProcess.ErrorOccurred) return; cmd = string.Format("checkout {0}/{1}", remoteName, remoteRef); formProcess = new FormProcess(Settings.GitCommand, cmd); formProcess.ShowDialog(this); Close(); }
private void ContinueBisect(GitBisectOption bisectOption) { FormProcess.ShowDialog(this, process: null, arguments: GitCommandHelpers.ContinueBisectCmd(bisectOption), Module.WorkingDir, input: null, useDialogSettings: false); Close(); }
private bool HandlePullOnExit(ref bool isError, FormProcess form) { if (!isError) return false; if (!PullFromRemote.Checked || string.IsNullOrEmpty(_NO_TRANSLATE_Remotes.Text)) return false; //auto pull only if current branch was rejected Regex isRefRemoved = new Regex(@"Your configuration specifies to .* the ref '.*'[\r]?\nfrom the remote, but no such ref was fetched."); if (isRefRemoved.IsMatch(form.GetOutputString())) { int idx = PSTaskDialog.cTaskDialog.ShowCommandBox(form, _pruneBranchesCaption.Text, _pruneBranchesMainInstruction.Text, _pruneBranchesBranch.Text, _pruneBranchesButtons.Text, true); if (idx == 0) { string remote = _NO_TRANSLATE_Remotes.Text; string pruneCmd = "remote prune " + remote; using (var formPrune = new FormRemoteProcess(Module, pruneCmd) { Remote = remote, Text = string.Format(_pruneFromCaption.Text, remote) }) { formPrune.ShowDialog(form); } } } return false; }
private void Stop_Click(object sender, EventArgs e) { FormProcess.ShowDialog(this, process: null, arguments: GitCommandHelpers.StopBisectCmd(), Module.WorkingDir, input: null, useDialogSettings: false); Close(); }
private bool EvaluateResultsBasedOnSettings(bool stashed, FormProcess process) { if (!Module.InTheMiddleOfConflictedMerge() && !Module.InTheMiddleOfRebase() && (process != null && !process.ErrorOccurred())) { InitModules(); return true; } // Rebase failed -> special 'rebase' merge conflict if (Rebase.Checked && Module.InTheMiddleOfRebase()) { UICommands.StartRebaseDialog(null); if (!Module.InTheMiddleOfConflictedMerge() && !Module.InTheMiddleOfRebase()) { return true; } } else { MergeConflictHandler.HandleMergeConflicts(UICommands, this); if (!Module.InTheMiddleOfConflictedMerge() && !Module.InTheMiddleOfRebase()) { return true; } } if (!AutoStash.Checked || !stashed || Module.InTheMiddleOfConflictedMerge() || Module.InTheMiddleOfRebase()) { return true; } return false; }
private void _addAsRemoteAndFetch_Click(object sender, EventArgs e) { if (_currentPullRequestInfo == null) { return; } UICommands.RepoChangedNotifier.Lock(); try { var remoteName = _currentPullRequestInfo.Owner; var remoteUrl = _currentPullRequestInfo.HeadRepo.CloneReadOnlyUrl; var remoteRef = _currentPullRequestInfo.HeadRef; var existingRepo = _hostedRemotes.FirstOrDefault(el => el.Name == remoteName); if (existingRepo != null) { var hostedRepository = existingRepo.GetHostedRepository(); hostedRepository.CloneProtocol = _cloneGitProtocol; if (hostedRepository.CloneReadOnlyUrl != remoteUrl) { MessageBox.Show(this, string.Format(_strRemoteAlreadyExist.Text, remoteName, hostedRepository.CloneReadOnlyUrl, remoteUrl), Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { var error = Module.AddRemote(remoteName, remoteUrl); if (!string.IsNullOrEmpty(error)) { MessageBox.Show(this, error, string.Format(_strCouldNotAddRemote.Text, remoteName, remoteUrl), MessageBoxButtons.OK, MessageBoxIcon.Error); return; } UICommands.RepoChangedNotifier.Notify(); } var cmd = string.Format("fetch --no-tags --progress {0} {1}:{0}/{1}", remoteName, remoteRef); var errorOccurred = !FormProcess.ShowDialog(this, AppSettings.VsrCommand, cmd); if (errorOccurred) { return; } UICommands.RepoChangedNotifier.Notify(); cmd = string.Format("checkout {0}/{1}", remoteName, remoteRef); if (FormProcess.ShowDialog(this, AppSettings.VsrCommand, cmd)) { UICommands.RepoChangedNotifier.Notify(); } } finally { UICommands.RepoChangedNotifier.UnLock(false); } Close(); }
private void ShowProcessDialogBox(IWin32Window owner, string source, FormProcess process) { if (process == null) return; if (!IsPullAll()) process.Remote = source; process.ShowDialog(owner); ErrorOccurred = process.ErrorOccurred(); }
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); }
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; }
private void ShowFilesClick(object sender, EventArgs e) { string arguments = string.Format("add --dry-run{0} \"{1}\"", force.Checked ? " -f" : "", Filter.Text); FormProcess.ShowDialog(this, arguments, Module.WorkingDir, input: null, useDialogSettings: false); }