private void Apply_Click(object sender, EventArgs e) { var patchFile = PatchFile.Text; var dirText = PatchDir.Text; var ignoreWhiteSpace = IgnoreWhitespace.Checked; if (string.IsNullOrEmpty(patchFile) && string.IsNullOrEmpty(dirText)) { MessageBox.Show(this, _noFileSelectedText.Text); return; } using (WaitCursorScope.Enter()) { if (PatchFileMode.Checked) { var arguments = IsDiffFile(patchFile) ? GitCommandHelpers.ApplyDiffPatchCmd(ignoreWhiteSpace, patchFile) : GitCommandHelpers.ApplyMailboxPatchCmd(ignoreWhiteSpace, patchFile); FormProcess.ShowDialog(this, arguments); } else { var arguments = GitCommandHelpers.ApplyMailboxPatchCmd(ignoreWhiteSpace); Module.ApplyPatch(dirText, arguments); } UICommands.RepoChangedNotifier.Notify(); EnableButtons(); if (!Module.InTheMiddleOfAction() && !Module.InTheMiddleOfPatch()) { Close(); } } }
private void SkipClick(object sender, EventArgs e) { using (WaitCursorScope.Enter()) { var applyingPatch = patchGrid1.PatchFiles.FirstOrDefault(p => p.IsNext); if (applyingPatch != null) { applyingPatch.IsSkipped = true; } FormProcess.ShowDialog(this, GitCommandHelpers.SkipRebaseCmd()); if (!Module.InTheMiddleOfRebase()) { Close(); } EnableButtons(); patchGrid1.RefreshGrid(); } }
private void ConflictedFiles_DoubleClick(object sender, EventArgs e) { using (WaitCursorScope.Enter()) { try { var items = GetConflicts(); StartProgressBarWithMaxValue(items.Length); foreach (var conflictData in items) { IncrementProgressBarValue(); ResolveItemConflict(conflictData); } } finally { StopAndHideProgressBar(); Initialize(); } } }
private void UpdateLostObjects() { using (WaitCursorScope.Enter()) { string cmdOutput = FormProcess.ReadDialog(this, process: null, arguments: $"fsck-objects{GetOptions()}", Module.WorkingDir, input: null, useDialogSettings: true); if (FormProcess.IsOperationAborted(cmdOutput)) { DialogResult = DialogResult.Abort; return; } _lostObjects.Clear(); _lostObjects.AddRange( cmdOutput .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select((s) => LostObject.TryParse(Module, s)) .Where(parsedLostObject => parsedLostObject is not null) .OrderByDescending(l => l.Date)); UpdateFilteredLostObjects(); } }
private void UpdateLostObjects() { using (WaitCursorScope.Enter()) { var dialogResult = FormProcess.ReadDialog(this, "fsck-objects" + GetOptions()); if (FormProcess.IsOperationAborted(dialogResult)) { DialogResult = DialogResult.Abort; return; } _lostObjects.Clear(); _lostObjects.AddRange( dialogResult .Split('\r', '\n') .Where(s => !string.IsNullOrEmpty(s)) .Select((s) => LostObject.TryParse(Module, s)) .Where(parsedLostObject => parsedLostObject != null)); UpdateFilteredLostObjects(); } }
private void SkipClick(object sender, EventArgs e) { using (WaitCursorScope.Enter()) { var applyingPatch = patchGrid1.PatchFiles.FirstOrDefault(p => p.IsNext); if (applyingPatch is not null) { applyingPatch.IsSkipped = true; Skipped.Add(applyingPatch); } FormProcess.ShowDialog(this, process: null, arguments: GitCommandHelpers.SkipRebaseCmd(), Module.WorkingDir, input: null, useDialogSettings: true); if (!Module.InTheMiddleOfRebase()) { Close(); } EnableButtons(); patchGrid1.RefreshGrid(); } }
private void LoadMultiBranchViewData(string remote) { using (WaitCursorScope.Enter(Cursors.AppStarting)) { IReadOnlyList <IGitRef> remoteHeads; if (Module.EffectiveSettings.Detailed.GetRemoteBranchesDirectlyFromRemote.ValueOrDefault) { EnsurePageant(remote); var formProcess = new FormRemoteProcess(Module, $"ls-remote --heads \"{remote}\"") { Remote = remote }; using (formProcess) { formProcess.ShowDialog(this); if (formProcess.ErrorOccurred()) { return; } var refList = CleanCommandOutput(formProcess.GetOutputString()); remoteHeads = Module.ParseRefs(refList); } } else { // use remote branches from git's local database if there were problems with receiving branches from the remote server remoteHeads = Module.GetRemoteBranches().Where(r => r.Remote == remote).ToList(); } ProcessHeads(remoteHeads); } return; string CleanCommandOutput(string processOutput) { // Command output consists of lines of format: // // <SHA1> \t <full-ref> // // Such as: // // fa77791d780a01a06d1f7d4ccad4ef93ed0ae2fd\trefs/heads/branchName int firstTabIdx = processOutput.IndexOf('\t'); return(firstTabIdx == 40 ? processOutput : firstTabIdx > 40 ? processOutput.Substring(firstTabIdx - 40) : string.Empty); } void ProcessHeads(IReadOnlyList <IGitRef> remoteHeads) { var localHeads = GetLocalBranches().ToList(); var remoteBranches = remoteHeads.ToHashSet(h => h.LocalName); // Add all the local branches. foreach (var head in localHeads) { var remoteName = head.Remote == remote ? head.MergeWith ?? head.Name : head.Name; var isKnownAtRemote = remoteBranches.Contains(remoteName); var row = _branchTable.NewRow(); row[ForceColumnName] = false; row[DeleteColumnName] = false; row[LocalColumnName] = head.Name; row[RemoteColumnName] = remoteName; row[NewColumnName] = isKnownAtRemote ? _no.Text : _yes.Text; row[PushColumnName] = isKnownAtRemote; _branchTable.Rows.Add(row); } // Offer to delete all the left over remote branches. foreach (var remoteHead in remoteHeads) { if (localHeads.All(h => h.Name != remoteHead.LocalName)) { var row = _branchTable.NewRow(); row[LocalColumnName] = null; row[RemoteColumnName] = remoteHead.LocalName; row[NewColumnName] = _no.Text; row[PushColumnName] = false; row[ForceColumnName] = false; row[DeleteColumnName] = false; _branchTable.Rows.Add(row); } } BranchGrid.Enabled = true; } }
private void StashedSelectedIndexChanged(object sender, EventArgs e) { GitStash gitStash = Stashes.SelectedItem as GitStash; GitItemStatus stashedItem = Stashed.SelectedItem; EnablePartialStash(); using (WaitCursorScope.Enter()) { if (stashedItem != null && gitStash == _currentWorkingDirStashItem) { // current working directory View.ViewCurrentChanges(stashedItem, isStaged: false, openWithDifftool: null); } else if (stashedItem != null) { if (stashedItem.IsNew) { if (!stashedItem.IsSubmodule) { View.ViewGitItemAsync(stashedItem.Name, stashedItem.TreeGuid); } else { ThreadHelper.JoinableTaskFactory.RunAsync( () => View.ViewTextAsync( stashedItem.Name, LocalizationHelpers.GetSubmoduleText(Module, stashedItem.Name, stashedItem.TreeGuid?.ToString()))); } } else { string extraDiffArguments = View.GetExtraDiffArguments(); Encoding encoding = View.Encoding; ThreadHelper.JoinableTaskFactory.Run( () => { Patch patch = Module.GetSingleDiff(gitStash.Name + "^", gitStash.Name, stashedItem.Name, stashedItem.OldName, extraDiffArguments, encoding, true, stashedItem.IsTracked); if (patch == null) { return(View.ViewPatchAsync(fileName: null, text: string.Empty, openWithDifftool: null /* not applicable */, isText: true)); } if (stashedItem.IsSubmodule) { return(View.ViewPatchAsync(fileName: null, text: LocalizationHelpers.ProcessSubmodulePatch(Module, stashedItem.Name, patch), openWithDifftool: null /* not implemented */, isText: stashedItem.IsSubmodule)); } return(View.ViewPatchAsync(fileName: stashedItem.Name, text: patch.Text, openWithDifftool: null /* not implemented */, isText: stashedItem.IsSubmodule)); }); } } else { View.Clear(); } } }
private void Initialize() { using (WaitCursorScope.Enter()) { int oldSelectedRow = 0; if (ConflictedFiles.SelectedRows.Count > 0) { oldSelectedRow = ConflictedFiles.SelectedRows[0].Index; } ConflictedFiles.DataSource = Module.GetConflicts(); ConflictedFiles.Columns[0].DataPropertyName = nameof(ConflictData.Filename); if (ConflictedFiles.Rows.Count > oldSelectedRow) { ConflictedFiles.Rows[oldSelectedRow].Selected = true; if (oldSelectedRow < ConflictedFiles.FirstDisplayedScrollingRowIndex || oldSelectedRow > (ConflictedFiles.FirstDisplayedScrollingRowIndex + ConflictedFiles.DisplayedRowCount(false))) { try { ConflictedFiles.FirstDisplayedScrollingRowIndex = oldSelectedRow; } catch (InvalidOperationException) { // ignore the exception - setting the row index is not so important to crash the app // see the #2975 issues for details } } } if (!InitMergetool()) { Close(); return; } ConflictedFilesContextMenu.Text = _conflictedFilesContextMenuText.Text; OpenMergetool.Text = _openMergeToolItemText.Text + " " + _mergetool; openMergeToolBtn.Text = _button1Text.Text + " " + _mergetool; if (Module.InTheMiddleOfRebase()) { Reset.Text = _resetItemRebaseText.Text; ContextChooseLocal.Text = _contextChooseLocalRebaseText.Text; ContextChooseRemote.Text = _contextChooseRemoteRebaseText.Text; } else { Reset.Text = _resetItemMergeText.Text; ContextChooseLocal.Text = _contextChooseLocalMergeText.Text; ContextChooseRemote.Text = _contextChooseRemoteMergeText.Text; } if (!Module.InTheMiddleOfConflictedMerge() && _thereWhereMergeConflicts) { UICommands.UpdateSubmodules(this); if (!Module.InTheMiddleOfPatch() && !Module.InTheMiddleOfRebase() && _offerCommit) { if (AppSettings.DontConfirmCommitAfterConflictsResolved || MessageBox.Show(this, _allConflictsResolved.Text, _allConflictsResolvedCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { UICommands.StartCommitDialog(this); } } Close(); } } }