Source:
<code>public static void createBareRepository() throws Exception { CliGitCommand gitCmd = new CliGitCommand(null); gitCmd.setDefaults(); final String[] gitImplementations = {"git", "jgit"}; Random random = new Random(); String gitImpl = gitImplementations[random.nextInt(gitImplementations.length)]; bareRepo = staticTemporaryFolder.newFolder(); bareURI = new URIish(bareRepo.getAbsolutePath()); hudson.EnvVars env = new hudson.EnvVars(); TaskListener listener = StreamTaskListener.fromStderr(); bareGitClient = Git.with(listener, env).in(bareRepo).using(gitImpl).getClient(); bareGitClient.init_().workspace(bareRepo.getAbsolutePath()).bare(true).execute(); <START> File cloneRepo = staticTemporaryFolder.newFolder(); <END> GitClient cloneGitClient = Git.with(listener, env).in(cloneRepo).using(gitImpl).getClient(); cloneGitClient.clone_() .url(bareRepo.getAbsolutePath()) .repositoryName("origin") .execute(); for (String branchName : branchNames) { File added = File.createTempFile("added-", ".txt", cloneRepo); String randomContent = java.util.UUID.randomUUID().toString(); String addedContent = "Initial commit to branch " + branchName + " content '" + randomContent + "'"; FileUtils.writeStringToFile(added, addedContent, "UTF-8"); cloneGitClient.add(added.getName()); cloneGitClient.commit("Initial commit to " + branchName + " file " + added.getName() + " with " + randomContent); FileUtils.writeStringToFile(added, "Another revision " + randomContent, "UTF-8"); cloneGitClient.add(added.getName()); cloneGitClient.commit("Second commit to " + branchName); cloneGitClient.push().to(bareURI).ref("HEAD:" + branchName).execute(); } FileUtils.deleteDirectory(cloneRepo); bareFirstCommit = bareGitClient.getHeadRev(bareRepo.getAbsolutePath(), "master"); }</code><technical_language>manual cleanup in line 229 FileUtils.deleteDirectory(cloneRepo); is required anymore if some kind of optimization. if this temporary folder required for lifetime of test instance TemporaryFolder rule is required here</technical_language>

Target:
public static void createBareRepository() throws Exception { CliGitCommand gitCmd = new CliGitCommand(null); gitCmd.setDefaults(); final String[] gitImplementations = {"git", "jgit"}; Random random = new Random(); String gitImpl = gitImplementations[random.nextInt(gitImplementations.length)]; bareRepo = staticTemporaryFolder.newFolder(); bareURI = new URIish(bareRepo.getAbsolutePath()); hudson.EnvVars env = new hudson.EnvVars(); TaskListener listener = StreamTaskListener.fromStderr(); bareGitClient = Git.with(listener, env).in(bareRepo).using(gitImpl).getClient(); bareGitClient.init_().workspace(bareRepo.getAbsolutePath()).bare(true).execute(); File cloneRepo = staticTemporaryFolder.newFolder(); GitClient cloneGitClient = Git.with(listener, env).in(cloneRepo).using(gitImpl).getClient(); cloneGitClient.clone_() .url(bareRepo.getAbsolutePath()) .repositoryName("origin") .execute(); for (String branchName : branchNames) { File added = File.createTempFile("added-", ".txt", cloneRepo); String randomContent = java.util.UUID.randomUUID().toString(); String addedContent = "Initial commit to branch " + branchName + " content '" + randomContent + "'"; FileUtils.writeStringToFile(added, addedContent, "UTF-8"); cloneGitClient.add(added.getName()); cloneGitClient.commit("Initial commit to " + branchName + " file " + added.getName() + " with " + randomContent); FileUtils.writeStringToFile(added, "Another revision " + randomContent, "UTF-8"); cloneGitClient.add(added.getName()); cloneGitClient.commit("Second commit to " + branchName); cloneGitClient.push().to(bareURI).ref("HEAD:" + branchName).execute(); } bareFirstCommit = bareGitClient.getHeadRev(bareRepo.getAbsolutePath(), "master"); }