Skip to content

Binary change not detected #506

@careri

Description

@careri

Hi!

NuGet: 0.13.0.0
OS: Windows 8.1

The following test case doesn't detected changes in a binary file.

  1. Write a binary file, size: 255. I fill by looping a byte.
  2. Commit the new change.
  3. Change a couple of bytes in the file. No change detected when calling repo.Diff.compare

Best Regards
/Carl

        [TestMethod]
        public void BinDiffDetectionFailed()
        {
            // Init repo
            var repoName = "PatchTest";
            var di = new DirectoryInfo(repoName);

            if (di.Exists)
            {
                di.Delete(true);
            }

            di.Create();
            Repository.Init(di.FullName, false);
            var repo = new Repository(di.FullName);

            // Create a binary file containing 255 bytes
            var dataFI = new FileInfo(Path.Combine(di.FullName, "data1.bin"));

            using (var writer = new BinaryWriter(dataFI.Create()))
            {
                byte b = 0;
                for (int i = 0; i < 255; i++)
                {
                    writer.Write(b++);
                }
            }
            // Commit
            repo.Index.Stage(dataFI.FullName);
            repo.Commit("Commit1");

            // Change a couple of bytes in the file
            using (var writer = new BinaryWriter(dataFI.OpenWrite()))
            {
                var offset = 100;
                var data = new byte[] { 10, 11, 12, 13, 14 };
                writer.Seek(offset, SeekOrigin.Begin);
                writer.Write(data);
            }
            // Call diff, no diffs are found...
            var paths = new List<string>() { dataFI.FullName };
            var c = repo.Diff.Compare(paths);
            Assert.AreEqual(1, c.Count(), "No change detected");
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions