예제 #1
0
            void UpdateGitRepoSummary()
            {
                const int shortGitRevLength = 7;

                if (!Directory.Exists(GitRepoPath))
                {
                    GitBranch = GitShortRev = onErrorPlaceholder;
                    return;
                }
                try
                {
                    GitBranchBasename = ReadString(GitRepoPath + @"HEAD")?.
                                        Split(' ')?[1]?.Trim();
                }
                catch (IndexOutOfRangeException ex)
                {
                    GlobalEnabler.LogException(ex);
                }

                // Remove the relative directory that points to a branch file.
                GitBranch = GitBranchBasename?.TrimStart(
                    @"refs/heads/".ToCharArray())?.Trim()
                            ?? onErrorPlaceholder;

                GitShortRev = ReadString(GitRepoPath + GitBranchBasename)?.
                              Substring(0, shortGitRevLength) ?? onErrorPlaceholder;
            }
예제 #2
0
 string ReadString(string path)
 {
     try
     {
         using (var stream = new StreamReader(path))
         {
             return(stream.ReadLine());
         }
     }
     catch (Exception ex)
     {
         GlobalEnabler.LogException(ex);
         return(null);
     }
 }