Пример #1
0
        public virtual void TestTwoLevelSubtree_FilterPath()
        {
            DirCache dc   = DirCache.NewInCore();
            FileMode mode = FileMode.REGULAR_FILE;

            string[]        paths = new string[] { "a.", "a/b", "a/c/e", "a/c/f", "a/d", "a0b" };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i]          = new DirCacheEntry(paths[i]);
                ents[i].FileMode = mode;
            }
            DirCacheBuilder b = dc.Builder();

            for (int i_1 = 0; i_1 < ents.Length; i_1++)
            {
                b.Add(ents[i_1]);
            }
            b.Finish();
            TreeWalk tw = new TreeWalk(db);

            for (int victimIdx = 0; victimIdx < paths.Length; victimIdx++)
            {
                tw.Reset();
                tw.AddTree(new DirCacheIterator(dc));
                tw.Filter = PathFilterGroup.CreateFromStrings(Collections.Singleton(paths[victimIdx
                                                                                    ]));
                tw.Recursive = tw.Filter.ShouldBeRecursive();
                NUnit.Framework.Assert.IsTrue(tw.Next());
                DirCacheIterator c = tw.GetTree <DirCacheIterator>(0);
                NUnit.Framework.Assert.IsNotNull(c);
                NUnit.Framework.Assert.AreEqual(victimIdx, c.ptr);
                NUnit.Framework.Assert.AreSame(ents[victimIdx], c.GetDirCacheEntry());
                NUnit.Framework.Assert.AreEqual(paths[victimIdx], tw.PathString);
                NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0));
                NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0));
                NUnit.Framework.Assert.IsFalse(tw.Next());
            }
        }
Пример #2
0
        public virtual void TestSingleSubtree_Recursive()
        {
            DirCache dc   = DirCache.NewInCore();
            FileMode mode = FileMode.REGULAR_FILE;

            string[]        paths = new string[] { "a.", "a/b", "a/c", "a/d", "a0b" };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i]          = new DirCacheEntry(paths[i]);
                ents[i].FileMode = mode;
            }
            DirCacheBuilder b = dc.Builder();

            for (int i_1 = 0; i_1 < ents.Length; i_1++)
            {
                b.Add(ents[i_1]);
            }
            b.Finish();
            DirCacheIterator i_2 = new DirCacheIterator(dc);
            TreeWalk         tw  = new TreeWalk(db);

            tw.AddTree(i_2);
            tw.Recursive = true;
            int pathIdx = 0;

            while (tw.Next())
            {
                DirCacheIterator c = tw.GetTree <DirCacheIterator>(0);
                NUnit.Framework.Assert.IsNotNull(c);
                NUnit.Framework.Assert.AreEqual(pathIdx, c.ptr);
                NUnit.Framework.Assert.AreSame(ents[pathIdx], c.GetDirCacheEntry());
                NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString);
                NUnit.Framework.Assert.AreEqual(mode.GetBits(), tw.GetRawMode(0));
                NUnit.Framework.Assert.AreSame(mode, tw.GetFileMode(0));
                pathIdx++;
            }
            NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx);
        }
Пример #3
0
        public virtual void TestFindSingleFile()
        {
            string          path = "a-file-path";
            DirCache        dc   = db.ReadDirCache();
            DirCacheBuilder b    = dc.Builder();

            NUnit.Framework.Assert.IsNotNull(b);
            DirCacheEntry entOrig = new DirCacheEntry(path);

            entOrig.FileMode = FileMode.REGULAR_FILE;
            NUnit.Framework.Assert.AreNotSame(path, entOrig.PathString);
            NUnit.Framework.Assert.AreEqual(path, entOrig.PathString);
            b.Add(entOrig);
            b.Finish();
            NUnit.Framework.Assert.AreEqual(1, dc.GetEntryCount());
            NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(0));
            NUnit.Framework.Assert.AreEqual(0, dc.FindEntry(path));
            NUnit.Framework.Assert.AreEqual(-1, dc.FindEntry("@@-before"));
            NUnit.Framework.Assert.AreEqual(0, Real(dc.FindEntry("@@-before")));
            NUnit.Framework.Assert.AreEqual(-2, dc.FindEntry("a-zoo"));
            NUnit.Framework.Assert.AreEqual(1, Real(dc.FindEntry("a-zoo")));
            NUnit.Framework.Assert.AreSame(entOrig, dc.GetEntry(path));
        }
