コード例 #1
0
        public virtual void TestDF_NoGap()
        {
            DirCache tree0 = db.ReadDirCache();
            DirCache tree1 = db.ReadDirCache();
            {
                DirCacheBuilder b0 = tree0.Builder();
                DirCacheBuilder b1 = tree1.Builder();
                b0.Add(CreateEntry("a", REGULAR_FILE));
                b0.Add(CreateEntry("a.b", EXECUTABLE_FILE));
                b1.Add(CreateEntry("a/b", REGULAR_FILE));
                b0.Add(CreateEntry("a0b", SYMLINK));
                b0.Finish();
                b1.Finish();
                NUnit.Framework.Assert.AreEqual(3, tree0.GetEntryCount());
                NUnit.Framework.Assert.AreEqual(1, tree1.GetEntryCount());
            }
            NameConflictTreeWalk tw = new NameConflictTreeWalk(db);

            tw.AddTree(new DirCacheIterator(tree0));
            tw.AddTree(new DirCacheIterator(tree1));
            AssertModes("a", REGULAR_FILE, TREE, tw);
            NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
            NUnit.Framework.Assert.IsTrue(tw.IsSubtree);
            tw.EnterSubtree();
            AssertModes("a/b", MISSING, REGULAR_FILE, tw);
            NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
            AssertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
            NUnit.Framework.Assert.IsFalse(tw.IsDirectoryFileConflict());
            AssertModes("a0b", SYMLINK, MISSING, tw);
            NUnit.Framework.Assert.IsFalse(tw.IsDirectoryFileConflict());
        }
コード例 #2
0
        public virtual void TestDF_DetectConflict()
        {
            DirCache tree0 = db.ReadDirCache();
            DirCache tree1 = db.ReadDirCache();
            {
                DirCacheBuilder b0 = tree0.Builder();
                DirCacheBuilder b1 = tree1.Builder();
                b0.Add(MakeEntry("0", REGULAR_FILE));
                b0.Add(MakeEntry("a", REGULAR_FILE));
                b1.Add(MakeEntry("0", REGULAR_FILE));
                b1.Add(MakeEntry("a.b", REGULAR_FILE));
                b1.Add(MakeEntry("a/b", REGULAR_FILE));
                b1.Add(MakeEntry("a/c/e", REGULAR_FILE));
                b0.Finish();
                b1.Finish();
                NUnit.Framework.Assert.AreEqual(2, tree0.GetEntryCount());
                NUnit.Framework.Assert.AreEqual(4, tree1.GetEntryCount());
            }
            NameConflictTreeWalk tw = new NameConflictTreeWalk(db);

            tw.AddTree(new DirCacheIterator(tree0));
            tw.AddTree(new DirCacheIterator(tree1));
            AssertModes("0", REGULAR_FILE, REGULAR_FILE, tw);
            NUnit.Framework.Assert.IsFalse(tw.IsDirectoryFileConflict());
            AssertModes("a", REGULAR_FILE, TREE, tw);
            NUnit.Framework.Assert.IsTrue(tw.IsSubtree);
            NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
            tw.EnterSubtree();
            AssertModes("a/b", MISSING, REGULAR_FILE, tw);
            NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
            AssertModes("a/c", MISSING, TREE, tw);
            NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
            tw.EnterSubtree();
            AssertModes("a/c/e", MISSING, REGULAR_FILE, tw);
            NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
            AssertModes("a.b", MISSING, REGULAR_FILE, tw);
            NUnit.Framework.Assert.IsFalse(tw.IsDirectoryFileConflict());
        }
コード例 #3
0
		/// <exception cref="System.IO.IOException"></exception>
		protected internal override bool MergeImpl()
		{
			bool implicitDirCache = false;
			if (dircache == null)
			{
				dircache = GetRepository().LockDirCache();
				implicitDirCache = true;
			}
			try
			{
				builder = dircache.Builder();
				DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder);
				tw = new NameConflictTreeWalk(db);
				tw.AddTree(MergeBase());
				tw.AddTree(sourceTrees[0]);
				tw.AddTree(sourceTrees[1]);
				tw.AddTree(buildIt);
				if (workingTreeIterator != null)
				{
					tw.AddTree(workingTreeIterator);
				}
				while (tw.Next())
				{
					if (!ProcessEntry(tw.GetTree<CanonicalTreeParser>(T_BASE), tw.GetTree<CanonicalTreeParser
						>(T_OURS), tw.GetTree<CanonicalTreeParser>(T_THEIRS), tw.GetTree<DirCacheBuildIterator
						>(T_INDEX), (workingTreeIterator == null) ? null : tw.GetTree<WorkingTreeIterator
						>(T_FILE)))
					{
						CleanUp();
						return false;
					}
					if (tw.IsSubtree && enterSubtree)
					{
						tw.EnterSubtree();
					}
				}
				if (!inCore)
				{
					// All content-merges are successfully done. If we can now write the
					// new index we are on quite safe ground. Even if the checkout of
					// files coming from "theirs" fails the user can work around such
					// failures by checking out the index again.
					if (!builder.Commit())
					{
						CleanUp();
						throw new IndexWriteException();
					}
					builder = null;
					// No problem found. The only thing left to be done is to checkout
					// all files from "theirs" which have been selected to go into the
					// new index.
					Checkout();
				}
				else
				{
					builder.Finish();
					builder = null;
				}
				if (GetUnmergedPaths().IsEmpty())
				{
					resultTree = dircache.WriteTree(oi);
					return true;
				}
				else
				{
					resultTree = null;
					return false;
				}
			}
			finally
			{
				if (implicitDirCache)
				{
					dircache.Unlock();
				}
			}
		}
