<commit_before>﻿using System;
using System.ComponentModel;
using System.IO;
using NDesk.Options;
using StructureMap;
using Sep.Git.Tfs.Core;

namespace Sep.Git.Tfs.Commands
{
    [Pluggable("info")]
    [Description("info")]
    [RequiresValidGitRepository]
    public class Info : GitTfsCommand
    {
        readonly Globals _globals;
        readonly TextWriter _stdout;
        readonly IGitTfsVersionProvider _versionProvider;

        public Info(Globals globals, TextWriter stdout, IGitTfsVersionProvider versionProvider)
        {
            _globals = globals;
            _stdout = stdout;
            _versionProvider = versionProvider;
        }

        public OptionSet OptionSet { get { return _globals.OptionSet; } }

        public int Run()
        {
            DescribeGit();

            DescribeGitTfs();

            var tfsRemotes = _globals.Repository.ReadAllTfsRemotes();
            foreach (var remote in tfsRemotes)
            {
                DescribeTfsRemotes(remote);
            }

            return GitTfsExitCodes.OK;
        }

        private void DescribeGit()
        {
            DisplayReadabilityLineJump();

            _stdout.WriteLine(_globals.GitVersion);
        }

        private void DescribeGitTfs()
        {
            DisplayReadabilityLineJump();
            _stdout.WriteLine(_versionProvider.GetVersionString());
            _stdout.WriteLine(" " + _versionProvider.GetPathToGitTfsExecutable());

            DescribeGitRepository();
        }

        private void DescribeGitRepository()
        {
            var repoDescription = File.ReadAllLines(@".git\description");
            if (repoDescription.Length == 0 || !repoDescription[0].StartsWith("$/"))
                return;

            DisplayReadabilityLineJump();

            _stdout.WriteLine("cloned from tfs path:" + string.Join(Environment.NewLine, repoDescription));
        }

        private void DescribeTfsRemotes(IGitTfsRemote remote)
        {
            DisplayReadabilityLineJump();
            _stdout.WriteLine("remote tfs id: '{0}' {1} {2}", remote.Id, remote.TfsUrl, remote.TfsRepositoryPath);
            _stdout.WriteLine("               {0} - {1} @ {2}", remote.RemoteRef, remote.MaxCommitHash, remote.MaxChangesetId);
        }

        private void DisplayReadabilityLineJump()
        {
            _stdout.WriteLine();
        }
    }
}
<commit_msg>Try{} catch{} because that's needed ;)<commit_after>﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using NDesk.Options;
using StructureMap;
using Sep.Git.Tfs.Core;

namespace Sep.Git.Tfs.Commands
{
    [Pluggable("info")]
    [Description("info")]
    [RequiresValidGitRepository]
    public class Info : GitTfsCommand
    {
        readonly Globals _globals;
        readonly TextWriter _stdout;
        readonly IGitTfsVersionProvider _versionProvider;

        public Info(Globals globals, TextWriter stdout, IGitTfsVersionProvider versionProvider)
        {
            _globals = globals;
            _stdout = stdout;
            _versionProvider = versionProvider;
        }

        public OptionSet OptionSet { get { return _globals.OptionSet; } }

        public int Run()
        {
            DescribeGit();

            DescribeGitTfs();

            var tfsRemotes = _globals.Repository.ReadAllTfsRemotes();
            foreach (var remote in tfsRemotes)
            {
                DescribeTfsRemotes(remote);
            }

            return GitTfsExitCodes.OK;
        }

        private void DescribeGit()
        {
            DisplayReadabilityLineJump();

            _stdout.WriteLine(_globals.GitVersion);
        }

        private void DescribeGitTfs()
        {
            DisplayReadabilityLineJump();
            _stdout.WriteLine(_versionProvider.GetVersionString());
            _stdout.WriteLine(" " + _versionProvider.GetPathToGitTfsExecutable());

            DescribeGitRepository();
        }

        private void DescribeGitRepository()
        {
            try
            {
                var repoDescription = File.ReadAllLines(@".git\description");
                if (repoDescription.Length == 0 || !repoDescription[0].StartsWith("$/"))
                    return;

                DisplayReadabilityLineJump();

                _stdout.WriteLine("cloned from tfs path:" + string.Join(Environment.NewLine, repoDescription));
            }
            catch (Exception)
            {
                Trace.WriteLine("warning: unable to read the repository description!");
            }
        }

        private void DescribeTfsRemotes(IGitTfsRemote remote)
        {
            DisplayReadabilityLineJump();
            _stdout.WriteLine("remote tfs id: '{0}' {1} {2}", remote.Id, remote.TfsUrl, remote.TfsRepositoryPath);
            _stdout.WriteLine("               {0} - {1} @ {2}", remote.RemoteRef, remote.MaxCommitHash, remote.MaxChangesetId);
        }

        private void DisplayReadabilityLineJump()
        {
            _stdout.WriteLine();
        }
    }
}

{'fraction_non_alphanumeric': 0.09417571569595262, 'fraction_numerical': 0.0031589338598223098, 'mean_word_length': 2.0299043062200957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2095380', 'n_tokens_mistral': 1368, 'n_tokens_neox': 1321, 'n_words': 259}