Exemplo n.º 1
0
        public void testParse_AddNoNewline()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testParse_AddNoNewline.patch");
            Assert.AreEqual(1, p.getFiles().Count);
            Assert.IsTrue(p.getErrors().Count == 0, GetAllErrorsFromPatch(p));

            FileHeader f = p.getFiles()[0];

            Assert.AreEqual("a", f.NewName);
            Assert.AreEqual(256, f.StartOffset);

            Assert.AreEqual("f2ad6c7", f.getOldId().name());
            Assert.AreEqual("c59d9b6", f.getNewId().name());
            Assert.AreEqual(FileHeader.PatchTypeEnum.UNIFIED, f.getPatchType());
            Assert.AreEqual(FileMode.RegularFile, f.GetOldMode());
            Assert.AreEqual(FileMode.RegularFile, f.NewMode);
            Assert.AreEqual(1, f.Hunks.Count);
            {
                HunkHeader h = f.Hunks[0];
                Assert.AreEqual(f, h.File);
                Assert.AreEqual(321, h.StartOffset);
                Assert.AreEqual(1, h.OldImage.StartLine);
                Assert.AreEqual(1, h.OldImage.LineCount);
                Assert.AreEqual(1, h.NewStartLine);
                Assert.AreEqual(1, h.NewLineCount);

                Assert.AreEqual(0, h.LinesContext);
                Assert.AreEqual(1, h.OldImage.LinesAdded);
                Assert.AreEqual(1, h.OldImage.LinesDeleted);
                Assert.AreEqual(f.getOldId(), h.OldImage.Id);

                Assert.AreEqual(367, h.EndOffset);
            }
        }
Exemplo n.º 2
0
        public void testEmpty()
        {
            var patch = new GitSharp.Core.Patch.Patch();

            Assert.IsTrue(patch.getFiles().Count == 0);
            Assert.IsTrue(patch.getErrors().Count == 0);
        }
Exemplo n.º 3
0
        public void testParse_CcDeleteFile()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testParse_CcDeleteFile.patch");
            Assert.AreEqual(1, p.getFiles().Count);
            Assert.IsTrue(p.getErrors().isEmpty());

            var cfh = (CombinedFileHeader)p.getFiles()[0];

            Assert.AreEqual("a", cfh.OldName);
            Assert.AreSame(FileHeader.DEV_NULL, cfh.NewName);

            Assert.AreEqual(187, cfh.StartOffset);

            Assert.AreEqual(2, cfh.ParentCount);
            Assert.AreSame(cfh.getOldId(0), cfh.getOldId());
            Assert.AreEqual("7898192", cfh.getOldId(0).name());
            Assert.AreEqual("2e65efe", cfh.getOldId(1).name());
            Assert.AreEqual("0000000", cfh.getNewId().name());

            Assert.AreSame(cfh.getOldMode(0), cfh.GetOldMode());
            Assert.AreSame(FileMode.RegularFile, cfh.getOldMode(0));
            Assert.AreSame(FileMode.RegularFile, cfh.getOldMode(1));
            Assert.AreSame(FileMode.Missing, cfh.NewMode);
            Assert.AreEqual(FileHeader.ChangeTypeEnum.DELETE, cfh.getChangeType());
            Assert.AreEqual(FileHeader.PatchTypeEnum.UNIFIED, cfh.getPatchType());

            Assert.IsTrue(cfh.Hunks.isEmpty());
        }
Exemplo n.º 4
0
        public void testError_GitBinaryNoForwardHunk()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testError_GitBinaryNoForwardHunk.patch");
            Assert.AreEqual(2, p.getFiles().Count);

            FileHeader fh0 = p.getFiles()[0];

            Assert.AreEqual("org.spearce.egit.ui/icons/toolbar/fetchd.png", fh0.NewName);
            Assert.AreEqual(FileHeader.PatchTypeEnum.GIT_BINARY, fh0.getPatchType());
            Assert.IsTrue(fh0.Hunks.isEmpty());
            Assert.IsNull(fh0.getForwardBinaryHunk());

            FileHeader fh1 = p.getFiles()[1];

            Assert.AreEqual("org.spearce.egit.ui/icons/toolbar/fetche.png", fh1.NewName);
            Assert.AreEqual(FileHeader.PatchTypeEnum.UNIFIED, fh1.getPatchType());
            Assert.IsTrue(fh1.Hunks.isEmpty());
            Assert.IsNull(fh1.getForwardBinaryHunk());

            Assert.AreEqual(1, p.getErrors().Count);
            FormatError e = p.getErrors()[0];

            Assert.AreEqual(FormatError.Severity.ERROR, e.getSeverity());
            Assert.AreEqual("Missing forward-image in GIT binary patch", e.getMessage());
            Assert.AreEqual(297, e.getOffset());
            Assert.AreEqual("\n", e.getLineText());
        }
Exemplo n.º 5
0
 public void testError_CcTruncatedOld()
 {
     GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testError_CcTruncatedOld.patch");
     Assert.AreEqual(1, p.getFiles().Count);
     Assert.AreEqual(3, p.getErrors().Count);
     {
         FormatError e = p.getErrors()[0];
         Assert.AreEqual(FormatError.Severity.ERROR, e.getSeverity());
         Assert.AreEqual(
             "Truncated hunk, at least 1 lines is missing for ancestor 1",
             e.getMessage());
         Assert.AreEqual(346, e.getOffset());
         Assert.IsTrue(e.getLineText().StartsWith(
                           "@@@ -55,12 -163,13 +163,15 @@@ public "));
     }
     {
         FormatError e = p.getErrors()[1];
         Assert.AreEqual(FormatError.Severity.ERROR, e.getSeverity());
         Assert.AreEqual(
             "Truncated hunk, at least 2 lines is missing for ancestor 2",
             e.getMessage());
         Assert.AreEqual(346, e.getOffset());
         Assert.IsTrue(e.getLineText().StartsWith(
                           "@@@ -55,12 -163,13 +163,15 @@@ public "));
     }
     {
         FormatError e = p.getErrors()[2];
         Assert.AreEqual(FormatError.Severity.ERROR, e.getSeverity());
         Assert.AreEqual("Truncated hunk, at least 3 new lines is missing", e
                         .getMessage());
         Assert.AreEqual(346, e.getOffset());
         Assert.IsTrue(e.getLineText().StartsWith(
                           "@@@ -55,12 -163,13 +163,15 @@@ public "));
     }
 }
Exemplo n.º 6
0
        public void testFileHeader()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testGetText_BothISO88591.patch");
            FileHeader fh = p.getFiles()[0];
            EditList   e  = fh.ToEditList();

            Assert.AreEqual(2, e.size());
            Assert.AreEqual(new Edit(4 - 1, 5 - 1, 4 - 1, 5 - 1), e.get(0));
            Assert.AreEqual(new Edit(16 - 1, 17 - 1, 16 - 1, 17 - 1), e.get(1));
        }
Exemplo n.º 7
0
        public void testParse_OneFileCc()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testParse_OneFileCc.patch");
            Assert.AreEqual(1, p.getFiles().Count);
            Assert.IsTrue(p.getErrors().isEmpty());

            var cfh = (CombinedFileHeader)p.getFiles()[0];

            Assert.AreEqual("org.spearce.egit.ui/src/org/spearce/egit/ui/UIText.java", cfh.NewName);
            Assert.AreEqual(cfh.NewName, cfh.OldName);

            Assert.AreEqual(98, cfh.StartOffset);

            Assert.AreEqual(2, cfh.ParentCount);
            Assert.AreSame(cfh.getOldId(0), cfh.getOldId());
            Assert.AreEqual("169356b", cfh.getOldId(0).name());
            Assert.AreEqual("dd8c317", cfh.getOldId(1).name());
            Assert.AreEqual("fd85931", cfh.getNewId().name());

            Assert.AreEqual(cfh.getOldMode(0), cfh.GetOldMode());
            Assert.AreEqual(FileMode.RegularFile, cfh.getOldMode(0));
            Assert.AreEqual(FileMode.RegularFile, cfh.getOldMode(1));
            Assert.AreEqual(FileMode.ExecutableFile, cfh.NewMode);
            Assert.AreEqual(FileHeader.ChangeTypeEnum.MODIFY, cfh.getChangeType());
            Assert.AreEqual(FileHeader.PatchTypeEnum.UNIFIED, cfh.getPatchType());

            Assert.AreEqual(1, cfh.Hunks.Count);
            {
                var h = (CombinedHunkHeader)cfh.Hunks[0];

                Assert.AreSame(cfh, h.File);
                Assert.AreEqual(346, h.StartOffset);
                Assert.AreEqual(764, h.EndOffset);

                Assert.AreSame(h.GetOldImage(0), h.OldImage);
                Assert.AreSame(cfh.getOldId(0), h.GetOldImage(0).Id);
                Assert.AreSame(cfh.getOldId(1), h.GetOldImage(1).Id);

                Assert.AreEqual(55, h.GetOldImage(0).StartLine);
                Assert.AreEqual(12, h.GetOldImage(0).LineCount);
                Assert.AreEqual(3, h.GetOldImage(0).LinesAdded);
                Assert.AreEqual(0, h.GetOldImage(0).LinesDeleted);

                Assert.AreEqual(163, h.GetOldImage(1).StartLine);
                Assert.AreEqual(13, h.GetOldImage(1).LineCount);
                Assert.AreEqual(2, h.GetOldImage(1).LinesAdded);
                Assert.AreEqual(0, h.GetOldImage(1).LinesDeleted);

                Assert.AreEqual(163, h.NewStartLine);
                Assert.AreEqual(15, h.NewLineCount);

                Assert.AreEqual(10, h.LinesContext);
            }
        }
