Class RmCommand

  • All Implemented Interfaces:
    java.util.concurrent.Callable<DirCache>

    public class RmCommand
    extends GitCommand<DirCache>
    Remove files from the index and working directory (or optionally only from the index).

    It has setters for all supported options and arguments of this command and a call() method to finally execute the command. Each instance of this class should only be used for one invocation of the command (means: one call to call()).

    Examples (git is a Git instance):

    Remove file "test.txt" from both index and working directory:

     git.rm().addFilepattern("test.txt").call();
     

    Remove file "new.txt" from the index (but not from the working directory):

     git.rm().setCached(true).addFilepattern("new.txt").call();
     
    See Also:
    Git documentation about Rm
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean cached
      Only remove files from index, not from working directory
      private java.util.Collection<java.lang.String> filepatterns  
    • Constructor Summary

      Constructors 
      Constructor Description
      RmCommand​(Repository repo)
      Constructor for RmCommand.
    • Field Detail

      • filepatterns

        private java.util.Collection<java.lang.String> filepatterns
      • cached

        private boolean cached
        Only remove files from index, not from working directory
    • Constructor Detail

      • RmCommand

        public RmCommand​(Repository repo)
        Constructor for RmCommand.
        Parameters:
        repo - the Repository
    • Method Detail

      • addFilepattern

        public RmCommand addFilepattern​(java.lang.String filepattern)
        Add file name pattern of files to be removed
        Parameters:
        filepattern - repository-relative path of file to remove (with / as separator)
        Returns:
        this
      • setCached

        public RmCommand setCached​(boolean cached)
        Only remove the specified files from the index.
        Parameters:
        cached - true if files should only be removed from index, false if files should also be deleted from the working directory
        Returns:
        this
        Since:
        2.2
      • delete

        private boolean delete​(java.io.File p)