public virtual void TestBuildOneFile_Commit_IndexChangedEvent()
        {
            // empty
            string   path = "a-file-path";
            FileMode mode = FileMode.REGULAR_FILE;
            // "old" date in 2008
            long                 lastModified = 1218123387057L;
            int                  length       = 1342;
            DirCacheEntry        entOrig;
            bool                 receivedEvent = false;
            DirCache             dc            = db.LockDirCache();
            IndexChangedListener listener      = new _IndexChangedListener_212();
            ListenerList         l             = db.Listeners;

            l.AddIndexChangedListener(listener);
            DirCacheBuilder b = dc.Builder();

            entOrig              = new DirCacheEntry(path);
            entOrig.FileMode     = mode;
            entOrig.LastModified = lastModified;
            entOrig.SetLength(length);
            b.Add(entOrig);
            try
            {
                b.Commit();
            }
            catch (_T123327308)
            {
                receivedEvent = true;
            }
            if (!receivedEvent)
            {
                NUnit.Framework.Assert.Fail("did not receive IndexChangedEvent");
            }
            // do the same again, as this doesn't change index compared to first
            // round we should get no event this time
            dc       = db.LockDirCache();
            listener = new _IndexChangedListener_239();
            l        = db.Listeners;
            l.AddIndexChangedListener(listener);
            b                    = dc.Builder();
            entOrig              = new DirCacheEntry(path);
            entOrig.FileMode     = mode;
            entOrig.LastModified = lastModified;
            entOrig.SetLength(length);
            b.Add(entOrig);
            try
            {
                b.Commit();
            }
            catch (_T123327308)
            {
                NUnit.Framework.Assert.Fail("unexpected IndexChangedEvent");
            }
        }
        /// <exception cref="NGit.Errors.CorruptObjectException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private void TestLongPath(int len)
        {
            string        longPath  = MakeLongPath(len);
            string        shortPath = "~~~ shorter-path";
            DirCacheEntry longEnt   = new DirCacheEntry(longPath);
            DirCacheEntry shortEnt  = new DirCacheEntry(shortPath);

            longEnt.FileMode  = FileMode.REGULAR_FILE;
            shortEnt.FileMode = FileMode.REGULAR_FILE;
            NUnit.Framework.Assert.AreEqual(longPath, longEnt.PathString);
            NUnit.Framework.Assert.AreEqual(shortPath, shortEnt.PathString);
            {
                DirCache dc1 = db.LockDirCache();
                {
                    DirCacheBuilder b = dc1.Builder();
                    b.Add(longEnt);
                    b.Add(shortEnt);
                    NUnit.Framework.Assert.IsTrue(b.Commit());
                }
                NUnit.Framework.Assert.AreEqual(2, dc1.GetEntryCount());
                NUnit.Framework.Assert.AreSame(longEnt, dc1.GetEntry(0));
                NUnit.Framework.Assert.AreSame(shortEnt, dc1.GetEntry(1));
            }
            {
                DirCache dc2 = db.ReadDirCache();
                NUnit.Framework.Assert.AreEqual(2, dc2.GetEntryCount());
                NUnit.Framework.Assert.AreNotSame(longEnt, dc2.GetEntry(0));
                NUnit.Framework.Assert.AreEqual(longPath, dc2.GetEntry(0).PathString);
                NUnit.Framework.Assert.AreNotSame(shortEnt, dc2.GetEntry(1));
                NUnit.Framework.Assert.AreEqual(shortPath, dc2.GetEntry(1).PathString);
            }
        }
        public virtual void TestWriteReadTree()
        {
            DirCache dc = db.LockDirCache();
            string   A  = string.Format("a%2000s", "a");
            string   B  = string.Format("b%2000s", "b");

            string[]        paths = new string[] { A + ".", A + "." + B, A + "/" + B, A + "0" + B };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i]          = new DirCacheEntry(paths[i]);
                ents[i].FileMode = FileMode.REGULAR_FILE;
            }
            DirCacheBuilder b = dc.Builder();

            for (int i_1 = 0; i_1 < ents.Length; i_1++)
            {
                b.Add(ents[i_1]);
            }
            b.Commit();
            DirCache read = db.ReadDirCache();

            NUnit.Framework.Assert.AreEqual(paths.Length, read.GetEntryCount());
            NUnit.Framework.Assert.AreEqual(1, read.GetCacheTree(true).GetChildCount());
        }
