< Summary

Information
Class: DirectSight.Reporting.GitHelper
Assembly DirectSight
File(s): /home/runner/work/DirectSight/DirectSight/DirectSight/Reporting/GitHelper.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 30
Coverable lines: 30
Total lines: 60
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
GetGitInformation()100%110%
GetFileHash(...)100%110%
ExecuteGitCommand(...)100%110%

File(s)

/home/runner/work/DirectSight/DirectSight/DirectSight/Reporting/GitHelper.cs

#LineLine coverage
 1using System.Diagnostics;
 2
 3namespace DirectSight.Reporting;
 4
 5/// <summary>
 6/// Helper class to retrieve information from Git.
 7/// </summary>
 8internal static class GitHelper
 9{
 10    /// <summary>
 11    /// Gets the Git information.
 12    /// </summary>
 13    /// <returns>The Git information.</returns>
 14    public static GitInformation GetGitInformation()
 015    {
 016        GitInformation gitInformation = new GitInformation();
 017        gitInformation.Branch = ExecuteGitCommand("rev-parse --abbrev-ref HEAD");
 018        gitInformation.Sha = ExecuteGitCommand("rev-parse HEAD");
 019        gitInformation.TimeStamp = ExecuteGitCommand("show -s --format=%ct");
 020        return gitInformation;
 021    }
 22
 23    /// <summary>
 24    /// Gets the file hash.
 25    /// </summary>
 26    /// <param name="path">The path.</param>
 27    /// <returns>The Git information.</returns>
 28    public static string GetFileHash(string path)
 029    {
 030        return ExecuteGitCommand("hash-object " + path);
 031    }
 32
 33    private static string ExecuteGitCommand(string arguments)
 034    {
 35        try
 036        {
 037            ProcessStartInfo processStartInfo = new ProcessStartInfo
 038            {
 039                FileName = "git",
 040                Arguments = arguments,
 041                RedirectStandardOutput = true,
 042                UseShellExecute = false,
 043                CreateNoWindow = true
 044            };
 45
 046            using (Process process = new Process { StartInfo = processStartInfo })
 047            {
 048                process.Start();
 049                string output = process.StandardOutput.ReadToEnd();
 050                process.WaitForExit();
 51
 052                return output.Trim();
 53            }
 54        }
 055        catch (System.Exception)
 056        {
 057            return string.Empty;
 58        }
 059    }
 60}