public File[] GetFiles(string currentDir, string path) { List <File> files = new List <File>(); ProcessHelper proc = new ProcessHelper(sdPath, @"have " + path); proc.WorkingDirectory = currentDir; string[] lines = proc.Go(); foreach (string line in lines) { // Something like: // //depot/wec/main_dev/zune/client/xaml/music/UI/Controls/TrackStatusIcon.cpp#40 - d:\wec_main_dev\zune\client\xaml\music\UI\Controls\TrackStatusIcon.cpp File file; int poundIndex = line.IndexOf('#'); Debug.Assert(poundIndex > 0); file.DepotPath = line.Substring(0, poundIndex - 1).Trim(); const string localPathPrefix = " - "; int localPathStart = line.IndexOf(localPathPrefix, poundIndex) + localPathPrefix.Length; Debug.Assert(localPathStart > poundIndex + localPathPrefix.Length); file.LocalPath = line.Substring(localPathStart).Trim(); if (!System.IO.File.Exists(file.LocalPath)) { OldLogger.LogLine("File not found locally: " + file.DepotPath, OldLogger.LevelValue.Warning); } files.Add(file); } return(files.ToArray()); }
public static Dictionary <string, string> GetUniqueCommits(string masterBranch, string[] branches) { if (!masterBranch.StartsWith("origin/")) { masterBranch = "origin/" + masterBranch; } Dictionary <string, string> forkpoints = new Dictionary <string, string>(); foreach (string branch in branches) { string forkPoint = (new ProcessHelper("git.exe", "merge-base " + masterBranch + " " + branch)).Go()[0]; Debug.Assert(forkPoint.Length == 40); string trimmedBranch = StringHelper.TrimStart(branch, @"origin/"); forkpoints[trimmedBranch] = forkPoint; OldLogger.LogLine(trimmedBranch + " seems to have forked from " + masterBranch + " at " + forkpoints[trimmedBranch], OldLogger.LevelValue.Verbose); } Dictionary <string, string> uniqueCommits = new Dictionary <string, string>(); foreach (string branch in forkpoints.Keys) { string firstChange = GetNextCommitInBranch(forkpoints[branch], @"origin/" + branch); if (string.IsNullOrEmpty(firstChange)) { OldLogger.LogLine("Unable to find any commits in " + branch, OldLogger.LevelValue.Warning); } else { uniqueCommits[branch] = firstChange; OldLogger.LogLine("The first commit in " + branch + " seems to be " + firstChange, OldLogger.LevelValue.Verbose); } } return(uniqueCommits); }
public static void MergeFromBranch(string sourceBranch) { OldLogger.LogLine("Merging from " + sourceBranch + " to " + GetCurrentBranchName()); ProcessHelper proc = new ProcessHelper("git.exe", "merge --strategy recursive --strategy-option patience " + sourceBranch); proc.Go(); string[] lines = proc.AllOutput; if (StringHelper.AnyLineContains(lines, "Automatic merge failed")) { OldLogger.LogLine("Unable to automatically merge " + GetCurrentBranchName(), OldLogger.LevelValue.Warning); foreach (string line in lines) { if (line.StartsWith("CONFLICT")) { OldLogger.LogLine(line); } } OldLogger.LogLine("Aborting merge"); OldLogger.LogLine("\tTo attempt again, go to " + GetCurrentBranchName() + " and run:"); OldLogger.LogLine("\t\t" + proc.CommandLine); (new ProcessHelper("git.exe", "merge --abort")).Go(); } }
public static bool SwitchBranch(string newBranch, out ProcessHelper proc) { OldLogger.LogLine("Switching to " + newBranch); proc = new ProcessHelper("git.exe", "checkout " + newBranch); proc.Go(); return(proc.ExitCode == 0); }
public static bool DeleteBranch(string branchName, bool force = false) { Debug.Assert(GetStatus().Branch != branchName); OldLogger.LogLine((force ? "FORCE " : "") + "Deleting " + branchName, (force ? OldLogger.LevelValue.Warning : OldLogger.LevelValue.Normal)); string deleteArgs = (force ? "-D" : "-d") + " " + branchName; ProcessHelper proc = new ProcessHelper("git.exe", "branch " + deleteArgs); proc.Go(); bool success = (proc.ExitCode == 0); if (!success) { OldLogger.LogLine("Unable to delete " + branchName, OldLogger.LevelValue.Warning); } return(success); }
public static bool Stash() { DateTime now = DateTime.Now; OldLogger.LogLine("Stashing current work"); string stashMessage = "Automated stash at " + now.ToLongTimeString() + " on " + now.ToShortDateString(); ProcessHelper proc = new ProcessHelper("git.exe", "stash save --include-untracked \"" + stashMessage + "\""); proc.Go(); bool hasError = proc.StandardError.Length != 0; if (hasError) { OldLogger.LogLine(proc.AllOutput, OldLogger.LevelValue.Warning); } return(!hasError); }
public static string[] GetReleaseBranchNames() { List <string> releaseBranches = new List <string>(); ProcessHelper proc = new ProcessHelper("git.exe", "branch -r"); foreach (string line in proc.Go(OldLogger.LevelValue.SuperChatty)) { if (IsReleaseBranchName(line)) { releaseBranches.Add(line.Trim()); } } OldLogger.LogLine("Found the following release branches:", OldLogger.LevelValue.SuperChatty); foreach (string branch in releaseBranches) { OldLogger.LogLine("\t" + branch, OldLogger.LevelValue.SuperChatty); } return(releaseBranches.ToArray()); }
public string[] Go(OldLogger.LevelValue logLevel) { Process process = new Process(); process.StartInfo.FileName = _fileName; process.StartInfo.Arguments = _arguments; if (!string.IsNullOrEmpty(WorkingDirectory)) { process.StartInfo.WorkingDirectory = WorkingDirectory; } string logEventName = "Process: " + _fileName.Substring(_fileName.LastIndexOf('\\') + 1) + " " + _arguments; if (!string.IsNullOrEmpty(process.StartInfo.WorkingDirectory)) { logEventName += " ( " + process.StartInfo.WorkingDirectory + " )"; } OldLogger.Start(logEventName, logLevel); process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.StartInfo.UseShellExecute = false; process.OutputDataReceived += Process_OutputDataReceived; process.ErrorDataReceived += Process_ErrorDataReceived; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); _exitCode = process.ExitCode; _processOver = true; process.OutputDataReceived -= Process_OutputDataReceived; process.ErrorDataReceived -= Process_ErrorDataReceived; OldLogger.Stop(logEventName, output: GetAllOutput(true), level: logLevel); return(GetAllOutput(false)); }
public static void StashPop() { Debug.Assert(!GetStatus().AnyChanges); OldLogger.LogLine("Restoring work from the stash"); (new ProcessHelper("git.exe", "stash pop")).Go(); }
public static void PullCurrentBranch() { Debug.Assert(!GetStatus().AnyChanges); OldLogger.LogLine("Pulling into " + GetCurrentBranchName()); (new ProcessHelper("git.exe", "pull")).Go(); }