Class GitRepo
- 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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.void
addFilesIn(String sourceFolder, String destinationFolder)
Copies all files of the specified directory to thedestinationFolder
of this git repository and adds the copied files using git add.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.void
addFilesIn(URL sourceFolder, Path destinationFolder)
Copies all files of the specified directory to thedestinationFolder
of this git repository and adds the copied files using git add.GitRepo
addSubmodule(String submoduleName)
Add a submodule to the main repository.void
changeAndCommitFile(String fileName, String fileContent, String message)
Append the specified content at the end of the given file and commit the file.void
changeAndCommitFoo(String message)
Appends the string "more" to the file "foo", adds it to the repository and commits it.void
checkout(String name)
void
close()
void
commit(String message)
Records all changes to the repository.void
createBranch(String name)
Creates the specified branch in this repository.String
getLastSha1()
Get sha1 hash of the most recent commit.String
git(Object... args)
String
gitDir(File dir, Object... args)
Execute git command in specified directory.Path
mkdir(String path)
void
setIdentity(String userName, String userMail)
Sets the identity to be used when committing files.void
touch(String fileName)
void
transferToDockerContainer(String host, int port)
Zip bare repository, copy to Docker container using sftp, then unzip.
-
-
-
Field Detail
-
dir
public final File dir
-
-
Constructor Detail
-
GitRepo
public GitRepo()
-
GitRepo
public GitRepo(String url)
Creates a new repo by cloning the given URL.
-
-
Method Detail
-
setIdentity
public void setIdentity(String userName, String userMail)
Sets the identity to be used when committing files.- Parameters:
userName
- the name of the useruserMail
- the email of the user
-
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 filefileContent
- the new content of the filemessage
- 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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- 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 containerport
- 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 thedestinationFolder
of this git repository and adds the copied files using git add.- Parameters:
sourceFolder
- the folder with the files to copydestinationFolder
- 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 thedestinationFolder
of this git repository and adds the copied files using git add.- Parameters:
sourceFolder
- the folder with the files to copydestinationFolder
- 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
-
-