Пример #1
0
        public static string GetGitRepoNameOrEmpty(Solution solution)
        {
            var sn = solution?.FullName;

            if (string.IsNullOrEmpty(sn))
            {
                return(string.Empty);
            }
            var workingDirectory = new FileInfo(sn).DirectoryName;

            return(GitInfo.IsGitRepository(workingDirectory) ? GetGitRepoName(workingDirectory) ?? string.Empty : string.Empty);
        }
Пример #2
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);
     }
 }
Пример #3
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);
     }
 }
Пример #4
0
 public override string Resolve(AvailableInfo info)
 {
     GitInfo.UpdateGitExecFp(info.GlobalSettings.GitDirectory); // there is likely a better way to adjust the git path
     return(GetGitRepoNameOrEmpty(info.Solution));
 }