Interface GitWorkTree

All Superinterfaces:
AutoCloseable

public interface GitWorkTree extends 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: Note that a 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 Details

    • builder

      @Nonnull GitWorkTreeCommandBuilder builder()
      Returns:
      a new GitWorkTreeCommandBuilder that can be used to build and execute git operations in the work tree
      Throws:
      IllegalStateException - if the work tree has been closed or has expired
    • close

      void close()
      Closes and deletes the work tree
      Specified by:
      close in interface AutoCloseable
    • getExpiry

      @Nonnull Instant getExpiry()
      Returns:
      the Instant at which this WorkTree expires 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:
      true if this WorkTree has expired and is available for clean up
    • publish

      void publish(@Nonnull PublishGitWorkTreeParameters parameters)
      Fetches newly created commits into the repository, invokes any registered repository hooks and, if not vetoed, updates the requested branch.
      Parameters:
      parameters - describes which RepositoryHookRequest to create and what refs to update
      Throws:
      IllegalStateException - if the work tree has been closed or has expired
    • mkdir

      void mkdir(@Nonnull String relativePath) throws IOException
      Creates a new directory, and all of its parent directories, at relativePath. If a directory already exists at relativePath, the method simply returns.
      Parameters:
      relativePath - the path at which a directory should be created, relative to the repository root
      Throws:
      FileAlreadyExistsException - if relativePath exists but is not a directory
      IOException - if an I/O error occurs
      IllegalStateException - if the work tree has been closed or has expired
    • write

      void write(@Nonnull String relativePath, @Nonnull Charset cs, @Nonnull com.atlassian.bitbucket.io.IoConsumer<Writer> callback) throws IOException
      Writes to the file located at relativePath.

      If file already exists, its contents will be overwritten.

      Parameters:
      relativePath - the path, relative to the work tree root, of the file to edit
      cs - the Charset with which to open the Writer
      callback - callback to hand the Writer to
      Throws:
      IOException - if the mutator fails, or if relativePath exists, but cannot be opened
      IllegalStateException - if the work tree has been closed or has expired
    • writeFrom

      void writeFrom(@Nonnull String relativePath, @Nonnull Charset cs, @Nonnull com.atlassian.bitbucket.io.IoSupplier<Reader> contentSupplier) throws IOException
      Writes to the file located at relativePath.

      If file already exists, its contents will be overwritten.

      Parameters:
      relativePath - the path, relative to the work tree root, of the file to edit
      cs - the Charset to use when writing the file
      contentSupplier - supplier of a Reader from which the new contents should be read
      Throws:
      IOException - if the mutator fails, or if relativePath exists, but cannot be opened
      IllegalStateException - if the work tree has been closed or has expired