Skip to content

findSimilar

Transform a diff marking file renames, copies, etc.

This modifies a diff in place, replacing old entries that look like renames or copies with new entries reflecting those changes. This also will, if requested, break modified files into add/remove pairs if the amount of change is above a threshold.

Signature

ts
class Diff {
  findSimilar(options?: DiffFindOptions): void;
}

Parameters

  • optionsnull | DiffFindOptions

    Options for finding diff.

    • allboolean

      Turn on all finding features.

    • breakRewritesboolean

      Actually split large rewrites into delete/add pairs

    • breakRewritesForRenamesOnlyboolean

      Do not break rewrites unless they contribute to a rename. Normally, breakRewrites and rewrites will measure the self-similarity of modified files and split the ones that have changed a lot into a delete/add pair. Then the sides of that pair will be considered candidates for rename and copy detection If you add this flag in and the split pair is not used for an actual rename or copy, then the modified record will be restored to a regular modified record instead of being split.

    • breakRewriteThresholdnumber

      Similarity to split modify into delete/add pair (default 60)

    • copiesboolean

      Look for copies?

    • copiesFromUnmodifiedboolean

      Consider unmodified as copy sources? For this to work correctly, use includeUnmodified when the initial diff is being generated.

    • copyThresholdnumber

      Similarity to consider a file copy (default 50)

    • dontIgnoreWhitespaceboolean

      Measure similarity including all data

    • exactMatchOnlyboolean

      Measure similarity only by comparing SHAs (fast and cheap)

    • forUntrackedboolean

      Find renames/copies for untracked items in working directory. For this to work correctly use the includeUntracked option when the initial diff is being generated.

    • ignoreLeadingWhitespaceboolean

      Measure similarity ignoring leading whitespace (default)

    • ignoreWhitespaceboolean

      Measure similarity ignoring all whitespace

    • removeUnmodifiedboolean

      Remove any unmodified deltas after find_similar is done. Using copiesFromUnmodified to emulate the --find-copies-harder behavior requires building a diff with the includeUnmodified flag. If you do not want unmodified records in the final result, pas this flag to have them removed.

    • renameFromRewriteThresholdnumber

      Similarity of modified to be eligible rename source (default 50)

    • renameLimitnumber

      Maximum similarity sources to examine for a file (somewhat like git-diff's -l option or diff.renameLimit config) Defaults to 200

    • renamesboolean

      Look for renames?

    • renamesFromRewritesboolean

      Consider old side of modified for renames?

    • renameThresholdnumber

      Similarity to consider a file renamed (default 50)

    • rewritesboolean

      Mark significant rewrites for split.

Released under the MIT License.