Exemplo n.º 8
0
        public void testParse_CcNewFile()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testParse_CcNewFile.patch");
            Assert.AreEqual(1, p.getFiles().Count);
            Assert.IsTrue(p.getErrors().isEmpty());

            var cfh = (CombinedFileHeader)p.getFiles()[0];

            Assert.AreSame(FileHeader.DEV_NULL, cfh.OldName);
            Assert.AreEqual("d", cfh.NewName);

            Assert.AreEqual(187, cfh.StartOffset);

            Assert.AreEqual(2, cfh.ParentCount);
            Assert.AreSame(cfh.getOldId(0), cfh.getOldId());
            Assert.AreEqual("0000000", cfh.getOldId(0).name());
            Assert.AreEqual("0000000", cfh.getOldId(1).name());
            Assert.AreEqual("4bcfe98", cfh.getNewId().name());

            Assert.AreSame(cfh.getOldMode(0), cfh.GetOldMode());
            Assert.AreSame(FileMode.Missing, cfh.getOldMode(0));
            Assert.AreSame(FileMode.Missing, cfh.getOldMode(1));
            Assert.AreSame(FileMode.RegularFile, cfh.NewMode);
            Assert.AreEqual(FileHeader.ChangeTypeEnum.ADD, cfh.getChangeType());
            Assert.AreEqual(FileHeader.PatchTypeEnum.UNIFIED, cfh.getPatchType());

            Assert.AreEqual(1, cfh.Hunks.Count);
            {
                var h = (CombinedHunkHeader)cfh.Hunks[0];

                Assert.AreSame(cfh, h.File);
                Assert.AreEqual(273, h.StartOffset);
                Assert.AreEqual(300, h.EndOffset);

                Assert.AreSame(h.GetOldImage(0), h.OldImage);
                Assert.AreSame(cfh.getOldId(0), h.GetOldImage(0).Id);
                Assert.AreSame(cfh.getOldId(1), h.GetOldImage(1).Id);

                Assert.AreEqual(1, h.GetOldImage(0).StartLine);
                Assert.AreEqual(0, h.GetOldImage(0).LineCount);
                Assert.AreEqual(1, h.GetOldImage(0).LinesAdded);
                Assert.AreEqual(0, h.GetOldImage(0).LinesDeleted);

                Assert.AreEqual(1, h.GetOldImage(1).StartLine);
                Assert.AreEqual(0, h.GetOldImage(1).LineCount);
                Assert.AreEqual(1, h.GetOldImage(1).LinesAdded);
                Assert.AreEqual(0, h.GetOldImage(1).LinesDeleted);

                Assert.AreEqual(1, h.NewStartLine);
                Assert.AreEqual(1, h.NewLineCount);

                Assert.AreEqual(0, h.LinesContext);
            }
        }
Exemplo n.º 9
0
        public void testTypes()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testEditList_Types.patch");
            FileHeader fh = p.getFiles()[0];
            EditList   e  = fh.ToEditList();

            Assert.AreEqual(3, e.size());
            Assert.AreEqual(new Edit(3 - 1, 3 - 1, 3 - 1, 4 - 1), e.get(0));
            Assert.AreEqual(new Edit(17 - 1, 19 - 1, 18 - 1, 18 - 1), e.get(1));
            Assert.AreEqual(new Edit(23 - 1, 25 - 1, 22 - 1, 28 - 1), e.get(2));
        }
Exemplo n.º 10
0
        public void testGetText_NoBinary()
        {
            Encoding cs = Charset.forName("ISO-8859-1");

            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testGetText_NoBinary.patch");
            Assert.IsTrue(p.getErrors().Count == 0);
            Assert.AreEqual(1, p.getFiles().Count);
            FileHeader fh = p.getFiles()[0];

            Assert.AreEqual(0, fh.Hunks.Count);
            Assert.AreEqual(ReadTestPatchFile(cs), fh.getScriptText(cs, cs));
        }
Exemplo n.º 11
0
        public void testError_TruncatedNew()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testError_TruncatedNew.patch");
            Assert.AreEqual(1, p.getFiles().Count);
            Assert.AreEqual(1, p.getErrors().Count);

            FormatError e = p.getErrors()[0];

            Assert.AreEqual(FormatError.Severity.ERROR, e.getSeverity());
            Assert.AreEqual("Truncated hunk, at least 1 new lines is missing", e.getMessage());
            Assert.AreEqual(313, e.getOffset());
            Assert.IsTrue(e.getLineText().StartsWith("@@ -236,9 +236,9 @@ protected "));
        }
Exemplo n.º 12
0
        public void testError_BodyTooLong()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testError_BodyTooLong.patch");
            Assert.AreEqual(1, p.getFiles().Count);
            Assert.AreEqual(1, p.getErrors().Count);

            FormatError e = p.getErrors()[0];

            Assert.AreEqual(FormatError.Severity.WARNING, e.getSeverity());
            Assert.AreEqual("Hunk header 4:11 does not match body line count of 4:12", e.getMessage());
            Assert.AreEqual(349, e.getOffset());
            Assert.IsTrue(e.getLineText().StartsWith("@@ -109,4 +109,11 @@ assert"));
        }
