private int CreateLostFoundTags() { var selectedLostObjects = Warnings.Rows .Cast <DataGridViewRow>() .Select(row => row.Cells[columnIsLostObjectSelected.Index]) .Where(cell => (bool?)cell.Value == true) .Select(cell => _filteredLostObjects[cell.RowIndex]) .ToList(); if (selectedLostObjects.Count == 0) { MessageBox.Show(this, selectLostObjectsToRestoreMessage.Text, selectLostObjectsToRestoreCaption.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(0); } var currentTag = 0; foreach (var lostObject in selectedLostObjects) { currentTag++; var createTagArgs = new GitCreateTagArgs($"{RestoredObjectsTagPrefix}{currentTag}", lostObject.Hash); var cmd = _gitTagController.GetCreateTagCommand(createTagArgs); UICommands.StartCommandLineProcessDialog(cmd, this); } return(currentTag); }
public void DeleteForce() { var branchHead = CreateBranchRef(UICommands.Module, FullPath); var cmd = new GitDeleteBranchCmd(new[] { branchHead }, true); UICommands.StartCommandLineProcessDialog(cmd, null); }
public void DeleteAllForce() { var branches = Nodes.DepthEnumerator <LocalBranchNode>(); var branchHeads = branches.Select(branch => CreateBranchRef(UICommands.Module, branch.FullPath)); var cmd = new GitDeleteBranchCmd(branchHeads.ToList(), true); UICommands.StartCommandLineProcessDialog(cmd, null); }
/// <summary>Delete the branch on the remote repository.</summary> public void Delete() { var remoteBranchInfo = GetRemoteBranchInfo(); var cmd = new GitDeleteRemoteBranchCmd(remoteBranchInfo.Remote, remoteBranchInfo.BranchName); if (MessageBoxes.ConfirmDeleteRemoteBranch(TreeViewNode.TreeView, remoteBranchInfo.BranchName, remoteBranchInfo.Remote)) { UICommands.StartCommandLineProcessDialog(cmd, null); } }
private void CreateWorktree() { //https://git-scm.com/docs/git-worktree var arguments = "worktree add " + WorktreeDirectory; if (radioButtonCreateNewBranch.Checked) { arguments += " -b " + textBoxNewBranchName.Text; } else { arguments += " " + ((GitRef)comboBoxBranches.SelectedItem).Name; } UICommands.StartCommandLineProcessDialog("git", arguments); this.DialogResult = DialogResult.OK; }
private void OkClick(object sender, EventArgs e) { try { var selectedBranches = Branches.GetSelectedBranches().ToArray(); if (!selectedBranches.Any()) { return; } if (_currentBranch != null && selectedBranches.Any(branch => branch.Name == _currentBranch)) { MessageBox.Show(this, string.Format(_cannotDeleteCurrentBranchMessage.Text, _currentBranch), _deleteBranchCaption.Text); return; } // always treat branches as unmerged if there is no current branch (HEAD is detached) var hasUnmergedBranches = _currentBranch == null || selectedBranches.Any(branch => !_mergedBranches.Contains(branch.Name)); // we could show yes/no dialog and set forcing checkbox automatically, but more safe way is asking user to do it himself if (hasUnmergedBranches && !ForceDelete.Checked) { MessageBox.Show(this, _deleteUnmergedBranchForcingSuggestion.Text, _deleteBranchCaption.Text); return; } // ask for confirmation to delete unmerged branch that may cause loosing commits // (actually we could check if there are another branches pointing to that commit) if (hasUnmergedBranches && MessageBox.Show(this, _deleteBranchQuestion.Text, _deleteBranchCaption.Text, MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } var cmd = new GitDeleteBranchCmd(selectedBranches, ForceDelete.Checked); UICommands.StartCommandLineProcessDialog(this, cmd); } catch (Exception ex) { Trace.WriteLine(ex.Message); } Close(); }
private string CreateTag() { if (string.IsNullOrWhiteSpace(commitPickerSmallControl1.SelectedCommitHash)) { MessageBox.Show(this, _noRevisionSelected.Text, _messageCaption.Text); return(string.Empty); } var createTagArgs = new GitCreateTagArgs(textBoxTagName.Text, commitPickerSmallControl1.SelectedCommitHash, GetSelectedOperation(annotate.SelectedIndex), tagMessage.Text, textBoxGpgKey.Text, ForceTag.Checked); var cmd = _gitTagController.GetCreateTagCommand(createTagArgs); if (!UICommands.StartCommandLineProcessDialog(cmd, this)) { return(string.Empty); } DialogResult = DialogResult.OK; return(textBoxTagName.Text); }
private void PruneWorktrees() { UICommands.StartCommandLineProcessDialog(this, "git", "worktree prune"); Initialize(); }
private DialogResult OkClick() { GitCheckoutBranchCmd cmd = new GitCheckoutBranchCmd(Branches.Text.Trim(), Remotebranch.Checked); if (Remotebranch.Checked) { if (rbCreateBranchWithCustomName.Checked) { cmd.NewBranchName = txtCustomBranchName.Text.Trim(); cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Create; if (cmd.NewBranchName.IsNullOrWhiteSpace()) { MessageBox.Show(_customBranchNameIsEmpty.Text, Text); DialogResult = DialogResult.None; return(DialogResult.None); } if (!Module.CheckBranchFormat(cmd.NewBranchName)) { MessageBox.Show(string.Format(_customBranchNameIsNotValid.Text, cmd.NewBranchName), Text); DialogResult = DialogResult.None; return(DialogResult.None); } } else if (rbResetBranch.Checked) { cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Reset; cmd.NewBranchName = _localBranchName; } else { cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.DontCreate; cmd.NewBranchName = null; } } Settings.LocalChanges changes = ChangesMode; Settings.CheckoutBranchAction = changes; Settings.UseDefaultCheckoutBranchAction = defaultActionChx.Checked; if (ShowLocalChangesGB()) { cmd.SetLocalChangesFromSettings(changes); } else { cmd.SetLocalChangesFromSettings(Settings.LocalChanges.DontChange); } IWin32Window _owner = Visible ? this : Owner; //Stash local changes, but only if the setting CheckForUncommittedChangesInCheckoutBranch is true if (Settings.CheckForUncommittedChangesInCheckoutBranch && changes == Settings.LocalChanges.Stash && Module.IsDirtyDir()) { UICommands.Stash(_owner); } { var successfullyCheckedOut = UICommands.StartCommandLineProcessDialog(cmd, _owner); if (successfullyCheckedOut) { return(DialogResult.OK); } else { return(DialogResult.None); } } }
private DialogResult OkClick() { GitCheckoutBranchCmd cmd = new GitCheckoutBranchCmd(Branches.Text.Trim(), Remotebranch.Checked); if (Remotebranch.Checked) { if (rbCreateBranchWithCustomName.Checked) { cmd.NewBranchName = txtCustomBranchName.Text.Trim(); cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Create; if (cmd.NewBranchName.IsNullOrWhiteSpace()) { MessageBox.Show(_customBranchNameIsEmpty.Text, Text); DialogResult = DialogResult.None; return(DialogResult.None); } if (!Module.CheckBranchFormat(cmd.NewBranchName)) { MessageBox.Show(string.Format(_customBranchNameIsNotValid.Text, cmd.NewBranchName), Text); DialogResult = DialogResult.None; return(DialogResult.None); } } else if (rbResetBranch.Checked) { cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Reset; cmd.NewBranchName = _localBranchName; } else { cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.DontCreate; cmd.NewBranchName = null; } } LocalChangesAction changes = ChangesMode; AppSettings.CheckoutBranchAction = changes; if ((Visible || AppSettings.UseDefaultCheckoutBranchAction) && IsThereUncommittedChanges()) { cmd.LocalChanges = changes; } else { cmd.LocalChanges = LocalChangesAction.DontChange; } IWin32Window owner = Visible ? this : Owner; bool stash = false; if (changes == LocalChangesAction.Stash) { if (_isDirtyDir == null && Visible) { _isDirtyDir = Module.IsDirtyDir(); } stash = _isDirtyDir == true; if (stash) { UICommands.StashSave(owner, AppSettings.IncludeUntrackedFilesInAutoStash); } } if (UICommands.StartCommandLineProcessDialog(cmd, owner)) { if (stash) { bool?messageBoxResult = AppSettings.AutoPopStashAfterCheckoutBranch; 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) { AppSettings.AutoPopStashAfterCheckoutBranch = messageBoxResult; } } if (messageBoxResult ?? false) { UICommands.StashPop(this); } } UICommands.UpdateSubmodules(this); return(DialogResult.OK); } return(DialogResult.None); }
private DialogResult OkClick() { // Ok button set as the "AcceptButton" for the form // if the user hits [Enter] at any point, we need to trigger txtCustomBranchName Leave event Ok.Focus(); GitCheckoutBranchCmd cmd = new GitCheckoutBranchCmd(Branches.Text.Trim(), Remotebranch.Checked); if (Remotebranch.Checked) { if (rbCreateBranchWithCustomName.Checked) { cmd.NewBranchName = txtCustomBranchName.Text.Trim(); cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Create; if (cmd.NewBranchName.IsNullOrWhiteSpace()) { MessageBox.Show(_customBranchNameIsEmpty.Text, Text); DialogResult = DialogResult.None; return(DialogResult.None); } if (!Module.CheckBranchFormat(cmd.NewBranchName)) { MessageBox.Show(string.Format(_customBranchNameIsNotValid.Text, cmd.NewBranchName), Text); DialogResult = DialogResult.None; return(DialogResult.None); } } else if (rbResetBranch.Checked) { IGitRef localBranchRef = GetLocalBranchRef(_localBranchName); IGitRef remoteBranchRef = GetRemoteBranchRef(cmd.BranchName); if (localBranchRef != null && remoteBranchRef != null) { string mergeBaseGuid = Module.GetMergeBase(localBranchRef.Guid, remoteBranchRef.Guid); bool isResetFastForward = localBranchRef.Guid.Equals(mergeBaseGuid); if (!isResetFastForward) { string mergeBaseText = mergeBaseGuid.IsNullOrWhiteSpace() ? "merge base" : GitRevision.ToShortSha(mergeBaseGuid); string warningMessage = string.Format(_resetNonFastForwardBranch.Text, _localBranchName, mergeBaseText); if (MessageBox.Show(this, warningMessage, _resetCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { DialogResult = DialogResult.None; return(DialogResult.None); } } } cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Reset; cmd.NewBranchName = _localBranchName; } else { cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.DontCreate; cmd.NewBranchName = null; } } LocalChangesAction changes = ChangesMode; if (changes != LocalChangesAction.Reset && chkSetLocalChangesActionAsDefault.Checked) { AppSettings.CheckoutBranchAction = changes; } if ((Visible || AppSettings.UseDefaultCheckoutBranchAction) && HasUncommittedChanges) { cmd.LocalChanges = changes; } else { cmd.LocalChanges = LocalChangesAction.DontChange; } IWin32Window owner = Visible ? this : Owner; bool stash = false; if (changes == LocalChangesAction.Stash) { if (_isDirtyDir == null && Visible) { _isDirtyDir = Module.IsDirtyDir(); } stash = _isDirtyDir == true; if (stash) { UICommands.StashSave(owner, AppSettings.IncludeUntrackedFilesInAutoStash); } } var originalHash = Module.GetCurrentCheckout(); ScriptManager.RunEventScripts(this, ScriptEvent.BeforeCheckout); if (UICommands.StartCommandLineProcessDialog(cmd, owner)) { if (stash) { bool?messageBoxResult = AppSettings.AutoPopStashAfterCheckoutBranch; if (messageBoxResult == null) { DialogResult res = cTaskDialog.MessageBox( this, _applyShashedItemsAgainCaption.Text, "", _applyShashedItemsAgain.Text, "", "", _dontShowAgain.Text, eTaskDialogButtons.YesNo, eSysIcons.Question, eSysIcons.Question); messageBoxResult = res == DialogResult.Yes; if (cTaskDialog.VerificationChecked) { AppSettings.AutoPopStashAfterCheckoutBranch = messageBoxResult; } } if (messageBoxResult ?? false) { UICommands.StashPop(this); } } var currentHash = Module.GetCurrentCheckout(); if (!string.Equals(originalHash, currentHash, StringComparison.OrdinalIgnoreCase)) { UICommands.UpdateSubmodules(this); } ScriptManager.RunEventScripts(this, ScriptEvent.AfterCheckout); return(DialogResult.OK); } return(DialogResult.None); }
private DialogResult OkClick() { // Ok button set as the "AcceptButton" for the form // if the user hits [Enter] at any point, we need to trigger txtCustomBranchName Leave event Ok.Focus(); var branchName = Branches.Text.Trim(); var isRemote = Remotebranch.Checked; var newBranchName = (string)null; var newBranchMode = CheckoutNewBranchMode.DontCreate; if (isRemote) { if (rbCreateBranchWithCustomName.Checked) { newBranchName = txtCustomBranchName.Text.Trim(); newBranchMode = CheckoutNewBranchMode.Create; if (string.IsNullOrWhiteSpace(newBranchName)) { MessageBox.Show(_customBranchNameIsEmpty.Text, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; return(DialogResult.None); } if (!Module.CheckBranchFormat(newBranchName)) { MessageBox.Show(string.Format(_customBranchNameIsNotValid.Text, newBranchName), Text, MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; return(DialogResult.None); } } else if (rbResetBranch.Checked) { IGitRef localBranchRef = GetLocalBranchRef(_localBranchName); IGitRef remoteBranchRef = GetRemoteBranchRef(branchName); if (localBranchRef != null && remoteBranchRef != null) { var mergeBaseGuid = Module.GetMergeBase(localBranchRef.ObjectId, remoteBranchRef.ObjectId); var isResetFastForward = localBranchRef.ObjectId == mergeBaseGuid; if (!isResetFastForward) { string mergeBaseText = mergeBaseGuid == null ? "merge base" : mergeBaseGuid.ToShortString(); string warningMessage = string.Format(_resetNonFastForwardBranch.Text, _localBranchName, mergeBaseText); if (MessageBox.Show(this, warningMessage, _resetCaption.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { DialogResult = DialogResult.None; return(DialogResult.None); } } } newBranchMode = CheckoutNewBranchMode.Reset; newBranchName = _localBranchName; } else { newBranchMode = CheckoutNewBranchMode.DontCreate; } } var localChanges = ChangesMode; if (localChanges != LocalChangesAction.Reset && chkSetLocalChangesActionAsDefault.Checked) { AppSettings.CheckoutBranchAction = localChanges; } if ((!Visible && !AppSettings.UseDefaultCheckoutBranchAction) || !HasUncommittedChanges) { localChanges = LocalChangesAction.DontChange; } IWin32Window owner = Visible ? this : Owner; bool stash = false; if (localChanges == LocalChangesAction.Stash) { if (_isDirtyDir == null && Visible) { _isDirtyDir = Module.IsDirtyDir(); } stash = _isDirtyDir == true; if (stash) { UICommands.StashSave(owner, AppSettings.IncludeUntrackedFilesInAutoStash); } } var originalId = Module.GetCurrentCheckout(); Debug.Assert(originalId != null, "originalId != null"); ScriptManager.RunEventScripts(this, ScriptEvent.BeforeCheckout); if (UICommands.StartCommandLineProcessDialog(owner, new GitCheckoutBranchCmd(branchName, isRemote, localChanges, newBranchMode, newBranchName))) { if (stash) { bool?messageBoxResult = AppSettings.AutoPopStashAfterCheckoutBranch; if (messageBoxResult == null) { using var dialog = new TaskDialog { OwnerWindowHandle = Handle, Text = _applyStashedItemsAgain.Text, Caption = _applyStashedItemsAgainCaption.Text, Icon = TaskDialogStandardIcon.Information, StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No, FooterCheckBoxText = _dontShowAgain.Text, FooterIcon = TaskDialogStandardIcon.Information, StartupLocation = TaskDialogStartupLocation.CenterOwner }; messageBoxResult = dialog.Show() == TaskDialogResult.Yes; if (dialog.FooterCheckBoxChecked == true) { AppSettings.AutoPopStashAfterCheckoutBranch = messageBoxResult; } } if (messageBoxResult ?? false) { UICommands.StashPop(this); } } var currentId = Module.GetCurrentCheckout(); if (originalId != currentId) { UICommands.UpdateSubmodules(this); } ScriptManager.RunEventScripts(this, ScriptEvent.AfterCheckout); return(DialogResult.OK); } return(DialogResult.None); IGitRef GetLocalBranchRef(string name) { return(GetLocalBranches().FirstOrDefault(head => head.Name.Equals(name, StringComparison.OrdinalIgnoreCase))); } IGitRef GetRemoteBranchRef(string name) { return(GetRemoteBranches().FirstOrDefault(head => head.Name.Equals(name, StringComparison.OrdinalIgnoreCase))); } }
private DialogResult OkClick() { GitCheckoutBranchCmd cmd = new GitCheckoutBranchCmd(Branches.Text.Trim(), Remotebranch.Checked); if (Remotebranch.Checked) { if (rbCreateBranchWithCustomName.Checked) { cmd.NewBranchName = txtCustomBranchName.Text.Trim(); cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Create; if (cmd.NewBranchName.IsNullOrWhiteSpace()) { MessageBox.Show(_customBranchNameIsEmpty.Text, Text); DialogResult = DialogResult.None; return(DialogResult.None); } if (!Module.CheckBranchFormat(cmd.NewBranchName)) { MessageBox.Show(string.Format(_customBranchNameIsNotValid.Text, cmd.NewBranchName), Text); DialogResult = DialogResult.None; return(DialogResult.None); } } else if (rbResetBranch.Checked) { cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Reset; cmd.NewBranchName = _localBranchName; } else { cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.DontCreate; cmd.NewBranchName = null; } } LocalChangesAction changes = ChangesMode; Settings.CheckoutBranchAction = changes; if (IsThereUncommittedChanges() && (Visible || Settings.UseDefaultCheckoutBranchAction)) { cmd.LocalChanges = changes; } else { cmd.LocalChanges = LocalChangesAction.DontChange; } IWin32Window owner = Visible ? this : Owner; bool stash = changes == LocalChangesAction.Stash && (_isDirtyDir ?? Module.IsDirtyDir()); if (stash) { UICommands.Stash(owner); } if (UICommands.StartCommandLineProcessDialog(cmd, owner)) { if (stash) { bool?messageBoxResult = Settings.AutoPopStashAfterCheckoutBranch; 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.AutoPopStashAfterCheckoutBranch = messageBoxResult; } } if (messageBoxResult ?? false) { FormProcess.ShowDialog(this, Module, "stash pop"); MergeConflictHandler.HandleMergeConflicts(UICommands, this, false); } } return(DialogResult.OK); } return(DialogResult.None); }