Esempio n. 1
0
 public static BranchReference ToBranchReference(this LibGit2Sharp.Branch branch)
 {
     return(new BranchReference
     {
         Name = branch.Name,
         IsRemote = branch.IsRemote,
         IsHead = branch.IsCurrentRepositoryHead
     });
 }
Esempio n. 2
0
        private void LinkBranchToRemote(LibGit2Sharp.Branch branch)
        {
            var remote = repo.Network.Remotes["origin"];

            if (remote != null)
            {
                repo.Branches.Update(branch, b => b.Remote = remote.Name, b => b.UpstreamBranch = branch.CanonicalName);
            }
        }
        public BranchModel(LibGit2Sharp.Branch branch, ISimpleRepositoryModel repo)
        {
            Extensions.Guard.ArgumentNotNull(branch, nameof(branch));
            Extensions.Guard.ArgumentNotNull(repo, nameof(repo));

            Name       = DisplayName = branch.FriendlyName;
            Repository = branch.IsRemote ? new SimpleRepositoryModel(branch.Remote.Url) : repo;
            IsTracking = branch.IsTracking;
            Id         = String.Format(CultureInfo.InvariantCulture, "{0}/{1}", Repository.Owner, Name);
        }
Esempio n. 4
0
        public BranchModel(LibGit2Sharp.Branch branch, IRepositoryModel repo)
        {
            Extensions.Guard.ArgumentNotNull(branch, nameof(branch));
            Extensions.Guard.ArgumentNotNull(repo, nameof(repo));
            Name = DisplayName = branch.FriendlyName;
#pragma warning disable 0618 // TODO: Replace `Branch.Remote` with `Repository.Network.Remotes[branch.RemoteName]`.
            Repository = branch.IsRemote ? new LocalRepositoryModel(branch.Remote.Url) : repo;
#pragma warning restore 0618
            IsTracking = branch.IsTracking;
            Id         = String.Format(CultureInfo.InvariantCulture, "{0}/{1}", Repository.Owner, Name);
        }
Esempio n. 5
0
        public void Checkout(String name, LibGit2Sharp.Signature sig)
        {
            if (commitRepo.HasUncommittedChanges())
            {
                throw new InvalidOperationException("Cannot change branches with uncommitted changes. Please commit first and try again.");
            }

            var localRef = localRefRoot + name;

            LibGit2Sharp.Branch branch = repo.Branches[localRef];

            var remoteRef    = remoteRefRoot + name;
            var remoteBranch = repo.Branches[remoteRef];

            //Found a local branch, use it
            if (branch != null)
            {
                LibGit2Sharp.Commands.Checkout(repo, branch);
                if (remoteBranch != null && remoteBranch.Tip != repo.Head.Tip)
                {
                    repo.Merge(remoteBranch, sig, new LibGit2Sharp.MergeOptions());
                }
                return; //Was able to do a simple checkout to a local branch
            }

            //No local branch, use the remote branch and create a new local branch
            if (remoteBranch != null)
            {
                //Since we already know there is not a local branch, create it
                var localBranch = repo.Branches.Add(name, remoteBranch.Tip);
                LinkBranchToRemote(localBranch);
                LibGit2Sharp.Commands.Checkout(repo, localBranch);
                return; //Was able to find branch in remote repo. Checkout to it
            }

            throw new InvalidOperationException($"Cannot find branch {name} in current local or remote branches. Do you need to create the branch or pull in updates?");
        }
Esempio n. 6
0
        public Branch(string friendlyName, string canonicalName, bool isRemote, bool isCurrentRepositoryHead, LibGit2Sharp.Branch trackedBranch)
        {
            Name          = friendlyName;
            CanonicalName = canonicalName;
            IsRemote      = isRemote;
            IsCurrentHead = isCurrentRepositoryHead;

            if (trackedBranch != null && trackedBranch.Tip != null)   // make sure the online repo exists
            {
                TrackingName = trackedBranch.FriendlyName;
            }
        }
Esempio n. 7
0
 public Branch(LibGit2Sharp.Branch branch)
     : this(branch.FriendlyName, branch.CanonicalName, branch.IsRemote, branch.IsCurrentRepositoryHead, branch.TrackedBranch)
 {
 }
Esempio n. 8
0
 public Branch(LibGit2Sharp.Branch original)
 {
     Commits = original.Commits.Select(c => new Commit(c));
     Name    = original.Name;
     Remote  = original.IsRemote;
 }
Esempio n. 9
0
 internal Branch(LibGit2Sharp.Branch branch)
 {
     innerBranch = branch;
 }
Esempio n. 10
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);
        }