Skip to content

diffTreeToWorkdirWithIndex

Create a diff between a tree and the working directory using index data to account for staged deletes, tracked files, etc.

This emulates git diff <tree> by diffing the tree to the index and the index to the working directory and blending the results into a single diff that includes staged deleted, etc.

Signature

ts
class Repository {
  diffTreeToWorkdirWithIndex(oldTree?: Tree, options?: DiffOptions): Diff;
}

Parameters

  • oldTreenull | Tree

    Tree used for the "oldFile" side of the delta. If you not pass, then an empty tree is used.

  • optionsnull | DiffOptions

    Describing options about how the diff should be executed.

    • contextLinesnumber

      Set the number of unchanged lines that define the boundary of a hunk (and to display before and after). The default value for this is 3.

    • disablePathspecMatchboolean

      If pathspecs are specified, this flag means that they should be applied as an exact match instead of a fnmatch pattern.

    • enableFastUntrackedDirsboolean

      When diff finds an untracked directory, to match the behavior of core Git, it scans the contents for ignored and untracked files. If all contents are ignored, then the directory is ignored; if any contents are not ignored, then the directory is untracked. This is extra work that may not matter in many cases. This flag turns off that scan and immediately labels an untracked directory as untracked (changing the behavior to not match core git).

    • forceBinaryboolean

      Treat all files as binary, disabling text diffs

    • forceTextboolean

      Treat all files as text, disabling binary attributes and detection.

    • idAbbrevnumber

      The default value for this is core.abbrev or 7 if unset.

    • ignoreBlankLinesboolean

      Ignore blank lines

    • ignoreCaseboolean

      Flag indicating whether case insensitive filenames should be used.

    • ignoreFilemodeboolean

      Flag indicating whether file mode changes are ignored.

    • ignoreSubmodulesboolean

      Flag indicating whether all submodules should be treated as unmodified.

    • ignoreWhitespaceboolean

      Ignore all whitespace

    • ignoreWhitespaceChangeboolean

      Ignore changes in the amount of whitespace

    • ignoreWhitespaceEolboolean

      Ignore whitespace at the end of line

    • includeIgnoredboolean

      Flag indicating whether ignored files are included.

    • includeTypechangeboolean

      If enabled, then Typechange delta records are generated.

    • includeTypechangeTreesboolean

      Event with includeTypechange, the tree returned generally shows a deleted blob. This flag correctly labels the tree transitions as a typechange record with the newFile's mode set to tree. Note that the tree SHA will not be available.

    • includeUnmodifiedboolean

      Flag indicating whether unmodified files are in the diff.

    • includeUnreadableboolean

      Include unreadable files in the diff

    • includeUnreadableAsUntrackedboolean

      Include unreadable files in the diff as untracked files

    • includeUntrackedboolean

      Flag indicating whether untracked files are in the diff

    • indentHeuristicboolean

      Use a heuristic that takes indentation and whitespace into account which generally can produce better diffs when dealing with ambiguous diff hunks.

    • interhunkLinesnumber

      Set the maximum number of unchanged lines between hunk boundaries before the hunks will be merged into one. The default value for this is 0.

    • maxSizenumber

      Maximum size (in bytes) above which a blob will be marked as binary automatically. A negative value will disable this entirely. The default value for this is 512MB.

    • minimalboolean

      Take extra time to find the minimal diff

    • newPrefixstring

      The virtual "directory" to prefix new file names with in hunk headers. The default value for this is "b".

    • oldPrefixstring

      The virtual "directory" to prefix old file names with in hunk headers. The default value for this is "a".

    • pathspecsstring[]

      Add to the array of paths/fnmatch patterns to constrain the diff.

    • patienceboolean

      Use the "patience diff" algorithm

    • recurseIgnoredDirsboolean

      Flag indicating whether ignored directories are traversed deeply or not.

    • recurseUntrackedDirsboolean

      Flag indicating whether untracked directories are traversed deeply or not.

    • reverseboolean

      Flag indicating whether the sides of the diff will be reversed.

    • showBinaryboolean

      Include the necessary deflate/delta information so that git-apply can apply given diff information to binary files.

    • showUnmodifiedboolean

      When generating output, include the names of unmodified files if they are included in the Diff. Normally these are skipped in the formats that list files (e.g. name-only, name-status, raw). Even with this these will not be included in the patch format.

    • showUntrackedContentboolean

      When generating patch text, include the content of untracked files. This automatically turns on includeUntracked but it does not turn on recurseUntrackedDirs. Add that flag if you want the content of every single untracked file.

    • skipBinaryCheckboolean

      Disable updating the binary flag in delta records. This is useful when iterating over a diff if you don't need hunk and data callbacks and want to avoid having to load a file completely.

    • updateIndexboolean

      When diff finds a file in the working directory with stat information different from the index, but the OID ends up being the same, write the correct stat information into the index. Note: without this flag, diff will always leave the index untouched.

Returns

  • Diff

    Diff between a tree and the working directory using index data to account for
    staged deletes, tracked files, etc.

Released under the MIT License.