示例#1
0
        //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();
                        }
                    }
                }
            }
        }
示例#2
0
        //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));
            }
        }
示例#3
0
        //this is the main command processing loop
        private void ProcessCommands(CmdLine cmdLine)
        {
            var       cmd = cmdLine.FirstCommand;
            GitBranch branch;
            Int32     branchNum = cmdLine.FirstNumber;

            if (cmd.ToLower() == "git")
            {
                ExecuteShell.RunCmdProcess(cmdLine.FullCommand, false);
                return;
            }

            // if the primary command is a number then we are performing an action
            // based on a branch. any invalid numbers will be ignored
            if (branchNum != -1)
            {
                if (git.ValidBranch(branchNum, out branch))
                {
                    ProcessBranchCommand(branch, cmdLine);
                }
                else
                {
                    Warn($"{branchNum} does not correspond to a branch");
                }
            }
            else
            {
                switch (cmd)
                {
                case "i":
                    //this will only occurr if there is no develop branch.
                    CreateDevelop();
                    break;

                case "/?":
                case "--help":
                    //no help yet as it is built into the view for simple reminder use
                    ShowHelp();
                    break;

                case "exit":
                case "":
                    CloseApp = true;
                    break;

                case "s":
                    //run the stash menu subloop for apply/delete/pop stash
                    ShowStashMenu(cmdLine);
                    break;

                case "p":
                    Inform(GitCommands.PruneRemotes());
                    break;

                case "f":
                    var featureName = "";
                    // a feature can be run in the form of :
                    // f this is a feature
                    // will will run a new feature called this-is-a-feature
                    if (cmdLine.Count > 1)
                    {
                        featureName = String.Join("-", cmdLine.commands, 1, cmdLine.Count - 1);
                    }
                    //if feature name is empty then we will request a name
                    CreateFeatureBranch(featureName);
                    break;

                default:
                    Console.WriteLine("Unknown Command");
                    break;
                }
            }
        }