public IEnumerable <Change> GetTreeChanges(string branch)
        {
            var gitBranch = _repository.Branches[branch];

            var gitCurrentCommit  = TryAndGetCurrentCommit(gitBranch);
            var gitPreviousCommit = TryAndGetPreviousCommit(gitBranch);

            List <Change> changes = new List <Change>();

            if (gitCurrentCommit != null && gitPreviousCommit != null)
            {
                TreeChanges tc = _repository.Diff.Compare <TreeChanges>(gitPreviousCommit.Tree, gitCurrentCommit.Tree);
                changes.AddRange(tc.Select(c => new Change
                {
                    Path   = c.Path,
                    Mode   = (GitMode)c.Mode,
                    Status = (GitChangeKind)c.Status
                }));
            }
            else
            {
                throw new Exception("Either the current or previous commits specified could not be found!");
            }

            return(changes);
        }
Ejemplo n.º 2
0
        public CommitDetail GetCommitDetails(string sha)
        {
            if (string.IsNullOrEmpty(sha))
            {
                throw new ArgumentNullException();
            }

            var commit = _repository.Lookup <LibGit2Sharp.Commit>(sha);

            if (commit == null)
            {
                throw new CommitNotFoundException(sha);
            }

            var commitParent = commit.Parents.Last();

            TreeChanges treeChanges = _repository.Diff.Compare <TreeChanges>(commitParent.Tree, commit.Tree);

            CommitDetail commitDetail = new CommitDetail(sha, commit.Message, commit.Author.Name, commit.Author.When.Date);

            commitDetail.Files.AddRange(treeChanges.Select(s => new CommitFile((int)s.Status, s.Path, Path.GetFileName(s.Path))));
            //commitDetail.Files.AddRange(treeChanges.Modified.Select(s => new CommitFile((int)s.Status, s.Path, Path.GetFileName(s.Path))));
            //commitDetail.Files.AddRange(treeChanges.Deleted.Select(s => new CommitFile((int)s.Status, s.Path, Path.GetFileName(s.Path))));

            return(commitDetail);
        }
Ejemplo n.º 3
0
        public CommitDetails GetDetails(string sha)
        {
            if (string.IsNullOrEmpty(sha))
            {
                throw new ArgumentNullException();
            }

            var           commit        = _repository.Lookup <LibGit2Sharp.Commit>(sha);
            CommitDetails commitDetails = new CommitDetails(sha, commit.Message, commit.Author.Name, commit.Author.When.Date);

            var commitParent = commit.Parents.LastOrDefault();

            if (commitParent != null)
            {
                TreeChanges treeChanges = _repository.Diff.Compare <TreeChanges>(commitParent.Tree, commit.Tree);
                commitDetails.Changes.AddRange(treeChanges.Select(s => new CommitChange(s.Status, s.Path, Path.GetFileName(s.Path))));
            }
            else
            {
                commitDetails.Changes.AddRange(commit.Tree.Select(s => new CommitChange(ChangeKind.Added, s.Path, Path.GetFileName(s.Name))));
            }

            return(commitDetails);
        }
 public static IEnumerable <string> FilterTreeChangesToPaths(TreeChanges changes)
 {
     return(changes.Select(x => x.Path));
 }