Interface Repositories

All Known Implementing Classes:
GitHub, RepositoriesImpl

public interface Repositories
Clones, updates and inspects a local checkout of a GitHub repository.

cloneOrPull(java.io.File, java.lang.String, java.lang.String, java.lang.String) honours its owner/repo arguments on every call, including the update path for a checkout that already exists, so calling it repeatedly for the same repository, or for different repositories from the same instance, is safe.

isUpToDate(java.io.File) takes no owner/repo argument; it derives the repository identity from the checkout at path itself, the same way remoteOf(java.io.File) does, rather than from whatever repository was configured when this instance was created.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    cloneOrPull(File target, String owner, String repo, String branch)
    Clones owner/repo into target if no checkout exists there yet, otherwise pulls the latest changes for branch (or the current branch, if null).
    void
    cloneOrPullFrom(File target, String cloneUrl, String branch)
    Clones or pulls cloneUrl into target, using the given URL directly rather than reconstructing one from an owner and repo, so any git host is honoured exactly as configured (github.com, GitHub Enterprise, or any other host).
    The owner and repository parsed from the implementation's own configured repository URL.
    boolean
    exists(File path)
     
    boolean
     
    remoteOf(File projectDir)
     
  • Method Details

    • cloneOrPull

      void cloneOrPull(File target, String owner, String repo, String branch) throws IOException
      Clones owner/repo into target if no checkout exists there yet, otherwise pulls the latest changes for branch (or the current branch, if null).
      Parameters:
      target - the local directory to clone into or pull within.
      owner - the GitHub account or organization that owns the repository.
      repo - the repository name, without the owner prefix.
      branch - the branch to clone or pull, or null for the current/default branch.
      Throws:
      IOException - if the clone or pull fails.
    • cloneOrPullFrom

      void cloneOrPullFrom(File target, String cloneUrl, String branch) throws IOException
      Clones or pulls cloneUrl into target, using the given URL directly rather than reconstructing one from an owner and repo, so any git host is honoured exactly as configured (github.com, GitHub Enterprise, or any other host).
      Parameters:
      target - the local directory to clone into or pull within.
      cloneUrl - the exact URL to clone from.
      branch - the branch to clone or pull, or null for the current/default branch.
      Throws:
      IOException - if the clone or pull fails.
    • exists

      boolean exists(File path)
      Parameters:
      path - the directory to check.
      Returns:
      true if a git repository checkout exists at path.
    • isUpToDate

      boolean isUpToDate(File path)
      Parameters:
      path - the checkout to check, whose own origin remote identifies the repository.
      Returns:
      true if path's current branch matches its remote counterpart, false if it is behind or the check itself fails (e.g. no network access).
    • remoteOf

      RemoteRepo remoteOf(File projectDir)
      Parameters:
      projectDir - the checkout whose origin remote is parsed.
      Returns:
      the owner and repository name parsed from projectDir's origin remote URL.
      Throws:
      RuntimeException - if projectDir has no origin remote configured, or its URL cannot be parsed into an owner and repository name.
    • configuredRepo

      RemoteRepo configuredRepo()
      The owner and repository parsed from the implementation's own configured repository URL.
      Returns:
      the configured owner and repo, or a RemoteRepo with null fields if none is configured.