Class FileBackedHttpGitRepository

java.lang.Object
org.jenkinsci.plugins.gitserver.HttpGitRepository
org.jenkinsci.plugins.gitserver.FileBackedHttpGitRepository

public abstract class FileBackedHttpGitRepository extends HttpGitRepository
Convenient subtype of HttpGitRepository where the repository is non-bare, resides in a directory local to the controller, and you maintain the local up-to-date checkout whenever a change is pushed.
Author:
Kohsuke Kawaguchi
  • Field Details

    • workspace

      public final Path workspace
      Directory of the local workspace on the controller. There will be "./.git" that hosts the actual repository.
  • Constructor Details

    • FileBackedHttpGitRepository

      protected FileBackedHttpGitRepository(Path workspace)
    • FileBackedHttpGitRepository

      protected FileBackedHttpGitRepository(File workspace)
  • Method Details

    • openRepository

      public org.eclipse.jgit.lib.Repository openRepository() throws IOException
      Description copied from class: HttpGitRepository
      Opens the repository this UI-bound object holds on to.
      Specified by:
      openRepository in class HttpGitRepository
      Throws:
      IOException
    • createInitialRepository

      protected void createInitialRepository(org.eclipse.jgit.lib.Repository r) throws IOException
      Called when there's no .git directory to create one.

      This implementation also imports whatever currently in there into the repository.

      Throws:
      IOException
    • createUploadPack

      public org.eclipse.jgit.transport.UploadPack createUploadPack(jakarta.servlet.http.HttpServletRequest context, org.eclipse.jgit.lib.Repository db) throws org.eclipse.jgit.transport.resolver.ServiceNotEnabledException, org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException
      This default implementation allows read access to anyone who can access the HTTP URL this repository is bound to.

      For example, if this object is used as a project action, and the project isn't readable to Alice, then Alice won't be able to pull from this repository (think of a POSIX file system where /foo/bar is rwx------ and /foo/bar/zot is rwxrwxrwx.)

      Overrides:
      createUploadPack in class HttpGitRepository
      Throws:
      org.eclipse.jgit.transport.resolver.ServiceNotEnabledException
      org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException
      See Also:
      • UploadPackFactory.create(Object, Repository)
    • createReceivePack

      public org.eclipse.jgit.transport.ReceivePack createReceivePack(jakarta.servlet.http.HttpServletRequest context, org.eclipse.jgit.lib.Repository db) throws org.eclipse.jgit.transport.resolver.ServiceNotEnabledException, org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException
      Requires the admin access to be able to push
      Overrides:
      createReceivePack in class HttpGitRepository
      Throws:
      org.eclipse.jgit.transport.resolver.ServiceNotEnabledException
      org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException
      See Also:
      • ReceivePackFactory.create(Object, Repository)
    • createReceivePack

      public org.eclipse.jgit.transport.ReceivePack createReceivePack(org.eclipse.jgit.lib.Repository db)
    • updateWorkspace

      protected void updateWorkspace(org.eclipse.jgit.lib.Repository repo) throws IOException, org.eclipse.jgit.api.errors.GitAPIException
      Called when new ref is pushed to update the local workspace. The default implementation does "git reset --hard main"
      Throws:
      IOException
      org.eclipse.jgit.api.errors.GitAPIException
    • checkPushPermission

      protected abstract void checkPushPermission()
      Do something like Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER) to make sure the user has the permission to push.