Ejemplo n.º 1
0
        public virtual void TestStringOfPearls_FilePath3()
        {
            RevCommit a = Commit(Tree(File("d/f", Blob("a"))));
            RevCommit b = Commit(Tree(File("d/f", Blob("a"))), a);
            RevCommit c = Commit(Tree(File("d/f", Blob("b"))), b);
            RevCommit d = Commit(Tree(File("d/f", Blob("b"))), c);
            RevCommit e = Commit(Tree(File("d/f", Blob("b"))), d);
            RevCommit f = Commit(Tree(File("d/f", Blob("b"))), e);
            RevCommit g = Commit(Tree(File("d/f", Blob("b"))), f);
            RevCommit h = Commit(Tree(File("d/f", Blob("b"))), g);
            RevCommit i = Commit(Tree(File("d/f", Blob("c"))), h);

            Filter("d/f");
            MarkStart(i);
            AssertCommit(i, rw.Next());
            NUnit.Framework.Assert.AreEqual(1, i.ParentCount);
            AssertCommit(c, i.GetParent(0));
            // h..d was skipped
            AssertCommit(c, rw.Next());
            NUnit.Framework.Assert.AreEqual(1, c.ParentCount);
            AssertCommit(a, c.GetParent(0));
            // b was skipped
            AssertCommit(a, rw.Next());
            NUnit.Framework.Assert.AreEqual(0, a.ParentCount);
            NUnit.Framework.Assert.IsNull(rw.Next());
        }
Ejemplo n.º 2
0
        public virtual void TestStringOfPearls_FilePath1()
        {
            RevCommit a = Commit(Tree(File("d/f", Blob("a"))));
            RevCommit b = Commit(Tree(File("d/f", Blob("a"))), a);
            RevCommit c = Commit(Tree(File("d/f", Blob("b"))), b);

            Filter("d/f");
            MarkStart(c);
            AssertCommit(c, rw.Next());
            NUnit.Framework.Assert.AreEqual(1, c.ParentCount);
            AssertCommit(a, c.GetParent(0));
            // b was skipped
            AssertCommit(a, rw.Next());
            NUnit.Framework.Assert.AreEqual(0, a.ParentCount);
            NUnit.Framework.Assert.IsNull(rw.Next());
        }
Ejemplo n.º 3
0
		public static MergeCommandResult CherryPick (NGit.Repository repo, RevCommit srcCommit)
		{
			RevCommit newHead = null;
			RevWalk revWalk = new RevWalk(repo);
			try
			{
				// get the head commit
				Ref headRef = repo.GetRef(Constants.HEAD);
				if (headRef == null)
				{
					throw new NoHeadException(JGitText.Get().commitOnRepoWithoutHEADCurrentlyNotSupported
						);
				}
				RevCommit headCommit = revWalk.ParseCommit(headRef.GetObjectId());
				
				// get the parent of the commit to cherry-pick
				if (srcCommit.ParentCount != 1)
				{
					throw new MultipleParentsNotAllowedException(JGitText.Get().canOnlyCherryPickCommitsWithOneParent
						);
				}
				RevCommit srcParent = srcCommit.GetParent(0);
				revWalk.ParseHeaders(srcParent);
				
				return MergeTrees (repo, srcParent, srcCommit, srcCommit.Name, true);
			}
			catch (IOException e)
			{
				throw new Exception ("Commit failed", e);
			}
			finally
			{
				revWalk.Release();
			}
		}
Ejemplo n.º 4
0
 /// <summary>Core validation to be performed on all stashed commits</summary>
 /// <param name="commit"></param>
 /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 private void ValidateStashedCommit(RevCommit commit)
 {
     NUnit.Framework.Assert.IsNotNull(commit);
     Ref stashRef = db.GetRef(Constants.R_STASH);
     NUnit.Framework.Assert.IsNotNull(stashRef);
     NUnit.Framework.Assert.AreEqual(commit, stashRef.GetObjectId());
     NUnit.Framework.Assert.IsNotNull(commit.GetAuthorIdent());
     NUnit.Framework.Assert.AreEqual(commit.GetAuthorIdent(), commit.GetCommitterIdent
         ());
     NUnit.Framework.Assert.AreEqual(2, commit.ParentCount);
     // Load parents
     RevWalk walk = new RevWalk(db);
     try
     {
         foreach (RevCommit parent in commit.Parents)
         {
             walk.ParseBody(parent);
         }
     }
     finally
     {
         walk.Release();
     }
     NUnit.Framework.Assert.AreEqual(1, commit.GetParent(1).ParentCount);
     NUnit.Framework.Assert.AreEqual(head, commit.GetParent(1).GetParent(0));
     NUnit.Framework.Assert.IsFalse(commit.Tree.Equals(head.Tree), "Head tree matches stashed commit tree"
         );
     NUnit.Framework.Assert.AreEqual(head, commit.GetParent(0));
     NUnit.Framework.Assert.IsFalse(commit.GetFullMessage().Equals(commit.GetParent(1)
         .GetFullMessage()));
 }
Ejemplo n.º 5
0
 /// <exception cref="System.IO.IOException"></exception>
 private IList<DiffEntry> DiffWorkingAgainstHead(RevCommit commit)
 {
     TreeWalk walk = CreateTreeWalk();
     try
     {
         walk.AddTree(commit.GetParent(0).Tree);
         walk.AddTree(commit.Tree);
         return DiffEntry.Scan(walk);
     }
     finally
     {
         walk.Release();
     }
 }