コード例 #4
0
ファイル: DirCacheCheckout.cs プロジェクト: stinos/ngit
 /// <summary>Scan head, index and merge tree.</summary>
 /// <remarks>
 /// Scan head, index and merge tree. Used during normal checkout or merge
 /// operations.
 /// </remarks>
 /// <exception cref="NGit.Errors.CorruptObjectException">NGit.Errors.CorruptObjectException
 /// 	</exception>
 /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 public virtual void PreScanTwoTrees()
 {
     removed.Clear();
     updated.Clear();
     conflicts.Clear();
     walk = new NameConflictTreeWalk(repo);
     builder = dc.Builder();
     AddTree(walk, headCommitTree);
     AddTree(walk, mergeCommitTree);
     walk.AddTree(new DirCacheBuildIterator(builder));
     walk.AddTree(workingTree);
     while (walk.Next())
     {
         ProcessEntry(walk.GetTree<CanonicalTreeParser>(0), walk.GetTree<CanonicalTreeParser
             >(1), walk.GetTree<DirCacheBuildIterator>(2), walk.GetTree<WorkingTreeIterator>(
             3));
         if (walk.IsSubtree)
         {
             walk.EnterSubtree();
         }
     }
 }
コード例 #5
0
		public virtual void TestDF_NoGap()
		{
			DirCache tree0 = db.ReadDirCache();
			DirCache tree1 = db.ReadDirCache();
			{
				DirCacheBuilder b0 = tree0.Builder();
				DirCacheBuilder b1 = tree1.Builder();
				b0.Add(MakeEntry("a", REGULAR_FILE));
				b0.Add(MakeEntry("a.b", EXECUTABLE_FILE));
				b1.Add(MakeEntry("a/b", REGULAR_FILE));
				b0.Add(MakeEntry("a0b", SYMLINK));
				b0.Finish();
				b1.Finish();
				NUnit.Framework.Assert.AreEqual(3, tree0.GetEntryCount());
				NUnit.Framework.Assert.AreEqual(1, tree1.GetEntryCount());
			}
			NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
			tw.AddTree(new DirCacheIterator(tree0));
			tw.AddTree(new DirCacheIterator(tree1));
			AssertModes("a", REGULAR_FILE, TREE, tw);
			NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
			NUnit.Framework.Assert.IsTrue(tw.IsSubtree);
			tw.EnterSubtree();
			AssertModes("a/b", MISSING, REGULAR_FILE, tw);
			NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
			AssertModes("a.b", EXECUTABLE_FILE, MISSING, tw);
			NUnit.Framework.Assert.IsFalse(tw.IsDirectoryFileConflict());
			AssertModes("a0b", SYMLINK, MISSING, tw);
			NUnit.Framework.Assert.IsFalse(tw.IsDirectoryFileConflict());
		}
コード例 #6
0
		public virtual void TestDF_DetectConflict()
		{
			DirCache tree0 = db.ReadDirCache();
			DirCache tree1 = db.ReadDirCache();
			{
				DirCacheBuilder b0 = tree0.Builder();
				DirCacheBuilder b1 = tree1.Builder();
				b0.Add(CreateEntry("0", REGULAR_FILE));
				b0.Add(CreateEntry("a", REGULAR_FILE));
				b1.Add(CreateEntry("0", REGULAR_FILE));
				b1.Add(CreateEntry("a.b", REGULAR_FILE));
				b1.Add(CreateEntry("a/b", REGULAR_FILE));
				b1.Add(CreateEntry("a/c/e", REGULAR_FILE));
				b0.Finish();
				b1.Finish();
				NUnit.Framework.Assert.AreEqual(2, tree0.GetEntryCount());
				NUnit.Framework.Assert.AreEqual(4, tree1.GetEntryCount());
			}
			NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
			tw.AddTree(new DirCacheIterator(tree0));
			tw.AddTree(new DirCacheIterator(tree1));
			AssertModes("0", REGULAR_FILE, REGULAR_FILE, tw);
			NUnit.Framework.Assert.IsFalse(tw.IsDirectoryFileConflict());
			AssertModes("a", REGULAR_FILE, TREE, tw);
			NUnit.Framework.Assert.IsTrue(tw.IsSubtree);
			NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
			tw.EnterSubtree();
			AssertModes("a/b", MISSING, REGULAR_FILE, tw);
			NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
			AssertModes("a/c", MISSING, TREE, tw);
			NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
			tw.EnterSubtree();
			AssertModes("a/c/e", MISSING, REGULAR_FILE, tw);
			NUnit.Framework.Assert.IsTrue(tw.IsDirectoryFileConflict());
			AssertModes("a.b", MISSING, REGULAR_FILE, tw);
			NUnit.Framework.Assert.IsFalse(tw.IsDirectoryFileConflict());
		}