Exemplo n.º 13
0
        public void testHunkHeader()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testGetText_BothISO88591.patch");
            FileHeader fh = p.getFiles()[0];

            EditList list0 = fh.Hunks[0].ToEditList();

            Assert.AreEqual(1, list0.size());
            Assert.AreEqual(new Edit(4 - 1, 5 - 1, 4 - 1, 5 - 1), list0.get(0));

            EditList list1 = fh.Hunks[1].ToEditList();

            Assert.AreEqual(1, list1.size());
            Assert.AreEqual(new Edit(16 - 1, 17 - 1, 16 - 1, 17 - 1), list1.get(0));
        }
Exemplo n.º 14
0
        public void testParse_GitBinaryLiteral()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testParse_GitBinaryLiteral.patch");
            int[] binsizes = { 359, 393, 372, 404 };
            Assert.AreEqual(5, p.getFiles().Count);
            Assert.IsTrue(p.getErrors().Count == 0);

            for (int i = 0; i < 4; i++)
            {
                FileHeader fh = p.getFiles()[i];
                Assert.AreEqual(FileHeader.ChangeTypeEnum.ADD, fh.getChangeType());
                Assert.IsNotNull(fh.getOldId());
                Assert.IsNotNull(fh.getNewId());
                Assert.AreEqual(ObjectId.ZeroId.Name, fh.getOldId().name());
                Assert.AreEqual(FileMode.RegularFile, fh.NewMode);
                Assert.IsTrue(fh.NewName.StartsWith(
                                  "org.spearce.egit.ui/icons/toolbar/"));
                Assert.AreEqual(FileHeader.PatchTypeEnum.GIT_BINARY, fh.getPatchType());
                Assert.IsTrue(fh.Hunks.Count == 0);
                Assert.IsTrue(fh.hasMetaDataChanges());

                BinaryHunk fwd = fh.getForwardBinaryHunk();
                BinaryHunk rev = fh.getReverseBinaryHunk();
                Assert.IsNotNull(fwd);
                Assert.IsNotNull(rev);
                Assert.AreEqual(binsizes[i], fwd.getSize());
                Assert.AreEqual(0, rev.getSize());

                Assert.AreEqual(fh, fwd.getFileHeader());
                Assert.AreEqual(fh, rev.getFileHeader());

                Assert.AreEqual(BinaryHunk.Type.LITERAL_DEFLATED, fwd.getType());
                Assert.AreEqual(BinaryHunk.Type.LITERAL_DEFLATED, rev.getType());
            }

            {
                FileHeader fh = p.getFiles()[4];
                Assert.AreEqual("org.spearce.egit.ui/plugin.xml", fh.NewName);
                Assert.AreEqual(FileHeader.ChangeTypeEnum.MODIFY, fh.getChangeType());
                Assert.AreEqual(FileHeader.PatchTypeEnum.UNIFIED, fh.getPatchType());
                Assert.IsFalse(fh.hasMetaDataChanges());
                Assert.AreEqual("ee8a5a0", fh.getNewId().name());
                Assert.IsNull(fh.getForwardBinaryHunk());
                Assert.IsNull(fh.getReverseBinaryHunk());
                Assert.AreEqual(1, fh.Hunks.Count);
                Assert.AreEqual(272, fh.Hunks[0].OldImage.StartLine);
            }
        }
Exemplo n.º 15
0
        protected static string GetAllErrorsFromPatch(GitSharp.Core.Patch.Patch patch)
        {
            if (patch == null || patch.getErrors().Count == 0)
            {
                return(string.Empty);
            }

            var sb = new StringBuilder();

            foreach (FormatError formatError in patch.getErrors())
            {
                sb.AppendLine(formatError.getMessage());
            }

            return(sb.ToString());
        }
Exemplo n.º 16
0
 protected static GitSharp.Core.Patch.Patch ParseTestPatchFile(string patchFile)
 {
     try
     {
         using (var inStream = new FileStream(patchFile, System.IO.FileMode.Open))
         {
             var p = new GitSharp.Core.Patch.Patch();
             p.parse(inStream);
             return(p);
         }
     }
     catch (IOException)
     {
         Assert.Fail("No " + patchFile + " test vector");
         return(null);                // Never happens
     }
 }
Exemplo n.º 17
0
 protected static GitSharp.Core.Patch.Patch ParseTestPatchFile(string patchFile)
 {
     try
     {
         using (var inStream = new FileStream(patchFile, System.IO.FileMode.Open))
         {
             var p = new GitSharp.Core.Patch.Patch();
             p.parse(inStream);
             return p;
         }
     }
     catch(IOException)
     {
         Assert.Fail("No " + patchFile + " test vector");
         return null; // Never happens
     }
 }
Exemplo n.º 18
0
        public void testError_DisconnectedHunk()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testError_DisconnectedHunk.patch");
            Assert.AreEqual(1, p.getFiles().Count);
            Assert.AreEqual(1, p.getErrors().Count);

            FileHeader fh = p.getFiles()[0];

            Assert.AreEqual("org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java", fh.NewName);
            Assert.AreEqual(1, fh.Hunks.Count);

            Assert.AreEqual(1, p.getErrors().Count);
            FormatError e = p.getErrors()[0];

            Assert.AreEqual(FormatError.Severity.ERROR, e.getSeverity());
            Assert.AreEqual("Hunk disconnected from file", e.getMessage());
            Assert.AreEqual(18, e.getOffset());
            Assert.IsTrue(e.getLineText().StartsWith("@@ -109,4 +109,11 @@ assert"));
        }
