Example #1
0
 /// <summary>
 /// Returns all branches that track the given branch.
 /// </summary>
 /// <param name="branch"></param>
 /// <returns></returns>
 public static IEnumerable<Branch> GetBranchesThatTrack(Branch branch, ObservableCollection<Branch> branches)
 {
     return branches.Where(b => b.TrackedBranch == branch);
 }
Example #2
0
        /// <summary>
        /// Creates a new branch model.
        /// </summary>
        /// <returns></returns>
        public static Branch Create(RepositoryViewModel repositoryViewModel, LibGit2Sharp.Repository repo, LibGit2Sharp.Branch branch)
        {
            Branch newBranch = new Branch
            {
                CanonicalName = branch.CanonicalName,
                Name = branch.Name,
                IsRemote = branch.IsRemote,
                IsTracking = branch.IsTracking,
                TipHash = branch.Tip.Sha.ToString(),
                AheadBy = branch.AheadBy,
                BehindBy = branch.BehindBy,
                TrackedBranchName = branch.TrackedBranch != null ? branch.TrackedBranch.Name : null
            };

            newBranch.repositoryViewModel = repositoryViewModel;

            // Loop through the first N commits and let them know about me.
            foreach (LibGit2Sharp.Commit branchCommit in branch.Commits.Take(repositoryViewModel.CommitsPerPage))
            {
                Commit commit = repositoryViewModel.Commits.Where(c => c.Hash == branchCommit.Sha.ToString()).FirstOrDefault();

                if (commit != null)
                {
                    commit.Branches.Add(newBranch); // Let the commit know that I am one of her branches.

                    // Process commit DisplayTags (tags to display next to the commit description, in this case = branch Tips).
                    if (newBranch.TipHash == commit.Hash)
                    {
                        commit.DisplayTags.Add(branch.Name);
                        newBranch.Tip = commit;
                    }
                }
            }

            return newBranch;
        }