Пример #4
0
        public virtual void TestNoSubtree_WithTreeWalk()
        {
            DirCache dc = DirCache.NewInCore();

            string[]        paths = new string[] { "a.", "a0b" };
            FileMode[]      modes = new FileMode[] { FileMode.EXECUTABLE_FILE, FileMode.GITLINK };
            DirCacheEntry[] ents  = new DirCacheEntry[paths.Length];
            for (int i = 0; i < paths.Length; i++)
            {
                ents[i]          = new DirCacheEntry(paths[i]);
                ents[i].FileMode = modes[i];
            }
            DirCacheBuilder b = dc.Builder();

            for (int i_1 = 0; i_1 < ents.Length; i_1++)
            {
                b.Add(ents[i_1]);
            }
            b.Finish();
            DirCacheIterator i_2 = new DirCacheIterator(dc);
            TreeWalk         tw  = new TreeWalk(db);

            tw.AddTree(i_2);
            int pathIdx = 0;

            while (tw.Next())
            {
                NUnit.Framework.Assert.AreSame(i_2, tw.GetTree <DirCacheIterator>(0));
                NUnit.Framework.Assert.AreEqual(pathIdx, i_2.ptr);
                NUnit.Framework.Assert.AreSame(ents[pathIdx], i_2.GetDirCacheEntry());
                NUnit.Framework.Assert.AreEqual(paths[pathIdx], tw.PathString);
                NUnit.Framework.Assert.AreEqual(modes[pathIdx].GetBits(), tw.GetRawMode(0));
                NUnit.Framework.Assert.AreSame(modes[pathIdx], tw.GetFileMode(0));
                pathIdx++;
            }
            NUnit.Framework.Assert.AreEqual(paths.Length, pathIdx);
        }
Пример #5
0
        public virtual void TestBuildThenClear()
        {
            DirCache dc = db.ReadDirCache();

            string[]        paths = new string[] { "a.", "a.b", "a/b", "a0b" };
            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.Finish();
            NUnit.Framework.Assert.IsFalse(dc.HasUnmergedPaths());
            NUnit.Framework.Assert.AreEqual(paths.Length, dc.GetEntryCount());
            dc.Clear();
            NUnit.Framework.Assert.AreEqual(0, dc.GetEntryCount());
            NUnit.Framework.Assert.IsFalse(dc.HasUnmergedPaths());
        }
Пример #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);
        }
Пример #7
0
 /// <exception cref="System.IO.IOException"></exception>
 protected internal override bool MergeImpl()
 {
     tw.AddTree(MergeBase());
     tw.AddTree(sourceTrees[0]);
     tw.AddTree(sourceTrees[1]);
     bool hasConflict = false;
     builder = cache.Builder();
     while (tw.Next())
     {
         int modeO = tw.GetRawMode(T_OURS);
         int modeT = tw.GetRawMode(T_THEIRS);
         if (modeO == modeT && tw.IdEqual(T_OURS, T_THEIRS))
         {
             Add(T_OURS, DirCacheEntry.STAGE_0);
             continue;
         }
         int modeB = tw.GetRawMode(T_BASE);
         if (modeB == modeO && tw.IdEqual(T_BASE, T_OURS))
         {
             Add(T_THEIRS, DirCacheEntry.STAGE_0);
         }
         else
         {
             if (modeB == modeT && tw.IdEqual(T_BASE, T_THEIRS))
             {
                 Add(T_OURS, DirCacheEntry.STAGE_0);
             }
             else
             {
                 if (NonTree(modeB))
                 {
                     Add(T_BASE, DirCacheEntry.STAGE_1);
                     hasConflict = true;
                 }
                 if (NonTree(modeO))
                 {
                     Add(T_OURS, DirCacheEntry.STAGE_2);
                     hasConflict = true;
                 }
                 if (NonTree(modeT))
                 {
                     Add(T_THEIRS, DirCacheEntry.STAGE_3);
                     hasConflict = true;
                 }
                 if (tw.IsSubtree)
                 {
                     tw.EnterSubtree();
                 }
             }
         }
     }
     builder.Finish();
     builder = null;
     if (hasConflict)
     {
         return false;
     }
     try
     {
         ObjectInserter odi = GetObjectInserter();
         resultTree = cache.WriteTree(odi);
         odi.Flush();
         return true;
     }
     catch (UnmergedPathException)
     {
         resultTree = null;
         return false;
     }
 }