Exemplo n.º 19
0
        public void testGetText_Convert()
        {
            Encoding csOld = Charset.forName("ISO-8859-1");
            Encoding csNew = Charset.forName("UTF-8");

            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testGetText_Convert.patch");
            Assert.IsTrue(p.getErrors().Count == 0);
            Assert.AreEqual(1, p.getFiles().Count);
            FileHeader fh = p.getFiles()[0];

            Assert.AreEqual(2, fh.Hunks.Count);

            // Read the original File as ISO-8859-1 and fix up the one place
            // where we changed the character encoding. That makes the exp
            // string match what we really expect to get back.
            //
            string exp = ReadTestPatchFile(csOld);

            exp = exp.Replace("\u00C3\u0085ngstr\u00C3\u00B6m", "\u00c5ngstr\u00f6m");  // henon: octal character representation is not legal in c# literals: "\303\205ngstr\303\266m"

            Assert.AreEqual(exp, fh.getScriptText(csOld, csNew));
        }
Exemplo n.º 20
0
        public void testParse_GitBinaryDelta()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testParse_GitBinaryDelta.patch");
            Assert.AreEqual(1, p.getFiles().Count);
            Assert.IsTrue(p.getErrors().Count == 0);

            FileHeader fh = p.getFiles()[0];

            Assert.IsTrue(fh.NewName.StartsWith("zero.bin"));
            Assert.AreEqual(FileHeader.ChangeTypeEnum.MODIFY, fh.getChangeType());
            Assert.AreEqual(FileHeader.PatchTypeEnum.GIT_BINARY, fh.getPatchType());
            Assert.AreEqual(FileMode.RegularFile, fh.NewMode);

            Assert.IsNotNull(fh.getOldId());
            Assert.IsNotNull(fh.getNewId());
            Assert.AreEqual("08e7df176454f3ee5eeda13efa0adaa54828dfd8", fh.getOldId()
                            .name());
            Assert.AreEqual("d70d8710b6d32ff844af0ee7c247e4b4b051867f", fh.getNewId()
                            .name());

            Assert.IsTrue(fh.Hunks.Count == 0);
            Assert.IsFalse(fh.hasMetaDataChanges());

            BinaryHunk fwd = fh.getForwardBinaryHunk();
            BinaryHunk rev = fh.getReverseBinaryHunk();

            Assert.IsNotNull(fwd);
            Assert.IsNotNull(rev);
            Assert.AreEqual(12, fwd.getSize());
            Assert.AreEqual(11, rev.getSize());

            Assert.AreEqual(fh, fwd.getFileHeader());
            Assert.AreEqual(fh, rev.getFileHeader());

            Assert.AreEqual(BinaryHunk.Type.DELTA_DEFLATED, fwd.getType());
            Assert.AreEqual(BinaryHunk.Type.DELTA_DEFLATED, rev.getType());

            Assert.AreEqual(496, fh.EndOffset);
        }
Exemplo n.º 21
0
        public void testParse_NoBinary()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testParse_NoBinary.patch");
            Assert.AreEqual(5, p.getFiles().Count);
            Assert.IsTrue(p.getErrors().Count == 0);

            for (int i = 0; i < 4; i++)
            {
                FileHeader fh = p.getFiles()[i];
                Assert.AreEqual(FileHeader.ChangeTypeEnum.ADD, fh.getChangeType());
                Assert.IsNotNull(fh.getOldId());
                Assert.IsNotNull(fh.getNewId());
                Assert.AreEqual("0000000", fh.getOldId().name());
                Assert.AreEqual(FileMode.Missing, fh.GetOldMode());
                Assert.AreEqual(FileMode.RegularFile, fh.NewMode);
                Assert.IsTrue(fh.NewName.StartsWith(
                                  "org.spearce.egit.ui/icons/toolbar/"));
                Assert.AreEqual(FileHeader.PatchTypeEnum.BINARY, fh.getPatchType());
                Assert.IsTrue(fh.Hunks.Count == 0);
                Assert.IsTrue(fh.hasMetaDataChanges());

                Assert.IsNull(fh.getForwardBinaryHunk());
                Assert.IsNull(fh.getReverseBinaryHunk());
            }

            {
                FileHeader fh = p.getFiles()[4];
                Assert.AreEqual("org.spearce.egit.ui/plugin.xml", fh.NewName);
                Assert.AreEqual(FileHeader.ChangeTypeEnum.MODIFY, fh.getChangeType());
                Assert.AreEqual(FileHeader.PatchTypeEnum.UNIFIED, fh.getPatchType());
                Assert.IsFalse(fh.hasMetaDataChanges());
                Assert.AreEqual("ee8a5a0", fh.getNewId().name());
                Assert.IsNull(fh.getForwardBinaryHunk());
                Assert.IsNull(fh.getReverseBinaryHunk());
                Assert.AreEqual(1, fh.Hunks.Count);
                Assert.AreEqual(272, fh.Hunks[0].OldImage.StartLine);
            }
        }
