Class DirCacheCheckout


  • public class DirCacheCheckout
    extends Object
    This class handles checking out one or two trees merging with the index.
    • Constructor Detail

      • DirCacheCheckout

        public DirCacheCheckout​(Repository repo,
                                ObjectId headCommitTree,
                                DirCache dc,
                                ObjectId mergeCommitTree,
                                WorkingTreeIterator workingTree)
                         throws IOException
        Constructs a DirCacheCeckout for merging and checking out two trees (HEAD and mergeCommitTree) and the index.
        Parameters:
        repo - the repository in which we do the checkout
        headCommitTree - the id of the tree of the head commit
        dc - the (already locked) Dircache for this repo
        mergeCommitTree - the id of the tree we want to fast-forward to
        workingTree - an iterator over the repositories Working Tree
        Throws:
        IOException
      • DirCacheCheckout

        public DirCacheCheckout​(Repository repo,
                                ObjectId headCommitTree,
                                DirCache dc,
                                ObjectId mergeCommitTree)
                         throws IOException
        Constructs a DirCacheCeckout for merging and checking out two trees (HEAD and mergeCommitTree) and the index. As iterator over the working tree this constructor creates a standard FileTreeIterator
        Parameters:
        repo - the repository in which we do the checkout
        headCommitTree - the id of the tree of the head commit
        dc - the (already locked) Dircache for this repo
        mergeCommitTree - the id of the tree we want to fast-forward to
        Throws:
        IOException
      • DirCacheCheckout

        public DirCacheCheckout​(Repository repo,
                                DirCache dc,
                                ObjectId mergeCommitTree,
                                WorkingTreeIterator workingTree)
                         throws IOException
        Constructs a DirCacheCeckout for checking out one tree, merging with the index.
        Parameters:
        repo - the repository in which we do the checkout
        dc - the (already locked) Dircache for this repo
        mergeCommitTree - the id of the tree we want to fast-forward to
        workingTree - an iterator over the repositories Working Tree
        Throws:
        IOException
      • DirCacheCheckout

        public DirCacheCheckout​(Repository repo,
                                DirCache dc,
                                ObjectId mergeCommitTree)
                         throws IOException
        Constructs a DirCacheCeckout for checking out one tree, merging with the index. As iterator over the working tree this constructor creates a standard FileTreeIterator
        Parameters:
        repo - the repository in which we do the checkout
        dc - the (already locked) Dircache for this repo
        mergeCommitTree - the id of the tree of the
        Throws:
        IOException
    • Method Detail

      • getConflicts

        public List<String> getConflicts()
        Get a list of conflicts created by this checkout
        Returns:
        a list of conflicts created by this checkout
      • getToBeDeleted

        public List<String> getToBeDeleted()
        Get list of paths of files which couldn't be deleted during last call to checkout()
        Returns:
        a list of paths (relative to the start of the working tree) of files which couldn't be deleted during last call to checkout() . checkout() detected that these files should be deleted but the deletion in the filesystem failed (e.g. because a file was locked). To have a consistent state of the working tree these files have to be deleted by the callers of DirCacheCheckout.
      • getRemoved

        public List<String> getRemoved()
        Get list of all files removed by this checkout
        Returns:
        a list of all files removed by this checkout
      • setProgressMonitor

        public void setProgressMonitor​(ProgressMonitor monitor)
        Set a progress monitor which can be passed to built-in filter commands, providing progress information for long running tasks.
        Parameters:
        monitor - the ProgressMonitor
        Since:
        4.11
      • checkout

        public boolean checkout()
                         throws IOException
        Execute this checkout. A WorkingTreeModifiedEvent is fired if the working tree was modified; even if the checkout fails.
        Returns:
        false if this method could not delete all the files which should be deleted (e.g. because one of the files was locked). In this case getToBeDeleted() lists the files which should be tried to be deleted outside of this method. Although false is returned the checkout was successful and the working tree was updated for all other files. true is returned when no such problem occurred
        Throws:
        IOException
      • setFailOnConflict

        public void setFailOnConflict​(boolean failOnConflict)
        If true, will scan first to see if it's possible to check out, otherwise throw CheckoutConflictException. If false, it will silently deal with the problem.
        Parameters:
        failOnConflict - a boolean.
      • setForce

        public void setForce​(boolean force)
        If true, dirty worktree files may be overridden. If false dirty worktree files will not be overridden in order not to delete unsaved content. This corresponds to native git's 'git checkout -f' option. By default this option is set to false.
        Parameters:
        force - a boolean.
        Since:
        5.3
      • checkoutEntry

        @Deprecated
        public static void checkoutEntry​(Repository repo,
                                         DirCacheEntry entry,
                                         ObjectReader or)
                                  throws IOException
        Updates the file in the working tree with content and mode from an entry in the index. The new content is first written to a new temporary file in the same directory as the real file. Then that new file is renamed to the final filename.

        Note: if the entry path on local file system exists as a non-empty directory, and the target entry type is a link or file, the checkout will fail with IOException since existing non-empty directory cannot be renamed to file or link without deleting it recursively.

        Parameters:
        repo - repository managing the destination work tree.
        entry - the entry containing new mode and content
        or - object reader to use for checkout
        Throws:
        IOException
        Since:
        3.6
      • checkoutEntry

        @Deprecated
        public static void checkoutEntry​(Repository repo,
                                         DirCacheEntry entry,
                                         ObjectReader or,
                                         boolean deleteRecursive,
                                         DirCacheCheckout.CheckoutMetadata checkoutMetadata)
                                  throws IOException
        Updates the file in the working tree with content and mode from an entry in the index. The new content is first written to a new temporary file in the same directory as the real file. Then that new file is renamed to the final filename.

        Note: if the entry path on local file system exists as a file, it will be deleted and if it exists as a directory, it will be deleted recursively, independently if has any content.

        Parameters:
        repo - repository managing the destination work tree.
        entry - the entry containing new mode and content
        or - object reader to use for checkout
        deleteRecursive - true to recursively delete final path if it exists on the file system
        checkoutMetadata - containing
        • smudgeFilterCommand to be run for smudging the entry to be checked out
        • eolStreamType used for stream conversion
        Throws:
        IOException
        Since:
        4.2
      • checkoutEntry

        public static void checkoutEntry​(Repository repo,
                                         DirCacheEntry entry,
                                         ObjectReader or,
                                         boolean deleteRecursive,
                                         DirCacheCheckout.CheckoutMetadata checkoutMetadata,
                                         WorkingTreeOptions options)
                                  throws IOException
        Updates the file in the working tree with content and mode from an entry in the index. The new content is first written to a new temporary file in the same directory as the real file. Then that new file is renamed to the final filename.

        Note: if the entry path on local file system exists as a file, it will be deleted and if it exists as a directory, it will be deleted recursively, independently if has any content.

        Parameters:
        repo - repository managing the destination work tree.
        entry - the entry containing new mode and content
        or - object reader to use for checkout
        deleteRecursive - true to recursively delete final path if it exists on the file system
        checkoutMetadata - containing
        • smudgeFilterCommand to be run for smudging the entry to be checked out
        • eolStreamType used for stream conversion
        options - WorkingTreeOptions that are effective; if null they are loaded from the repository config
        Throws:
        IOException
        Since:
        6.3
      • getContent

        public static void getContent​(Repository repo,
                                      String path,
                                      DirCacheCheckout.CheckoutMetadata checkoutMetadata,
                                      ObjectLoader ol,
                                      WorkingTreeOptions opt,
                                      OutputStream os)
                               throws IOException
        Return filtered content for a specific object (blob). EOL handling and smudge-filter handling are applied in the same way as it would be done during a checkout.
        Parameters:
        repo - the repository
        path - the path used to determine the correct filters for the object
        checkoutMetadata - containing
        • smudgeFilterCommand to be run for smudging the object
        • eolStreamType used for stream conversion (can be null)
        ol - the object loader to read raw content of the object
        opt - the working tree options where only 'core.autocrlf' is used for EOL handling if 'checkoutMetadata.eolStreamType' is not valid
        os - the output stream the filtered content is written to. The caller is responsible to close the stream.
        Throws:
        IOException
        Since:
        5.7
      • getContent

        public static void getContent​(Repository repo,
                                      String path,
                                      DirCacheCheckout.CheckoutMetadata checkoutMetadata,
                                      DirCacheCheckout.StreamSupplier inputStream,
                                      WorkingTreeOptions opt,
                                      OutputStream os)
                               throws IOException
        Return filtered content for blob contents. EOL handling and smudge-filter handling are applied in the same way as it would be done during a checkout.
        Parameters:
        repo - the repository
        path - the path used to determine the correct filters for the object
        checkoutMetadata - containing
        • smudgeFilterCommand to be run for smudging the object
        • eolStreamType used for stream conversion (can be null)
        inputStream - A supplier for the raw content of the object. Each call should yield a fresh stream of the same object.
        opt - the working tree options where only 'core.autocrlf' is used for EOL handling if 'checkoutMetadata.eolStreamType' is not valid
        os - the output stream the filtered content is written to. The caller is responsible to close the stream.
        Throws:
        IOException
        Since:
        6.3