org.eclipse.jgit.dircache

## Class DirCacheCheckout

- java.lang.Object
- - org.eclipse.jgit.dircache.DirCacheCheckout

    public class DirCacheCheckout
    extends Object

This class handles checking out one or two trees merging with the index.

### Constructor Summary

Constructors
Constructor and Description
`DirCacheCheckout(Repository repo, DirCache dc, ObjectId mergeCommitTree)` Constructs a DirCacheCeckout for checking out one tree, merging with the index.
`DirCacheCheckout(Repository repo, DirCache dc, ObjectId mergeCommitTree, WorkingTreeIterator workingTree)` Constructs a DirCacheCeckout for checking out one tree, merging with the index.
`DirCacheCheckout(Repository repo, ObjectId headCommitTree, DirCache dc, ObjectId mergeCommitTree)` Constructs a DirCacheCeckout for merging and checking out two trees (HEAD and mergeCommitTree) and the index.
`DirCacheCheckout(Repository repo, ObjectId headCommitTree, DirCache dc, ObjectId mergeCommitTree, WorkingTreeIterator workingTree)` Constructs a DirCacheCeckout for merging and checking out two trees (HEAD and mergeCommitTree) and the index.

### Method Summary

Methods
`boolean` `checkout()` Execute this checkout
`static void` `checkoutEntry(Repository repository, File f, DirCacheEntry entry)` Updates the file in the working tree with content and mode from an entry in the index.
`static void` `checkoutEntry(Repository repo, File f, DirCacheEntry entry, ObjectReader or)` Updates the file in the working tree with content and mode from an entry in the index.
`static void` `checkValidPath(String path)` Check if path is a valid path for a checked out file name or ref name.
`List<String>` `getConflicts()`
`List<String>` `getRemoved()`
`List<String>` `getToBeDeleted()`
`Map<String,ObjectId>` `getUpdated()`
`void` `prescanOneTree()` Scan index and merge tree (no HEAD).
`void` `preScanTwoTrees()` Scan head, index and merge tree.
`void` `setFailOnConflict(boolean failOnConflict)` If `true`, will scan first to see if it's possible to check out, otherwise throw `CheckoutConflictException`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### 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

#### preScanTwoTrees

    public void preScanTwoTrees()
                         throws CorruptObjectException,
                                IOException

Scan head, index and merge tree. Used during normal checkout or merge operations.

Throws:
  `CorruptObjectException`
  `IOException`

#### prescanOneTree

    public void prescanOneTree()
                        throws MissingObjectException,
                               IncorrectObjectTypeException,
                               CorruptObjectException,
                               IOException

Scan index and merge tree (no HEAD). Used e.g. for initial checkout when there is no head yet.

Throws:
  `MissingObjectException`
  `IncorrectObjectTypeException`
  `CorruptObjectException`
  `IOException`

#### 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

    public static void checkoutEntry(Repository repository,
                     File f,
                     DirCacheEntry entry)
                              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. 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` - the file to be modified. The parent directory for this file has to exist already
  `entry` - the entry containing new mode and content
Throws:
  `IOException`

#### checkoutEntry

    public static void checkoutEntry(Repository repo,
                     File f,
                     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` -
  `f` - the file to be modified. The parent directory for this file has to exist already
  `entry` - the entry containing new mode and content
  `or` - object reader to use for checkout
Throws:
  `IOException`

#### checkValidPath

    public static void checkValidPath(String path)
                               throws InvalidPathException

Check if path is a valid path for a checked out file name or ref name.

Parameters:
  `path` -
Throws:
  `InvalidPathException` - if the path is invalid
Since:
  3.3