Class CleanCommand

  • All Implemented Interfaces:
    java.util.concurrent.Callable<java.util.Set<java.lang.String>>

    public class CleanCommand
    extends GitCommand<java.util.Set<java.lang.String>>
    Remove untracked files from the working tree
    See Also:
    Git documentation about Clean
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean directories  
      private boolean dryRun  
      private boolean force  
      private boolean ignore  
      private java.util.Set<java.lang.String> paths  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected CleanCommand​(Repository repo)
      Constructor for CleanCommand
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set<java.lang.String> call()
      private java.util.Set<java.lang.String> cleanPath​(java.lang.String path, java.util.Set<java.lang.String> inFiles)
      When dryRun is false, deletes the specified path from disk.
      private java.util.Set<java.lang.String> filterFolders​(java.util.Set<java.lang.String> untracked, java.util.Set<java.lang.String> untrackedFolders)  
      private java.util.Set<java.lang.String> filterIgnorePaths​(java.util.Set<java.lang.String> inputPaths, java.util.Set<java.lang.String> ignoredNotInIndex, boolean exact)  
      CleanCommand setCleanDirectories​(boolean dirs)
      If dirs is set, in addition to files, also clean directories.
      CleanCommand setDryRun​(boolean dryRun)
      If dryRun is set, the paths in question will not actually be deleted.
      CleanCommand setForce​(boolean force)
      If force is set, directories that are git repositories will also be deleted.
      CleanCommand setIgnore​(boolean ignore)
      If ignore is set, don't report/clean files/directories that are ignored by a .gitignore.
      CleanCommand setPaths​(java.util.Set<java.lang.String> paths)
      If paths are set, only these paths are affected by the cleaning.
      • Methods inherited from class java.lang.Object

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

      • paths

        private java.util.Set<java.lang.String> paths
      • dryRun

        private boolean dryRun
      • directories

        private boolean directories
      • ignore

        private boolean ignore
      • force

        private boolean force
    • Constructor Detail

      • CleanCommand

        protected CleanCommand​(Repository repo)
        Constructor for CleanCommand
        Parameters:
        repo - the Repository
    • Method Detail

      • call

        public java.util.Set<java.lang.String> call()
                                             throws NoWorkTreeException,
                                                    GitAPIException

        Execute the command

        Executes the clean command with all the options and parameters collected by the setter methods of this class. Each instance of this class should only be used for one invocation of the command (means: one call to call())

        Specified by:
        call in interface java.util.concurrent.Callable<java.util.Set<java.lang.String>>
        Specified by:
        call in class GitCommand<java.util.Set<java.lang.String>>
        Throws:
        NoWorkTreeException
        GitAPIException
      • cleanPath

        private java.util.Set<java.lang.String> cleanPath​(java.lang.String path,
                                                          java.util.Set<java.lang.String> inFiles)
                                                   throws java.io.IOException
        When dryRun is false, deletes the specified path from disk. If dryRun is true, no paths are actually deleted. In both cases, the paths that would have been deleted are added to inFiles and returned. Paths that are directories are recursively deleted when directories is true. Paths that are git repositories are recursively deleted when directories and force are both true.
        Parameters:
        path - The path to be cleaned
        inFiles - A set of strings representing the files that have been cleaned already, the path to be cleaned will be added to this set before being returned.
        Returns:
        a set of strings with the cleaned path added to it
        Throws:
        java.io.IOException
      • filterIgnorePaths

        private java.util.Set<java.lang.String> filterIgnorePaths​(java.util.Set<java.lang.String> inputPaths,
                                                                  java.util.Set<java.lang.String> ignoredNotInIndex,
                                                                  boolean exact)
      • filterFolders

        private java.util.Set<java.lang.String> filterFolders​(java.util.Set<java.lang.String> untracked,
                                                              java.util.Set<java.lang.String> untrackedFolders)
      • setPaths

        public CleanCommand setPaths​(java.util.Set<java.lang.String> paths)
        If paths are set, only these paths are affected by the cleaning.
        Parameters:
        paths - the paths to set (with / as separator)
        Returns:
        this
      • setDryRun

        public CleanCommand setDryRun​(boolean dryRun)
        If dryRun is set, the paths in question will not actually be deleted.
        Parameters:
        dryRun - whether to do a dry run or not
        Returns:
        this
      • setForce

        public CleanCommand setForce​(boolean force)
        If force is set, directories that are git repositories will also be deleted.
        Parameters:
        force - whether or not to delete git repositories
        Returns:
        this
        Since:
        4.5
      • setCleanDirectories

        public CleanCommand setCleanDirectories​(boolean dirs)
        If dirs is set, in addition to files, also clean directories.
        Parameters:
        dirs - whether to clean directories too, or only files.
        Returns:
        this
      • setIgnore

        public CleanCommand setIgnore​(boolean ignore)
        If ignore is set, don't report/clean files/directories that are ignored by a .gitignore. otherwise do handle them.
        Parameters:
        ignore - whether to respect .gitignore or not.
        Returns:
        this