示例#1
0
        public static Branch CreateBranch(Repository repository, BranchData branchData)
        {
            Verify.Argument.IsNotNull(repository, "repository");
            Verify.Argument.IsNotNull(branchData, "branchData");
            Verify.Argument.IsFalse(branchData.IsRemote, "branchData", "Cannot create remote branch.");

            Revision revision;
            lock(repository.Revisions.SyncRoot)
            {
                revision = repository.Revisions.GetOrCreateRevision(branchData.SHA1);
            }
            var branch = new Branch(repository, branchData.Name, revision);
            if(branchData.IsCurrent) repository.Head.Pointer = branch;
            return branch;
        }
示例#2
0
        public static void UpdateBranch(Branch branch, BranchData branchData)
        {
            Verify.Argument.IsNotNull(branch, "branch");
            Verify.Argument.IsNotNull(branchData, "branchData");
            Verify.Argument.IsFalse(branchData.IsRemote, "branchData", "Cannot update remote branch.");

            var repo = branch.Repository;
            if(branch.Revision.Hash != branchData.SHA1)
            {
                lock(repo.Revisions.SyncRoot)
                {
                    branch.Pointer = repo.Revisions.GetOrCreateRevision(branchData.SHA1);
                }
            }
            if(branchData.IsCurrent)
            {
                repo.Head.Pointer = branch;
            }
        }