Class UnifiedDiff


  • public class UnifiedDiff
    extends java.lang.Object
    Parses and applies diff files in git unified format.

    Supported diffs can be generated with:

       git diff --no-index --no-renames before/ after/
     

    Usage:

       UnifiedDiff diff = new UnifiedDiff(new File("/path/to/file.diff"));
       diff.apply(new File("source/dir"));
     
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void apply​(java.io.File directory, int prefix)
      Applies the diff to the given directory, stripping the "prefix" number of directories.
      UnifiedDiff invert()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FROM_FILE

        public static final java.util.regex.Pattern FROM_FILE
      • TO_FILE

        public static final java.util.regex.Pattern TO_FILE
      • CHUNK_SPEC

        public static final java.util.regex.Pattern CHUNK_SPEC
      • GIT_DIFF

        public static final java.util.regex.Pattern GIT_DIFF
      • DELETED_FILE

        public static final java.util.regex.Pattern DELETED_FILE
      • NEW_FILE

        public static final java.util.regex.Pattern NEW_FILE
    • Constructor Detail

      • UnifiedDiff

        public UnifiedDiff​(java.io.File file)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • UnifiedDiff

        public UnifiedDiff​(java.nio.file.Path path)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • UnifiedDiff

        public UnifiedDiff()
    • Method Detail

      • apply

        public void apply​(java.io.File directory,
                          int prefix)
                   throws java.io.IOException
        Applies the diff to the given directory, stripping the "prefix" number of directories.

        Equivalent to "patch -p[prefix]"

        Throws:
        java.io.IOException