m_output; private string m_errorMessage; public GitHistory() { // Initialize member variables. m_output = new List(); } public string GitClient { get { return m_gitClient; } set { m_gitClient = value; } } public string LocalPath { get { return m_localPath; } set { m_localPath = value; } } public string VersionTag { get { return m_versionTag; } set { m_versionTag = value; } } [Output()] public int TotalChanges { get { return m_totalChanges; } } public override bool Execute() { try { // Launch Git Client and wait for it to complete. using (Process p = new Process()) { p.StartInfo.FileName = m_gitClient; p.StartInfo.Arguments = string.Format(@"log --pretty=oneline ""{0}..""", m_versionTag); p.StartInfo.WorkingDirectory = m_localPath; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.OutputDataReceived += OnOutputDataReceived; p.ErrorDataReceived += OnErrorDataReceived; p.Start(); p.BeginOutputReadLine(); p.BeginErrorReadLine(); p.WaitForExit(); } // Check if the command encountered an error. if (!string.IsNullOrEmpty(m_errorMessage)) throw new Exception(m_errorMessage); // Count the number of changes returned by the query. m_totalChanges = m_output.Count; return true; } catch (Exception ex) { // Notify about the exception. m_totalChanges = -1; Log.LogError(ex.Message); return false; } } private void OnOutputDataReceived(object sender, DataReceivedEventArgs e) { // Accumulate the output for processing. if (!string.IsNullOrEmpty(e.Data)) m_output.Add(e.Data); } private void OnErrorDataReceived(object sender, DataReceivedEventArgs e) { // Capture the encountered error. if (!string.IsNullOrEmpty(e.Data)) m_errorMessage = e.Data; } } ]]>