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

      • getUpdated

        public Map<String,​ObjectId> getUpdated()
        Returns:
        a list of updated paths and objectIds
      • getConflicts

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

        public List<String> getToBeDeleted()
        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()
        Returns:
        a list of all files removed by this checkout
      • checkout

        public boolean checkout()
                         throws IOException
        Execute this checkout
        Returns:
        false if this method could not delete all the files which should be deleted (e.g. because of 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 -
      • checkoutEntry

        @Deprecated
        public static void checkoutEntry​(Repository repository,
                                         File f,
                                         DirCacheEntry entry)
                                  throws IOException
        Deprecated.
        Use the overloaded form that accepts ObjectReader.
        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. Use this method only for checkout of a single entry. Otherwise use checkoutEntry(Repository, File f, DirCacheEntry, ObjectReader) instead which allows to reuse one ObjectReader for multiple entries.

        TODO: this method works directly on File IO, we may need another abstraction (like WorkingTreeIterator). This way we could tell e.g. Eclipse that Files in the workspace got changed

        Parameters:
        repository -
        f - this parameter is ignored.
        entry - the entry containing new mode and content
        Throws:
        IOException
      • checkoutEntry

        @Deprecated
        public static void checkoutEntry​(Repository repo,
                                         File f,
                                         DirCacheEntry entry,
                                         ObjectReader or)
                                  throws IOException
        Deprecated.
        Do not pass File object.
        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.

        TODO: this method works directly on File IO, we may need another abstraction (like WorkingTreeIterator). This way we could tell e.g. Eclipse that Files in the workspace got changed

        Parameters:
        repo -
        f - this parameter is ignored.
        entry - the entry containing new mode and content
        or - object reader to use for checkout
        Throws:
        IOException
      • checkoutEntry

        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.

        TODO: this method works directly on File IO, we may need another abstraction (like WorkingTreeIterator). This way we could tell e.g. Eclipse that Files in the workspace got changed

        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