Package 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DirCacheCheckout.CheckoutMetadata
Metadata used in checkout processstatic interface
DirCacheCheckout.StreamSupplier
Something that can supply anInputStream
.
-
Constructor Summary
Constructors Constructor 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
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
checkout()
Execute this checkout.static void
checkoutEntry(Repository repo, DirCacheEntry entry, ObjectReader or)
Deprecated.static void
checkoutEntry(Repository repo, DirCacheEntry entry, ObjectReader or, boolean deleteRecursive, DirCacheCheckout.CheckoutMetadata checkoutMetadata)
Deprecated.static void
checkoutEntry(Repository repo, DirCacheEntry entry, ObjectReader or, boolean deleteRecursive, DirCacheCheckout.CheckoutMetadata checkoutMetadata, WorkingTreeOptions options)
Updates the file in the working tree with content and mode from an entry in the index.List<String>
getConflicts()
Get a list of conflicts created by this checkoutstatic void
getContent(Repository repo, String path, DirCacheCheckout.CheckoutMetadata checkoutMetadata, DirCacheCheckout.StreamSupplier inputStream, WorkingTreeOptions opt, OutputStream os)
Return filtered content for blob contents.static void
getContent(Repository repo, String path, DirCacheCheckout.CheckoutMetadata checkoutMetadata, ObjectLoader ol, WorkingTreeOptions opt, OutputStream os)
Return filtered content for a specific object (blob).List<String>
getRemoved()
Get list of all files removed by this checkoutList<String>
getToBeDeleted()
Get list of paths of files which couldn't be deleted during last call tocheckout()
Map<String,DirCacheCheckout.CheckoutMetadata>
getUpdated()
Get list of updated paths and smudgeFilterCommandsvoid
prescanOneTree()
Scan index and merge tree (no HEAD).void
preScanTwoTrees()
Scan head, index and merge tree.void
setFailOnConflict(boolean failOnConflict)
Iftrue
, will scan first to see if it's possible to check out, otherwise throwCheckoutConflictException
.void
setForce(boolean force)
Iftrue
, dirty worktree files may be overridden.void
setProgressMonitor(ProgressMonitor monitor)
Set a progress monitor which can be passed to built-in filter commands, providing progress information for long running tasks.
-
-
-
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 checkoutheadCommitTree
- the id of the tree of the head commitdc
- the (already locked) Dircache for this repomergeCommitTree
- the id of the tree we want to fast-forward toworkingTree
- 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 standardFileTreeIterator
- Parameters:
repo
- the repository in which we do the checkoutheadCommitTree
- the id of the tree of the head commitdc
- the (already locked) Dircache for this repomergeCommitTree
- 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 checkoutdc
- the (already locked) Dircache for this repomergeCommitTree
- the id of the tree we want to fast-forward toworkingTree
- 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 standardFileTreeIterator
- Parameters:
repo
- the repository in which we do the checkoutdc
- the (already locked) Dircache for this repomergeCommitTree
- the id of the tree of the- Throws:
IOException
-
-
Method Detail
-
getUpdated
public Map<String,DirCacheCheckout.CheckoutMetadata> getUpdated()
Get list of updated paths and smudgeFilterCommands- Returns:
- a list of updated paths and smudgeFilterCommands
-
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 tocheckout()
- 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 ofDirCacheCheckout
.
-
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
- theProgressMonitor
- Since:
- 4.11
-
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.
-
checkout
public boolean checkout() throws IOException
Execute this checkout. AWorkingTreeModifiedEvent
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 casegetToBeDeleted()
lists the files which should be tried to be deleted outside of this method. Althoughfalse
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)
Iftrue
, will scan first to see if it's possible to check out, otherwise throwCheckoutConflictException
. Iffalse
, it will silently deal with the problem.- Parameters:
failOnConflict
- a boolean.
-
setForce
public void setForce(boolean force)
Iftrue
, dirty worktree files may be overridden. Iffalse
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
Deprecated.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 contentor
- 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
Deprecated.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 contentor
- object reader to use for checkoutdeleteRecursive
- true to recursively delete final path if it exists on the file systemcheckoutMetadata
- 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 contentor
- object reader to use for checkoutdeleteRecursive
- true to recursively delete final path if it exists on the file systemcheckoutMetadata
- containing- smudgeFilterCommand to be run for smudging the entry to be checked out
- eolStreamType used for stream conversion
options
-WorkingTreeOptions
that are effective; ifnull
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 repositorypath
- the path used to determine the correct filters for the objectcheckoutMetadata
- 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 objectopt
- the working tree options where only 'core.autocrlf' is used for EOL handling if 'checkoutMetadata.eolStreamType' is not validos
- 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 repositorypath
- the path used to determine the correct filters for the objectcheckoutMetadata
- 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 validos
- the output stream the filtered content is written to. The caller is responsible to close the stream.- Throws:
IOException
- Since:
- 6.3
-
-