Пример #1
0
        private static CommitChangeStats GetChangeStats(string cmd, string projectDir)
        {
            if (!SoftwareCoUtil.IsGitProject(projectDir))
            {
                return(new CommitChangeStats());
            }
            CommitChangeStats stats = new CommitChangeStats();

            /**
             * example:
             * -mbp-2:swdc-vscode xavierluiz$ git diff --stat
             *  lib/KpmProviderManager.ts | 22 ++++++++++++++++++++--
             *  1 file changed, 20 insertions(+), 2 deletions(-)
             *
             *  for multiple files it will look like this...
             *  7 files changed, 137 insertions(+), 55 deletions(-)
             */
            List <string> results = SoftwareCoUtil.GetCommandResultList(cmd, projectDir);

            if (results == null || results.Count == 0)
            {
                // something went wrong, but don't try to parse a null or undefined str
                return(stats);
            }

            // just look for the line with "insertions" and "deletions"
            return(AccumulateChangeStats(results));
        }
Пример #2
0
        public static CommitInfo GetLastCommitInfo(string projectDir, string email)
        {
            if (!SoftwareCoUtil.IsGitProject(projectDir))
            {
                return(new CommitInfo());
            }
            CommitInfo commitInfo = new CommitInfo();

            string authorArg = (email != null) ? " --author=" + email + " " : " ";
            string cmd       = "git log --pretty=%H,%s" + authorArg + "--max-count=1";

            List <string> results = SoftwareCoUtil.GetCommandResultList(cmd, projectDir);

            if (results != null && results.Count > 0)
            {
                string[] parts = results[0].Split(',');
                if (parts != null && parts.Length == 2)
                {
                    commitInfo.commitId = parts[0];
                    commitInfo.comment  = parts[1];
                    commitInfo.email    = email;
                }
            }

            return(commitInfo);
        }