//sub menu for working with existing stash, or creating stash off a branch private void ShowStashMenu(CmdLine cmd) { //this means that the user is asking for a new named stash to be created if (cmd.HasArg("new")) { CreateNewStash(cmd.HasArg("K")); return; } // start a sub loop rendering to the console for stash code. bool bDone = false; Int32 stashNum; while (!bDone && git.Stashes.Count > 0) { render.Clear(); RenderStashes(); var cmdline = GetCommandFromUser(); stashNum = cmdline.FirstNumber; GitStash stash; if (!cmdline.Valid) { //skip out of the submenu bDone = true; } else //this code is both testing and getting a stash for use further down the loop if (stashNum == -1 || !git.GetStash(stashNum, out stash)) { render.WriteLn(">> Invalid stash number", ConsoleColor.Red); } else { if (cmdline.HasArg("del")) { //delete the selected stash Inform(GitCommands.DropStash(stash.Number)); LoadStashes(); } else { // only unstash if the stash matches the active branch // or (F)orce command applied // or confirmation var bContinue = git.ActiveBranch.Branch == stash.Branch || cmdline.HasArg("F") || Confirm($"Unstash ({stash.Number.ToString()}) from {stash.Branch} into {git.ActiveBranch}"); if (bContinue) { Inform(GitCommands.ApplyStash(stash.Number, cmdline.HasArg("d"))); //refresh the stashlist before refreshing the rendering loop LoadStashes(); } } } } }
//cmdSwitch has some options in relation to switching branches // s perform stash backup before moving to a new branch so you can recover the work // // sp stash all work and switch to a new branch and pop it // ideal if you are accidentally coding in the wrong branch and haven't committed // sa stash and apply to new branch, but leave the stash available // ff if the branch is a feature, then finish and close up the feature branch // only do this if the pullrequest and remote doesnt exist private void ProcessBranchCommand(GitBranch gitBranch, CmdLine cmdSwitch) { if (gitBranch.Branch.ToLower().Equals("master")) { Inform("Switching to master branch is not supported in this tool"); return; } if (cmdSwitch.HasArg("FF") || cmdSwitch.HasArg("FFF")) { DeleteFeatureBranch(gitBranch); if (cmdSwitch.HasArg("FFF")) { DeleteOriginFeatureBranch(gitBranch); } return; } if (!gitBranch.IsActive) { // render.WriteLn("S -> will create a stash before switching"); // render.WriteLn("SP-> will create a stash and apply the stash in the new branch and delete the stash"); // render.WriteLn("SA-> will create a stash and apply the stash in the new branch and preserve the stash"); StashKind stashKind = StashKind.None; if (cmdSwitch.HasArg("S")) { stashKind = StashKind.Stash; } else if (cmdSwitch.HasArg("SP")) { stashKind = StashKind.StashAndPop; } else if (cmdSwitch.HasArg("SA")) { stashKind = StashKind.StashAndApply; } Inform(GitCommands.CheckoutBranch(gitBranch.Branch, stashKind)); } }