java.lang.Object
org.jenkinsci.test.acceptance.plugins.git.GitRepo
All Implemented Interfaces:
Closeable, AutoCloseable

public class GitRepo extends Object implements Closeable
Manipulates git repository locally.
Author:
Kohsuke Kawaguchi
  • Field Details

    • dir

      public final File dir
  • Constructor Details

    • GitRepo

      public GitRepo()
    • GitRepo

      public GitRepo(String url)
      Creates a new repo by cloning the given URL.
  • Method Details

    • setIdentity

      public void setIdentity(String userName, String userMail)
      Sets the identity to be used when committing files.
      Parameters:
      userName - the name of the user
      userMail - the email of the user
    • git

      public String git(Object... args)
    • gitDir

      public String gitDir(File dir, Object... args)
      Execute git command in specified directory.
    • changeAndCommitFile

      public void changeAndCommitFile(String fileName, String fileContent, String message)
      Append the specified content at the end of the given file and commit the file.
      Parameters:
      fileName - the name of the file
      fileContent - the new content of the file
      message - the commit message to ue
    • changeAndCommitFoo

      public void changeAndCommitFoo(String message)
      Appends the string "more" to the file "foo", adds it to the repository and commits it.
      Parameters:
      message - commit message
    • commit

      public void commit(String message)
      Records all changes to the repository.
      Parameters:
      message - commit message
    • touch

      public void touch(String fileName)
    • getLastSha1

      public String getLastSha1()
      Get sha1 hash of the most recent commit.
      Returns:
      Hash value
    • checkout

      public void checkout(String name)
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • addSubmodule

      public GitRepo addSubmodule(String submoduleName)
      Add a submodule to the main repository.
      Parameters:
      submoduleName - name of the submodule
    • transferToDockerContainer

      public void transferToDockerContainer(String host, int port)
      Zip bare repository, copy to Docker container using sftp, then unzip. The repo is now accessible over "ssh://git@ip:port/home/git/gitRepo.git"
      Parameters:
      host - IP of Docker container
      port - SSH port of Docker container
    • addFilesIn

      public void addFilesIn(String sourceFolder)
      Copies all files of the specified folder to the root folder of this git repository and adds the copied files using 'git add.
      Parameters:
      sourceFolder - the folder with the files to copy
    • addFilesIn

      public void addFilesIn(String sourceFolder, String destinationFolder)
      Copies all files of the specified directory to the destinationFolder of this git repository and adds the copied files using git add.
      Parameters:
      sourceFolder - the folder with the files to copy
      destinationFolder - the destination folder for the copied files
    • addFilesIn

      public void addFilesIn(URL sourceFolder)
      Copies all files of the specified folder to the root folder of this git repository and adds the copied files using 'git add.
      Parameters:
      sourceFolder - the folder with the files to copy
    • addFilesIn

      public void addFilesIn(URL sourceFolder, Path destinationFolder)
      Copies all files of the specified directory to the destinationFolder of this git repository and adds the copied files using git add.
      Parameters:
      sourceFolder - the folder with the files to copy
      destinationFolder - the destination folder for the copied files
    • createBranch

      public void createBranch(String name)
      Creates the specified branch in this repository.
      Parameters:
      name - the name of the branch
    • mkdir

      public Path mkdir(String path)