Interface GitWorkTree
- All Superinterfaces:
AutoCloseable
Represents a
git repository work tree that can be used to create new commits. The basic flow for
creating one or more commits is as follows:
- Create a new
GitWorkTreeBuilderusingGitWorkTreeBuilderFactory.builder(Repository)for the repository in question. - Specify the
committhe work tree should check out andexecutethe change operation in the context of a temporaryGitWorkTree. The work tree on disk is automatically deleted after the operation completes. Edit, addfiles, or usebuilder()to manipulate the index directly thoughgitoperations such asrmandmvand to create new commits.Publishthe HEAD commit of the work tree to the repository, specifying thetarget branchto update.
GitWorkTree is a temporary location on disk that is deleted after the change operation
completes, or when the GitWorkTree expires. Each GitWorkTree is configured
with an expiry to prevent stale work tree directories from building up
in case of system failures.- Since:
- 7.14
-
Method Summary
Modifier and TypeMethodDescriptionbuilder()voidclose()Closes and deletes the work treecom.atlassian.bitbucket.repository.RepositorybooleanvoidCreates a new directory, and all of its parent directories, atrelativePath.voidpublish(PublishGitWorkTreeParameters parameters) Fetches newly created commits into therepository, invokes any registered repository hooks and, if not vetoed, updates the requestedbranch.voidWrites to the file located atrelativePath.voidwriteFrom(String relativePath, Charset cs, com.atlassian.bitbucket.io.IoSupplier<Reader> contentSupplier) Writes to the file located atrelativePath.
-
Method Details
-
builder
- Returns:
- a new
GitWorkTreeCommandBuilderthat can be used to build and executegitoperations in the work tree - Throws:
IllegalStateException- if the work tree has beenclosedor hasexpired
-
close
void close()Closes and deletes the work tree- Specified by:
closein interfaceAutoCloseable
-
getExpiry
- Returns:
- the
Instantat which thisWorkTreeexpires and becomes available for clean up
-
getRepository
@Nonnull com.atlassian.bitbucket.repository.Repository getRepository()- Returns:
- the repository for which the work tree was created
-
isExpired
boolean isExpired()- Returns:
trueif thisWorkTreehas expired and is available for clean up
-
publish
Fetches newly created commits into therepository, invokes any registered repository hooks and, if not vetoed, updates the requestedbranch.- Parameters:
parameters- describes whichRepositoryHookRequestto create and what refs to update- Throws:
IllegalStateException- if the work tree has beenclosedor hasexpired
-
mkdir
Creates a new directory, and all of its parent directories, atrelativePath. If a directory already exists atrelativePath, the method simply returns.- Parameters:
relativePath- the path at which a directory should be created, relative to the repository root- Throws:
FileAlreadyExistsException- ifrelativePathexists but is not a directoryIOException- if an I/O error occursIllegalStateException- if the work tree has beenclosedor hasexpired
-
write
void write(@Nonnull String relativePath, @Nonnull Charset cs, @Nonnull com.atlassian.bitbucket.io.IoConsumer<Writer> callback) throws IOException Writes to the file located atrelativePath.If file already exists, its contents will be overwritten.
- Parameters:
relativePath- the path, relative to the work tree root, of the file to editcs- theCharsetwith which to open theWritercallback- callback to hand theWriterto- Throws:
IOException- if themutatorfails, or ifrelativePathexists, but cannot be openedIllegalStateException- if the work tree has beenclosedor hasexpired
-
writeFrom
void writeFrom(@Nonnull String relativePath, @Nonnull Charset cs, @Nonnull com.atlassian.bitbucket.io.IoSupplier<Reader> contentSupplier) throws IOException Writes to the file located atrelativePath.If file already exists, its contents will be overwritten.
- Parameters:
relativePath- the path, relative to the work tree root, of the file to editcs- theCharsetto use when writing the filecontentSupplier- supplier of aReaderfrom which the new contents should be read- Throws:
IOException- if themutatorfails, or ifrelativePathexists, but cannot be openedIllegalStateException- if the work tree has beenclosedor hasexpired
-