Beispiel #1
0
        public void testBuildOneFile_FinishWriteCommit()
        {
            string        path         = "a-File-path";
            var           mode         = FileMode.RegularFile;
            long          lastModified = 1218123387057L;
            int           Length       = 1342;
            DirCacheEntry entOrig;

            DirCache        dc = DirCache.Lock(db);
            DirCacheBuilder b  = dc.builder();

            Assert.IsNotNull(b);

            entOrig = new DirCacheEntry(path);
            entOrig.setFileMode(mode);
            entOrig.setLastModified(lastModified);
            entOrig.setLength(Length);

            Assert.AreNotSame(path, entOrig.getPathString());
            Assert.AreEqual(path, entOrig.getPathString());
            Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId());
            Assert.AreEqual(mode.Bits, entOrig.getRawMode());
            Assert.AreEqual(0, entOrig.getStage());
            Assert.AreEqual(lastModified, entOrig.getLastModified());
            Assert.AreEqual(Length, entOrig.getLength());
            Assert.IsFalse(entOrig.isAssumeValid());
            b.add(entOrig);

            b.finish();
            Assert.AreEqual(1, dc.getEntryCount());
            Assert.AreSame(entOrig, dc.getEntry(0));

            dc.write();
            Assert.IsTrue(dc.commit());

            dc = DirCache.read(db);
            Assert.AreEqual(1, dc.getEntryCount());

            DirCacheEntry entRead = dc.getEntry(0);

            Assert.AreNotSame(entOrig, entRead);
            Assert.AreEqual(path, entRead.getPathString());
            Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId());
            Assert.AreEqual(mode.Bits, entOrig.getRawMode());
            Assert.AreEqual(0, entOrig.getStage());
            Assert.AreEqual(lastModified, entOrig.getLastModified());
            Assert.AreEqual(Length, entOrig.getLength());
            Assert.IsFalse(entOrig.isAssumeValid());
        }
        private static void AssertAreEqual(CGitIndexRecord c, DirCacheEntry j)
        {
            Assert.IsNotNull(c);
            Assert.IsNotNull(j);

            Assert.AreEqual(c.Path, j.getPathString());
            Assert.AreEqual(c.Id, j.getObjectId());
            Assert.AreEqual(c.Mode, j.getRawMode());
            Assert.AreEqual(c.Stage, j.getStage());
        }
Beispiel #3
0
        public void testSetFileMode()
        {
            DirCacheEntry e = new DirCacheEntry("a");

            Assert.AreEqual(0, e.getRawMode());

            e.setFileMode(FileMode.RegularFile);
            Assert.AreSame(FileMode.RegularFile, e.getFileMode());
            Assert.AreEqual(FileMode.RegularFile.Bits, e.getRawMode());

            e.setFileMode(FileMode.ExecutableFile);
            Assert.AreSame(FileMode.ExecutableFile, e.getFileMode());
            Assert.AreEqual(FileMode.ExecutableFile.Bits, e.getRawMode());

            e.setFileMode(FileMode.Symlink);
            Assert.AreSame(FileMode.Symlink, e.getFileMode());
            Assert.AreEqual(FileMode.Symlink.Bits, e.getRawMode());

            e.setFileMode(FileMode.GitLink);
            Assert.AreSame(FileMode.GitLink, e.getFileMode());
            Assert.AreEqual(FileMode.GitLink.Bits, e.getRawMode());

            try
            {
                e.setFileMode(FileMode.Missing);
                Assert.Fail("incorrectly accepted FileMode.MISSING");
            }
            catch (ArgumentException err)
            {
                Assert.AreEqual("Invalid mode 0 for path a", err.Message);
            }

            try
            {
                e.setFileMode(FileMode.Tree);
                Assert.Fail("incorrectly accepted FileMode.TREE");
            }
            catch (ArgumentException err)
            {
                Assert.AreEqual("Invalid mode " + FileMode.TYPE_TREE + " for path a", err.Message);
            }
        }
Beispiel #4
0
        public void testBuildRejectsUnsetFileMode()
        {
            DirCache        dc = DirCache.newInCore();
            DirCacheBuilder b  = dc.builder();

            Assert.IsNotNull(b);

            DirCacheEntry e = new DirCacheEntry("a");

            Assert.AreEqual(0, e.getRawMode());
            try
            {
                b.add(e);
            }
            catch (ArgumentException err)
            {
                Assert.AreEqual("FileMode not set for path a", err.Message);
            }
        }