Ejemplo n.º 1
0
        public virtual void DeleteMergedBranch_historyNotPruned()
        {
            RevCommit parent = tr.Commit().Create();
            RevCommit b1Tip  = tr.Branch("b1").Commit().Parent(parent).Add("x", "x").Create();
            RevCommit b2Tip  = tr.Branch("b2").Commit().Parent(parent).Add("y", "y").Create();
            // merge b1Tip and b2Tip and update refs/heads/b1 to the merge commit
            Merger merger = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger(repo
                                                                                            ));

            merger.Merge(b1Tip, b2Tip);
            NGit.Junit.CommitBuilder cb = tr.Commit();
            cb.Parent(b1Tip).Parent(b2Tip);
            cb.SetTopLevelTree(merger.GetResultTreeId());
            RevCommit mergeCommit = cb.Create();
            RefUpdate u           = repo.UpdateRef("refs/heads/b1");

            u.SetNewObjectId(mergeCommit);
            u.Update();
            RefUpdate update = repo.UpdateRef("refs/heads/b2");

            update.SetForceUpdate(true);
            update.Delete();
            gc.SetExpireAgeMillis(0);
            gc.Prune(Collections.EmptySet <ObjectId>());
            NUnit.Framework.Assert.IsTrue(repo.HasObject(b2Tip));
        }
        public virtual void TestMultiRename()
        {
            string    contents = "A";
            RevCommit a        = Commit(Tree(File("a", Blob(contents))));

            // rename a to b
            NGit.Junit.CommitBuilder commitBuilder = CommitBuilder().Parent(a).Add("b", Blob
                                                                                       (contents)).Rm("a");
            RevCommit renameCommit1 = commitBuilder.Create();

            // rename b to c
            commitBuilder = CommitBuilder().Parent(renameCommit1).Add("c", Blob(contents)).Rm
                                ("b");
            RevCommit renameCommit2 = commitBuilder.Create();

            // rename c to a
            commitBuilder = CommitBuilder().Parent(renameCommit2).Add("a", Blob(contents)).Rm
                                ("c");
            RevCommit renameCommit3 = commitBuilder.Create();

            Follow("a");
            MarkStart(renameCommit3);
            AssertCommit(renameCommit3, rw.Next());
            AssertCommit(renameCommit2, rw.Next());
            AssertCommit(renameCommit1, rw.Next());
            AssertCommit(a, rw.Next());
            NUnit.Framework.Assert.IsNull(rw.Next());
            AssertRenames("c->a", "b->c", "a->b");
        }
Ejemplo n.º 3
0
        /// <exception cref="System.Exception"></exception>
        internal CommitBuilder(TestRepository _enclosing, CommitBuilder
                               prior)
        {
            this._enclosing = _enclosing;
            this.branch     = prior.branch;
            DirCacheBuilder b = this.tree.Builder();

            for (int i = 0; i < prior.tree.GetEntryCount(); i++)
            {
                b.Add(prior.tree.GetEntry(i));
            }
            b.Finish();
            this.parents.AddItem(prior.Create());
        }
        public virtual void TestSingleRename()
        {
            RevCommit a = Commit(Tree(File("a", Blob("A"))));

            // rename a to b
            NGit.Junit.CommitBuilder commitBuilder = CommitBuilder().Parent(a).Add("b", Blob
                                                                                       ("A")).Rm("a");
            RevCommit renameCommit = commitBuilder.Create();

            Follow("b");
            MarkStart(renameCommit);
            AssertCommit(renameCommit, rw.Next());
            AssertCommit(a, rw.Next());
            NUnit.Framework.Assert.IsNull(rw.Next());
            AssertRenames("a->b");
        }
Ejemplo n.º 5
0
        /// <summary>Create a chain of commits of given depth.</summary>
        /// <remarks>
        /// Create a chain of commits of given depth.
        /// <p>
        /// Each commit contains one file named "a" containing the index of the
        /// commit in the chain as its content. The created commit chain is
        /// referenced from any ref.
        /// <p>
        /// A chain of depth = N will create 3*N objects in Gits object database. For
        /// each depth level three objects are created: the commit object, the
        /// top-level tree object and a blob for the content of the file "a".
        /// </remarks>
        /// <param name="depth">the depth of the commit chain.</param>
        /// <returns>the commit that is the tip of the commit chain</returns>
        /// <exception cref="System.Exception">System.Exception</exception>
        private RevCommit CommitChain(int depth)
        {
            if (depth <= 0)
            {
                throw new ArgumentException("Chain depth must be > 0");
            }
            NGit.Junit.CommitBuilder cb = tr.Commit();
            RevCommit tip;

            do
            {
                --depth;
                tip = cb.Add("a", string.Empty + depth).Message(string.Empty + depth).Create();
                cb  = cb.Child();
            }while (depth > 0);
            return(tip);
        }
Ejemplo n.º 6
0
			/// <exception cref="System.Exception"></exception>
			internal CommitBuilder(TestRepository _enclosing, CommitBuilder
				 prior)
			{
				this._enclosing = _enclosing;
				this.branch = prior.branch;
				DirCacheBuilder b = this.tree.Builder();
				for (int i = 0; i < prior.tree.GetEntryCount(); i++)
				{
					b.Add(prior.tree.GetEntry(i));
				}
				b.Finish();
				this.parents.AddItem(prior.Create());
			}
Ejemplo n.º 7
0
			/// <summary>Forcefully update this branch to a particular commit.</summary>
			/// <remarks>Forcefully update this branch to a particular commit.</remarks>
			/// <param name="to">the commit to update to.</param>
			/// <returns>
			/// 
			/// <code>to</code>
			/// .
			/// </returns>
			/// <exception cref="System.Exception">System.Exception</exception>
			public virtual RevCommit Update(CommitBuilder to)
			{
				return this.Update(to.Create());
			}
Ejemplo n.º 8
0
 /// <summary>Forcefully update this branch to a particular commit.</summary>
 /// <remarks>Forcefully update this branch to a particular commit.</remarks>
 /// <param name="to">the commit to update to.</param>
 /// <returns>
 ///
 /// <code>to</code>
 /// .
 /// </returns>
 /// <exception cref="System.Exception">System.Exception</exception>
 public virtual RevCommit Update(CommitBuilder to)
 {
     return(this.Update(to.Create()));
 }