Exemplo n.º 22
0
        public void testError_GarbageBetweenFiles()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testError_GarbageBetweenFiles.patch");
            Assert.AreEqual(2, p.getFiles().Count);

            FileHeader fh0 = p.getFiles()[0];

            Assert.AreEqual("org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java", fh0.NewName);
            Assert.AreEqual(1, fh0.Hunks.Count);

            FileHeader fh1 = p.getFiles()[1];

            Assert.AreEqual("org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java", fh1.NewName);
            Assert.AreEqual(1, fh1.Hunks.Count);

            Assert.AreEqual(1, p.getErrors().Count);
            FormatError e = p.getErrors()[0];

            Assert.AreEqual(FormatError.Severity.WARNING, e.getSeverity());
            Assert.AreEqual("Unexpected hunk trailer", e.getMessage());
            Assert.AreEqual(926, e.getOffset());
            Assert.AreEqual("I AM NOT HERE\n", e.getLineText());
        }
Exemplo n.º 23
0
        public void testGetText_DiffCc()
        {
            Assert.Ignore("We are going to deal with encoding problems later. For now, they are only disturbing the build.");

            Encoding csOld = Charset.forName("ISO-8859-1");
            Encoding csNew = Charset.forName("UTF-8");

            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testGetText_DiffCc.patch");
            Assert.IsTrue(p.getErrors().Count == 0);
            Assert.AreEqual(1, p.getFiles().Count);
            var fh = (CombinedFileHeader)p.getFiles()[0];

            Assert.AreEqual(1, fh.Hunks.Count);

            // Read the original File as ISO-8859-1 and fix up the one place
            // where we changed the character encoding. That makes the exp
            // string match what we really expect to get back.
            //
            string exp = ReadTestPatchFile(csOld);

            exp = exp.Replace("\u00C3\u0085ngstr\u00C3\u00B6m", "\u00c5ngstr\u00f6m");
            Assert.AreEqual(exp, fh.getScriptText(new[] { csNew, csOld, csNew }));
        }
Exemplo n.º 24
0
        public virtual int parseBody(Patch script, int end)
        {
            byte[] buf = _file.Buffer;
            int    c = RawParseUtils.nextLF(buf, _startOffset), last = c;

            _oldImage.LinesDeleted = 0;
            _oldImage.LinesAdded   = 0;

            for (; c < end; last = c, c = RawParseUtils.nextLF(buf, c))
            {
                bool breakScan;
                switch (buf[c])
                {
                case (byte)' ':
                case (byte)'\n':
                    LinesContext++;
                    continue;

                case (byte)'-':
                    _oldImage.LinesDeleted++;
                    continue;

                case (byte)'+':
                    _oldImage.LinesAdded++;
                    continue;

                case (byte)'\\':                         // Matches "\ No newline at end of file"
                    continue;

                default:
                    breakScan = true;
                    break;
                }

                if (breakScan)
                {
                    break;
                }
            }

            if (last < end && LinesContext + _oldImage.LinesDeleted - 1 == _oldImage.LineCount &&
                LinesContext + _oldImage.LinesAdded == NewLineCount &&
                RawParseUtils.match(buf, last, Patch.SigFooter) >= 0)
            {
                // This is an extremely common occurrence of "corruption".
                // Users add footers with their signatures After this mark,
                // and git diff adds the git executable version number.
                // Let it slide; the hunk otherwise looked sound.
                //
                _oldImage.LinesDeleted--;
                return(last);
            }

            if (LinesContext + _oldImage.LinesDeleted < _oldImage.LineCount)
            {
                int missingCount = _oldImage.LineCount - (LinesContext + _oldImage.LinesDeleted);
                script.error(buf, _startOffset, "Truncated hunk, at least "
                             + missingCount + " old lines is missing");
            }
            else if (LinesContext + _oldImage.LinesAdded < NewLineCount)
            {
                int missingCount = NewLineCount - (LinesContext + _oldImage.LinesAdded);
                script.error(buf, _startOffset, "Truncated hunk, at least "
                             + missingCount + " new lines is missing");
            }
            else if (LinesContext + _oldImage.LinesDeleted > _oldImage.LineCount ||
                     LinesContext + _oldImage.LinesAdded > NewLineCount)
            {
                string oldcnt = _oldImage.LineCount + ":" + NewLineCount;
                string newcnt = (LinesContext + _oldImage.LinesDeleted) + ":"
                                + (LinesContext + _oldImage.LinesAdded);
                script.warn(buf, _startOffset, "Hunk header " + oldcnt
                            + " does not match body line count of " + newcnt);
            }

            return(c);
        }
