Пример #1
0
 public static string GetGitRepoName(string workingDirectory)
 {
     using (var pProcess = new System.Diagnostics.Process {
         StartInfo =
         {
             FileName               = GitInfo.GetGitExecFp(),
             Arguments              = "rev-parse --show-toplevel", //As per: https://stackoverflow.com/questions/15715825/how-do-you-get-the-git-repositorys-name-in-some-git-repository
             UseShellExecute        = false,
             StandardOutputEncoding = Encoding.UTF8,
             RedirectStandardOutput = true,
             CreateNoWindow         = true,
             WorkingDirectory       = workingDirectory
         }
     }) {
         pProcess.Start();
         var rootDirectory = pProcess.StandardOutput.ReadToEnd().TrimEnd(' ', '\r', '\n');
         pProcess.WaitForExit();
         if (pProcess.ExitCode != 0)
         {
             return(string.Empty);
         }
         return(new DirectoryInfo(rootDirectory).Name);
     }
 }
Пример #2
0
 public static string GetGitBranch(string workingDirectory)
 {
     using (var pProcess = new System.Diagnostics.Process {
         StartInfo =
         {
             FileName               = GitInfo.GetGitExecFp(),
             Arguments              = "symbolic-ref --short -q HEAD", //As per: http://git-blame.blogspot.sg/2013/06/checking-current-branch-programatically.html. Or: "rev-parse --abbrev-ref HEAD"
             UseShellExecute        = false,
             StandardOutputEncoding = Encoding.UTF8,
             RedirectStandardOutput = true,
             CreateNoWindow         = true,
             WorkingDirectory       = workingDirectory
         }
     }) {
         pProcess.Start();
         var branchName = pProcess.StandardOutput.ReadToEnd().TrimEnd(' ', '\r', '\n');
         pProcess.WaitForExit();
         if (pProcess.ExitCode != 0)
         {
             return("detached HEAD");
         }
         return(branchName);
     }
 }