public void TestCollectArgumentsMergeReset() { GitCheckoutBranchCmd cmd = GetInstance(true); IEnumerable <string> whenMergeChangesOnly = new List <string> { "checkout", "--merge", "\"branchName\"" }; IEnumerable <string> whenMergeChangesWithRemoteNewBranchCreate = new List <string> { "checkout", "--merge", "-b \"newBranchName\"", "\"branchName\"" }; IEnumerable <string> whenMergeChangesWithRemoteNewBranchReset = new List <string> { "checkout", "--merge", "-B \"newBranchName\"", "\"branchName\"" }; IEnumerable <string> whenResetChangesOnly = new List <string> { "checkout", "--force", "\"branchName\"" }; IEnumerable <string> whenResetChangesWithRemoteNewBranchCreate = new List <string> { "checkout", "--force", "-b \"newBranchName\"", "\"branchName\"" }; IEnumerable <string> whenResetChangesWithRemoteNewBranchReset = new List <string> { "checkout", "--force", "-B \"newBranchName\"", "\"branchName\"" }; // Merge { cmd.LocalChanges = LocalChangesAction.Merge; cmd.Remote = false; Assert.AreEqual(cmd.ToLine(), whenMergeChangesOnly.Join(" ")); cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Create; cmd.Remote = true; cmd.NewBranchName = "newBranchName"; Assert.AreEqual(cmd.ToLine(), whenMergeChangesWithRemoteNewBranchCreate.Join(" ")); cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Reset; Assert.AreEqual(cmd.ToLine(), whenMergeChangesWithRemoteNewBranchReset.Join(" ")); } // Reset { cmd.LocalChanges = LocalChangesAction.Reset; cmd.Remote = false; Assert.AreEqual(cmd.ToLine(), whenResetChangesOnly.Join(" ")); cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Create; cmd.Remote = true; cmd.NewBranchName = "newBranchName"; Assert.AreEqual(cmd.ToLine(), whenResetChangesWithRemoteNewBranchCreate.Join(" ")); cmd.NewBranchAction = GitCheckoutBranchCmd.NewBranch.Reset; Assert.AreEqual(cmd.ToLine(), whenResetChangesWithRemoteNewBranchReset.Join(" ")); } }
public void TestConstructorRemoteIsFalse() { var cmd = new GitCheckoutBranchCmd("branchName", false); Assert.IsNotNull(cmd); Assert.AreEqual(cmd.BranchName, "branchName"); Assert.IsFalse(cmd.Remote); }
public void TestConstructorRemoteIsFalse() { GitCheckoutBranchCmd cmd = GetInstance(false); Assert.IsNotNull(cmd); Assert.AreEqual(cmd.BranchName, "branchName"); Assert.IsFalse(cmd.Remote); }
public void TestAccessesRemoteIsFalse() { GitCheckoutBranchCmd cmd = GetInstance(true); Assert.IsFalse(cmd.AccessesRemote()); }
public void TestGitCommandName() { GitCheckoutBranchCmd cmd = GetInstance(true); Assert.AreEqual(cmd.GitComandName(), "checkout"); }
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); }
public void TestAccessesRemoteIsFalse() { var cmd = new GitCheckoutBranchCmd("branchName", true); Assert.IsFalse(cmd.AccessesRemote); }
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); }