Exemplo n.º 25
0
		public virtual int parseBody(Patch script, int end)
		{
			byte[] buf = _file.Buffer;
			int c = RawParseUtils.nextLF(buf, _startOffset), last = c;

			_oldImage.LinesDeleted = 0;
			_oldImage.LinesAdded = 0;

			for (; c < end; last = c, c = RawParseUtils.nextLF(buf, c))
			{
				bool breakScan;
				switch (buf[c])
				{
					case (byte)' ':
					case (byte)'\n':
						LinesContext++;
						continue;

					case (byte)'-':
						_oldImage.LinesDeleted++;
						continue;

					case (byte)'+':
						_oldImage.LinesAdded++;
						continue;

					case (byte)'\\': // Matches "\ No newline at end of file"
						continue;

					default:
						breakScan = true;
						break;
				}

				if (breakScan)
				{
					break;
				}
			}

			if (last < end && LinesContext + _oldImage.LinesDeleted - 1 == _oldImage.LineCount
				&& LinesContext + _oldImage.LinesAdded == NewLineCount
				&& RawParseUtils.match(buf, last, Patch.SigFooter) >= 0)
			{
				// This is an extremely common occurrence of "corruption".
				// Users add footers with their signatures After this mark,
				// and git diff adds the git executable version number.
				// Let it slide; the hunk otherwise looked sound.
				//
				_oldImage.LinesDeleted--;
				return last;
			}

			if (LinesContext + _oldImage.LinesDeleted < _oldImage.LineCount)
			{
				int missingCount = _oldImage.LineCount - (LinesContext + _oldImage.LinesDeleted);
				script.error(buf, _startOffset, "Truncated hunk, at least "
												+ missingCount + " old lines is missing");
			}
			else if (LinesContext + _oldImage.LinesAdded < NewLineCount)
			{
				int missingCount = NewLineCount - (LinesContext + _oldImage.LinesAdded);
				script.error(buf, _startOffset, "Truncated hunk, at least "
												+ missingCount + " new lines is missing");
			}
			else if (LinesContext + _oldImage.LinesDeleted > _oldImage.LineCount
					 || LinesContext + _oldImage.LinesAdded > NewLineCount)
			{
				string oldcnt = _oldImage.LineCount + ":" + NewLineCount;
				string newcnt = (LinesContext + _oldImage.LinesDeleted) + ":"
								+ (LinesContext + _oldImage.LinesAdded);
				script.warn(buf, _startOffset, "Hunk header " + oldcnt
											   + " does not match body line count of " + newcnt);
			}

			return c;
		}
Exemplo n.º 26
0
		public void testEmpty()
		{
			var patch = new GitSharp.Core.Patch.Patch();
			Assert.IsTrue(patch.getFiles().Count == 0);
			Assert.IsTrue(patch.getErrors().Count == 0);
		}
        public override int parseBody(Patch script, int end)
        {
            byte[] buf = File.Buffer;
            int c = RawParseUtils.nextLF(buf, StartOffset);

            _old.ForEach(coi =>
                         	{
                         		coi.LinesAdded = 0;
                         		coi.LinesDeleted = 0;
                         		coi.LinesContext = 0;
                         	});

            LinesContext = 0;
            int nAdded = 0;

            for (int eol; c < end; c = eol)
            {
                eol = RawParseUtils.nextLF(buf, c);

                if (eol - c < _old.Count + 1)
                {
                    // Line isn't long enough to mention the state of each
                    // ancestor. It must be the end of the hunk.
                    break;
                }

                bool break_scan = false;
                switch (buf[c])
                {
                    case (byte)' ':
                    case (byte)'-':
                    case (byte)'+':
                        break;

                    default:
                        // Line can't possibly be part of this hunk; the first
                        // ancestor information isn't recognizable.
                        //
                        break_scan = true;
                        break;
                }
                if (break_scan)
                    break;

                int localcontext = 0;
                for (int ancestor = 0; ancestor < _old.Count; ancestor++)
                {
                    switch (buf[c + ancestor])
                    {
                        case (byte)' ':
                            localcontext++;
                            _old[ancestor].LinesContext++;
                            continue;

                        case (byte)'-':
                            _old[ancestor].LinesDeleted++;
                            continue;

                        case (byte)'+':
                            _old[ancestor].LinesAdded++;
                            nAdded++;
                            continue;

                        default:
                            break_scan = true;
                            break;
                    }
                    if (break_scan)
                        break;
                }
                if (break_scan)
                    break;

                if (localcontext == _old.Count)
                {
                    LinesContext++;
                }
            }

            for (int ancestor = 0; ancestor < _old.Count; ancestor++)
            {
                CombinedOldImage o = _old[ancestor];
                int cmp = o.LinesContext + o.LinesDeleted;
                if (cmp < o.LineCount)
                {
                    int missingCnt = o.LineCount - cmp;
                    script.error(buf, StartOffset, "Truncated hunk, at least "
                            + missingCnt + " lines is missing for ancestor "
                            + (ancestor + 1));
                }
            }

            if (LinesContext + nAdded < NewLineCount)
            {
                int missingCount = NewLineCount - (LinesContext + nAdded);
                script.error(buf, StartOffset, "Truncated hunk, at least "
                        + missingCount + " new lines is missing");
            }

            return c;
        }
