internal static string CreateStash(string s, bool keepCode) { var msg = '"' + s + '"'; var sKeepCmd = keepCode ? " && git stash apply " : ""; return(ExecuteShell.RunCmdProcess($"git stash push -u -m {msg} {sKeepCmd} ", false)); }
public static string ApplyStash(int number, bool dropStash) { var stash = "stash@{" + number.ToString() + "}"; var cmd = dropStash ? "pop" : "apply"; return(ExecuteShell.RunCmdProcess($"git stash {cmd} {stash} ", false)); }
public static string DeleteFeatureBranch(string branch, bool switchToDevelop) { string before = ""; if (switchToDevelop) { before = "git checkout develop && "; } return(ExecuteShell.RunCmdProcess($"{before} git branch -d {branch}", false)); }
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)); }
//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; } } }
public static string DeleteRemoteFeatureBranch(string branch) { return(ExecuteShell.RunCmdProcess($"git push origin --delete {branch}", false)); }
public static string PruneRemotes() => ExecuteShell.RunCmdProcess("git remote prune origin", false);
public static string GetAllBranches() => ExecuteShell.RunCmdProcess("git branch && git branch --list -r");
public static string GetUserDetails() => ExecuteShell.RunCmdProcess("git config user.name && git config user.email").Replace("\n", ",");
public static string CreateFeatureBranch(string branchName) { var s = $"git checkout develop && git checkout -b feature/{branchName} && git push -u origin feature/{branchName} "; return(ExecuteShell.RunCmdProcess(s, false)); }
public static string CreateDevelopBranch() => ExecuteShell.RunCmdProcess("git checkout master && git branch develop && git push -u origin develop && git checkout develop", false);
public static string GetBranchList() => ExecuteShell.RunCmdProcess("git branch");
public static string DropStash(int number) { var stash = "stash@{" + number.ToString() + "}"; return(ExecuteShell.RunCmdProcess($"git stash drop {stash} ", false)); }
public static string GetStashList() => ExecuteShell.RunCmdProcess($"git stash list");