Class IndexDiff

java.lang.Object
org.eclipse.jgit.lib.IndexDiff

public class IndexDiff extends Object
Compares the index, a tree, and the working directory Ignored files are not taken into account. The following information is retrieved:
  • added files
  • changed files
  • removed files
  • missing files
  • modified files
  • conflicting files
  • untracked files
  • files with assume-unchanged flag
  • Field Details

  • Constructor Details

    • IndexDiff

      public IndexDiff(Repository repository, String revstr, WorkingTreeIterator workingTreeIterator) throws IOException
      Construct an IndexDiff
      Parameters:
      repository - a Repository object.
      revstr - symbolic name e.g. HEAD An EmptyTreeIterator is used if revstr cannot be resolved.
      workingTreeIterator - iterator for working directory
      Throws:
      IOException
    • IndexDiff

      public IndexDiff(Repository repository, ObjectId objectId, WorkingTreeIterator workingTreeIterator) throws IOException
      Construct an Indexdiff
      Parameters:
      repository - a Repository object.
      objectId - tree id. If null, an EmptyTreeIterator is used.
      workingTreeIterator - iterator for working directory
      Throws:
      IOException
  • Method Details

    • setIgnoreSubmoduleMode

      public void setIgnoreSubmoduleMode(SubmoduleWalk.IgnoreSubmoduleMode mode)
      Defines how modifications in submodules are treated
      Parameters:
      mode - defines how modifications in submodules are treated
      Since:
      3.6
    • setWorkingTreeItFactory

      public void setWorkingTreeItFactory(IndexDiff.WorkingTreeIteratorFactory wTreeIt)
      Allows higher layers to set the factory for WorkingTreeIterators.
      Parameters:
      wTreeIt -
      Since:
      3.6
    • setFilter

      public void setFilter(TreeFilter filter)
      Sets a filter. Can be used e.g. for restricting the tree walk to a set of files.
      Parameters:
      filter - a TreeFilter object.
    • diff

      public boolean diff() throws IOException
      Run the diff operation. Until this is called, all lists will be empty. Use diff(ProgressMonitor, int, int, String) if a progress monitor is required.
      Returns:
      if anything is different between index, tree, and workdir
      Throws:
      IOException
    • diff

      public boolean diff(RepositoryBuilderFactory factory) throws IOException
      Run the diff operation. Until this is called, all lists will be empty. Use diff(ProgressMonitor, int, int, String, RepositoryBuilderFactory) if a progress monitor is required.

      The operation may create repositories for submodules using builders provided by the given factory, if any, and will also close these submodule repositories again.

      Parameters:
      factory - the RepositoryBuilderFactory to use to create builders to create submodule repositories, if needed; if null, submodule repositories will be built using a plain RepositoryBuilder.
      Returns:
      if anything is different between index, tree, and workdir
      Throws:
      IOException
      Since:
      5.6
    • diff

      public boolean diff(ProgressMonitor monitor, int estWorkTreeSize, int estIndexSize, String title) throws IOException
      Run the diff operation. Until this is called, all lists will be empty.

      The operation may be aborted by the progress monitor. In that event it will report what was found before the cancel operation was detected. Callers should ignore the result if monitor.isCancelled() is true. If a progress monitor is not needed, callers should use diff() instead. Progress reporting is crude and approximate and only intended for informing the user.

      Parameters:
      monitor - for reporting progress, may be null
      estWorkTreeSize - number or estimated files in the working tree
      estIndexSize - number of estimated entries in the cache
      title - a String object.
      Returns:
      if anything is different between index, tree, and workdir
      Throws:
      IOException
    • diff

      public boolean diff(ProgressMonitor monitor, int estWorkTreeSize, int estIndexSize, String title, RepositoryBuilderFactory factory) throws IOException
      Run the diff operation. Until this is called, all lists will be empty.

      The operation may be aborted by the progress monitor. In that event it will report what was found before the cancel operation was detected. Callers should ignore the result if monitor.isCancelled() is true. If a progress monitor is not needed, callers should use diff() instead. Progress reporting is crude and approximate and only intended for informing the user.

      The operation may create repositories for submodules using builders provided by the given factory, if any, and will also close these submodule repositories again.

      Parameters:
      monitor - for reporting progress, may be null
      estWorkTreeSize - number or estimated files in the working tree
      estIndexSize - number of estimated entries in the cache
      title - a String object.
      factory - the RepositoryBuilderFactory to use to create builders to create submodule repositories, if needed; if null, submodule repositories will be built using a plain RepositoryBuilder.
      Returns:
      if anything is different between index, tree, and workdir
      Throws:
      IOException
      Since:
      5.6
    • hasFiles

      private boolean hasFiles(File directory)
    • recordFileMode

      private void recordFileMode(String path, FileMode mode)
    • isEntryGitLink

      private boolean isEntryGitLink(AbstractTreeIterator ti)
    • addConflict

      private void addConflict(String path, int stage)
    • getAdded

      public Set<String> getAdded()
      Get list of files added to the index, not in the tree
      Returns:
      list of files added to the index, not in the tree
    • getChanged

      public Set<String> getChanged()
      Get list of files changed from tree to index
      Returns:
      list of files changed from tree to index
    • getRemoved

      public Set<String> getRemoved()
      Get list of files removed from index, but in tree
      Returns:
      list of files removed from index, but in tree
    • getMissing

      public Set<String> getMissing()
      Get list of files in index, but not filesystem
      Returns:
      list of files in index, but not filesystem
    • getModified

      public Set<String> getModified()
      Get list of files modified on disk relative to the index
      Returns:
      list of files modified on disk relative to the index
    • getUntracked

      public Set<String> getUntracked()
      Get list of files that are not ignored, and not in the index.
      Returns:
      list of files that are not ignored, and not in the index.
    • getConflicting

      public Set<String> getConflicting()
      Get list of files that are in conflict, corresponds to the keys of getConflictingStageStates()
      Returns:
      list of files that are in conflict, corresponds to the keys of getConflictingStageStates()
    • getConflictingStageStates

      public Map<String,IndexDiff.StageState> getConflictingStageStates()
      Get the map from each path of getConflicting() to its corresponding IndexDiff.StageState
      Returns:
      the map from each path of getConflicting() to its corresponding IndexDiff.StageState
      Since:
      3.0
    • getIgnoredNotInIndex

      public Set<String> getIgnoredNotInIndex()
      The method returns the list of ignored files and folders. Only the root folder of an ignored folder hierarchy is reported. If a/b/c is listed in the .gitignore then you should not expect a/b/c/d/e/f to be reported here. Only a/b/c will be reported. Furthermore only ignored files / folders are returned that are NOT in the index.
      Returns:
      list of files / folders that are ignored
    • getAssumeUnchanged

      public Set<String> getAssumeUnchanged()
      Get list of files with the flag assume-unchanged
      Returns:
      list of files with the flag assume-unchanged
    • getUntrackedFolders

      public Set<String> getUntrackedFolders()
      Get list of folders containing only untracked files/folders
      Returns:
      list of folders containing only untracked files/folders
    • getIndexMode

      public FileMode getIndexMode(String path)
      Get the file mode of the given path in the index
      Parameters:
      path - a String object.
      Returns:
      file mode
    • getPathsWithIndexMode

      public Set<String> getPathsWithIndexMode(FileMode mode)
      Get the list of paths that IndexDiff has detected to differ and have the given file mode
      Parameters:
      mode - a FileMode object.
      Returns:
      the list of paths that IndexDiff has detected to differ and have the given file mode
      Since:
      3.6