Exemple #4
0
 public virtual void TestBuildOneFile_Commit()
 {
     string        path         = "a-file-path";
     FileMode      mode         = FileMode.REGULAR_FILE;
     long          lastModified = 1218123387057L;
     int           length       = 1342;
     DirCacheEntry entOrig;
     {
         DirCache        dc = db.LockDirCache();
         DirCacheBuilder b  = dc.Builder();
         NUnit.Framework.Assert.IsNotNull(b);
         entOrig              = new DirCacheEntry(path);
         entOrig.FileMode     = mode;
         entOrig.LastModified = lastModified;
         entOrig.SetLength(length);
         NUnit.Framework.Assert.AreNotSame(path, entOrig.PathString);
         NUnit.Framework.Assert.AreEqual(path, entOrig.PathString);
         NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entOrig.GetObjectId());
         NUnit.Framework.Assert.AreEqual(mode.GetBits(), entOrig.RawMode);
         NUnit.Framework.Assert.AreEqual(0, entOrig.Stage);
         NUnit.Framework.Assert.AreEqual(lastModified, entOrig.LastModified);
         NUnit.Framework.Assert.AreEqual(length, entOrig.Length);
         NUnit.Framework.Assert.IsFalse(entOrig.IsAssumeValid);
         b.Add(entOrig);
         NUnit.Framework.Assert.IsTrue(b.Commit());
         NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount());
         NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(0));
         NUnit.Framework.Assert.IsFalse(new FilePath(db.Directory, "index.lock").Exists());
     }
     {
         DirCache dc = db.ReadDirCache();
         NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount());
         DirCacheEntry entRead = dc.GetEntry(0);
         NUnit.Framework.Assert.AreNotSame(entOrig, entRead);
         NUnit.Framework.Assert.AreEqual(path, entRead.PathString);
         NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, entOrig.GetObjectId());
         NUnit.Framework.Assert.AreEqual(mode.GetBits(), entOrig.RawMode);
         NUnit.Framework.Assert.AreEqual(0, entOrig.Stage);
         NUnit.Framework.Assert.AreEqual(lastModified, entOrig.LastModified);
         NUnit.Framework.Assert.AreEqual(length, entOrig.Length);
         NUnit.Framework.Assert.IsFalse(entOrig.IsAssumeValid);
     }
 }
		/// <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();
				}
			}
		}
Exemple #6
0
        /// <summary>Execute this checkout</summary>
        /// <returns>
        /// <code>false</code> if this method could not delete all the files
        /// which should be deleted (e.g. because of of the files was
        /// locked). In this case
        /// <see cref="GetToBeDeleted()">GetToBeDeleted()</see>
        /// lists the files
        /// which should be tried to be deleted outside of this method.
        /// Although <code>false</code> is returned the checkout was
        /// successful and the working tree was updated for all other files.
        /// <code>true</code> is returned when no such problem occurred
        /// </returns>
        /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
        public virtual bool Checkout()
        {
            toBeDeleted.Clear();
            if (headCommitTree != null)
            {
                PreScanTwoTrees();
            }
            else
            {
                PrescanOneTree();
            }
            if (!conflicts.IsEmpty())
            {
                if (failOnConflict)
                {
                    dc.Unlock();
                    throw new NGit.Errors.CheckoutConflictException(Sharpen.Collections.ToArray(conflicts
                                                                                                , new string[conflicts.Count]));
                }
                else
                {
                    CleanUpConflicts();
                }
            }
            // update our index
            builder.Finish();
            FilePath file = null;
            string   last = string.Empty;

            // when deleting files process them in the opposite order as they have
            // been reported. This ensures the files are deleted before we delete
            // their parent folders
            for (int i = removed.Count - 1; i >= 0; i--)
            {
                string r = removed[i];
                file = new FilePath(repo.WorkTree, r);
                if (!file.Delete() && file.Exists())
                {
                    toBeDeleted.AddItem(r);
                }
                else
                {
                    if (!IsSamePrefix(r, last))
                    {
                        RemoveEmptyParents(file);
                    }
                    last = r;
                }
            }
            if (file != null)
            {
                RemoveEmptyParents(file);
            }
            foreach (string path in updated.Keys)
            {
                // ... create/overwrite this file ...
                file = new FilePath(repo.WorkTree, path);
                if (!file.GetParentFile().Mkdirs())
                {
                }
                // ignore
                DirCacheEntry entry = dc.GetEntry(path);
                // submodules are handled with separate operations
                if (FileMode.GITLINK.Equals(entry.RawMode))
                {
                    continue;
                }
                CheckoutEntry(repo, file, entry);
            }
            // commit the index builder - a new index is persisted
            if (!builder.Commit())
            {
                dc.Unlock();
                throw new IndexWriteException();
            }
            return(toBeDeleted.Count == 0);
        }