Exemplo n.º 28
0
        public void testParse_ConfigCaseInsensitive()
        {
            GitSharp.Core.Patch.Patch p = ParseTestPatchFile(PatchsDir + "testParse_ConfigCaseInsensitive.patch");
            Assert.AreEqual(2, p.getFiles().Count);
            Assert.IsTrue(p.getErrors().Count == 0);

            FileHeader fRepositoryConfigTest = p.getFiles()[0];
            FileHeader fRepositoryConfig     = p.getFiles()[1];

            Assert.AreEqual(
                "org.spearce.jgit.test/tst/org/spearce/jgit/lib/RepositoryConfigTest.java",
                fRepositoryConfigTest.NewName);

            Assert.AreEqual(
                "org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryConfig.java",
                fRepositoryConfig.NewName);

            Assert.AreEqual(572, fRepositoryConfigTest.StartOffset);
            Assert.AreEqual(1490, fRepositoryConfig.StartOffset);

            Assert.AreEqual("da7e704", fRepositoryConfigTest.getOldId().name());
            Assert.AreEqual("34ce04a", fRepositoryConfigTest.getNewId().name());
            Assert.AreEqual(FileHeader.PatchTypeEnum.UNIFIED, fRepositoryConfigTest.getPatchType());
            Assert.AreEqual(FileMode.RegularFile, fRepositoryConfigTest.GetOldMode());
            Assert.AreEqual(FileMode.RegularFile, fRepositoryConfigTest.NewMode);
            Assert.AreEqual(1, fRepositoryConfigTest.Hunks.Count);
            {
                HunkHeader h = fRepositoryConfigTest.Hunks[0];
                Assert.AreEqual(fRepositoryConfigTest, h.File);
                Assert.AreEqual(921, h.StartOffset);
                Assert.AreEqual(109, h.OldImage.StartLine);
                Assert.AreEqual(4, h.OldImage.LineCount);
                Assert.AreEqual(109, h.NewStartLine);
                Assert.AreEqual(11, h.NewLineCount);

                Assert.AreEqual(4, h.LinesContext);
                Assert.AreEqual(7, h.OldImage.LinesAdded);
                Assert.AreEqual(0, h.OldImage.LinesDeleted);
                Assert.AreEqual(fRepositoryConfigTest.getOldId(), h.OldImage.Id);

                Assert.AreEqual(1490, h.EndOffset);
            }

            Assert.AreEqual("45c2f8a", fRepositoryConfig.getOldId().name());
            Assert.AreEqual("3291bba", fRepositoryConfig.getNewId().name());
            Assert.AreEqual(FileHeader.PatchTypeEnum.UNIFIED, fRepositoryConfig
                            .getPatchType());
            Assert.AreEqual(FileMode.RegularFile, fRepositoryConfig.GetOldMode());
            Assert.AreEqual(FileMode.RegularFile, fRepositoryConfig.NewMode);
            Assert.AreEqual(3, fRepositoryConfig.Hunks.Count);
            {
                HunkHeader h = fRepositoryConfig.Hunks[0];
                Assert.AreEqual(fRepositoryConfig, h.File);
                Assert.AreEqual(1803, h.StartOffset);
                Assert.AreEqual(236, h.OldImage.StartLine);
                Assert.AreEqual(9, h.OldImage.LineCount);
                Assert.AreEqual(236, h.NewStartLine);
                Assert.AreEqual(9, h.NewLineCount);

                Assert.AreEqual(7, h.LinesContext);
                Assert.AreEqual(2, h.OldImage.LinesAdded);
                Assert.AreEqual(2, h.OldImage.LinesDeleted);
                Assert.AreEqual(fRepositoryConfig.getOldId(), h.OldImage.Id);

                Assert.AreEqual(2434, h.EndOffset);
            }
            {
                HunkHeader h = fRepositoryConfig.Hunks[1];
                Assert.AreEqual(2434, h.StartOffset);
                Assert.AreEqual(300, h.OldImage.StartLine);
                Assert.AreEqual(7, h.OldImage.LineCount);
                Assert.AreEqual(300, h.NewStartLine);
                Assert.AreEqual(7, h.NewLineCount);

                Assert.AreEqual(6, h.LinesContext);
                Assert.AreEqual(1, h.OldImage.LinesAdded);
                Assert.AreEqual(1, h.OldImage.LinesDeleted);

                Assert.AreEqual(2816, h.EndOffset);
            }
            {
                HunkHeader h = fRepositoryConfig.Hunks[2];
                Assert.AreEqual(2816, h.StartOffset);
                Assert.AreEqual(954, h.OldImage.StartLine);
                Assert.AreEqual(7, h.OldImage.LineCount);
                Assert.AreEqual(954, h.NewStartLine);
                Assert.AreEqual(7, h.NewLineCount);

                Assert.AreEqual(6, h.LinesContext);
                Assert.AreEqual(1, h.OldImage.LinesAdded);
                Assert.AreEqual(1, h.OldImage.LinesDeleted);

                Assert.AreEqual(3035, h.EndOffset);
            }
        }