Exemple #1
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));
            }
        }
Exemple #2
0
        public static string CheckoutBranch(string branch, StashKind stashKind)
        {
            string before = "";
            string after  = "";

            switch (stashKind)
            {
            case StashKind.Stash:
                before = $"git stash push -u -m \"khGit auto-switch-stash {DateTime.Now.ToString()}\"  &&  ";
                break;

            case StashKind.StashAndPop:
                before = $"git stash push -u && ";
                after  = "&&  git stash pop";
                break;

            case StashKind.StashAndApply:
                before = $"git stash push -u -m \"khGit auto-switch-stash {DateTime.Now.ToString()}\" &&  ";
                after  = "&&  git stash apply";
                break;
            }
            return(ExecuteShell.RunCmdProcess($"{before} git checkout {branch} {after}", false));
        }