private Repository createJGitRepository( RepoStore repoStore, String projName ) throws IOException { File repoDir = new File(repoStore.getRootDirectory(), projName); return new FileRepositoryBuilder().setWorkTree(repoDir).build(); }
public static boolean currentCommitsAreEqual(Path dir1, Path dir2) { try { RevCommit commit1 = new Git( new FileRepositoryBuilder().setWorkTree( dir1.toFile().getAbsoluteFile() ).build() ).log().call().iterator().next(); RevCommit commit2 = new Git( new FileRepositoryBuilder().setWorkTree( dir2.toFile().getAbsoluteFile() ).build() ).log().call().iterator().next(); return commit1.equals(commit2); } catch (IOException e) { throw new RuntimeException(e); } catch (NoHeadException e) { return false; } catch (GitAPIException e) { throw new RuntimeException(e); } }
String getLatestReleaseTag(final String releaseTagPattern) throws IOException, GitAPIException { final Pattern tagPattern = Pattern.compile(releaseTagPattern); final FileRepositoryBuilder builder = new FileRepositoryBuilder(); final Repository repository = builder.setWorkTree(new File(gitDir)).findGitDir().build(); final RevWalk walk = new RevWalk(repository); walk.markStart(walk.parseCommit(repository.resolve("HEAD"))); final String tag = new Git(repository).describe().call(); walk.reset(); final Matcher releaseTagMatcher = tagPattern.matcher(tag); repository.close(); return releaseTagMatcher.matches() ? tag : null; }
protected String parseCommit() throws IOException { String providedCommit = System.getProperty("heroku.buildVersion"); if (null == providedCommit) { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setWorkTree(getRootDir()) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); ObjectId head = repository.resolve("HEAD"); return head == null ? null : head.name(); } else { return providedCommit; } }
.call(); } else { Repository gitRepo = builder.setWorkTree(repositoryPath.toFile()).setMustExist(false).build(); this.git = new Git(gitRepo); try {
final void buildRepository(File workTree, File gitDir) throws GitRepositoryException { if (gitDir == null && workTree == null) { throw new GitRepositoryException("Neither worktree nor GIT_DIR is set."); } else { if (workTree != null && !workTree.exists()) { throw new GitRepositoryException("The worktree " + workTree + " does not exist"); } if (gitDir != null && !gitDir.exists()) { throw new GitRepositoryException("The GIT_DIR " + gitDir + " does not exist"); } } FileRepositoryBuilder repositoryBuilder = getRepositoryBuilder(); if (gitDir == null) { if (repositoryBuilder.findGitDir(workTree).getGitDir() == null) { throw new GitRepositoryException(workTree + " is not inside a Git repository. Please specify the GIT_DIR separately."); } repositoryBuilder.setWorkTree(repositoryBuilder.getGitDir().getParentFile()); } else { repositoryBuilder.setGitDir(gitDir); repositoryBuilder.setWorkTree(workTree); } try { repository = repositoryBuilder.build(); } catch (IOException e) { throw new GitRepositoryException("Could not initialize repository", e); } }
protected String parseCommit() throws IOException { String providedCommit = System.getProperty("heroku.buildVersion"); if (null == providedCommit) { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setWorkTree(getRootDir()) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); ObjectId head = repository.resolve("HEAD"); return head == null ? null : head.name(); } else { return providedCommit; } }
repositoryBuilder.setWorkTree(getProject().getProjectDir());
public void commitFile() throws IOException { final FileRepositoryBuilder builder = new FileRepositoryBuilder(); final Repository repository = builder.setWorkTree(new File(gitDir)).findGitDir().build(); try { new Git(repository).commit().setOnly("build.gradle").setMessage("Bump the version of builld.gradle").call(); } catch (final GitAPIException e) { e.printStackTrace(); } }
@Override public Repository openRepository() throws IOException { File rd = getRepositoryDir(); // TODO 7: should we cache r here? Who will be closing r? FileRepository r = new FileRepositoryBuilder().setWorkTree(rd).build(); if (!r.getObjectDatabase().exists()){ r.create(); try { new FilePath(rd).untarFrom(JenkowWorkflowRepository.class.getResourceAsStream("/jenkow-repository-seed.tar"),FilePath.TarCompression.NONE); } catch (InterruptedException e1) { LOGGER.log(Level.WARNING, "Seeding of jenkow-repository failed",e1); } addAndCommit(r,".","Initial import of the existing contents"); } return r; }
@Before public void initGitRepo() throws Exception { gitWorkTree = new File(gitRepoDir.getRoot(), testName.getMethodName()).getAbsoluteFile(); final Repository gitRepo = new FileRepositoryBuilder().setWorkTree(gitWorkTree).build(); gitRepo.create(); git = Git.wrap(gitRepo); gitUri = "git+file://" + (gitWorkTree.getPath().startsWith(File.separator) ? "" : "/") + gitWorkTree.getPath().replace(File.separatorChar, '/') + "/.git"; // Start the master branch with an empty commit. git.commit().setMessage("Initial commit").call(); }
/** * Initializes the {@link FileRepository} or creates a new own if it does * not exist. */ private void initRepository() throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.setWorkTree(localWorkspace); repository = builder.build(); if (!new File(localWorkspace, ".git").isDirectory()) { repository.create(); repository.getConfig().setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); repository.getConfig().setString("remote", "origin", "url", remoteLocation); repository.getConfig().setString("branch", watchBranch, "remote", "origin"); repository.getConfig().setString("branch", watchBranch, "merge", "refs/heads/" + watchBranch); repository.getConfig().save(); } }
/** * @param gitBasedRepositoryConfiguration the configuration of the repository * @throws IOException thrown if repository does not exist * @throws GitAPIException thrown if there was an error while checking the status of the repository * @throws NoWorkTreeException thrown if the directory is not a git work tree */ public GitBasedRepository(GitBasedRepositoryConfiguration gitBasedRepositoryConfiguration) throws IOException, NoWorkTreeException, GitAPIException { super(Objects.requireNonNull(gitBasedRepositoryConfiguration)); this.gitBasedRepositoryConfiguration = gitBasedRepositoryConfiguration; FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository gitRepo = builder.setWorkTree(this.repositoryRoot.toFile()).setMustExist(false).build(); if (!Files.exists(this.repositoryRoot.resolve(".git"))) { gitRepo.create(); } // explicitly enable longpaths to ensure proper handling of long pathss gitRepo.getConfig().setBoolean("core", null, "longpaths", true); gitRepo.getConfig().save(); this.eventBus = new EventBus(); this.git = new Git(gitRepo); if (gitBasedRepositoryConfiguration.isAutoCommit() && !this.git.status().call().isClean()) { this.addCommit("Files changed externally."); } }
repo = builder.setWorkTree(repoDir). setGitDir(new File(repoDir, ".git")). setMustExist(false).
/** * Method description * * * @param directory * * @return * * @throws IOException */ public static org.eclipse.jgit.lib.Repository open(File directory) throws IOException { FS fs = FS.DETECTED; FileRepositoryBuilder builder = new FileRepositoryBuilder(); builder.setFS(fs); if (isGitDirectory(fs, directory)) { // bare repository builder.setGitDir(directory).setBare(); } else { builder.setWorkTree(directory); } return builder.build(); }
@Test public void remoteToLocal_submodule() throws Exception { pushMirrorSettings(null, null); // Create a new repository for a submodule. final File gitSubmoduleWorkTree = new File(gitRepoDir.getRoot(), testName.getMethodName() + ".submodule").getAbsoluteFile(); final Repository gitSubmoduleRepo = new FileRepositoryBuilder().setWorkTree(gitSubmoduleWorkTree).build(); gitSubmoduleRepo.create(); final Git gitSubmodule = Git.wrap(gitSubmoduleRepo); final String gitSubmoduleUri = "file://" + (gitSubmoduleWorkTree.getPath().startsWith(File.separator) ? "" : "/") + gitSubmoduleWorkTree.getPath().replace(File.separatorChar, '/') + "/.git"; // Prepare the master branch of the submodule repository. addToGitIndex(gitSubmodule, gitSubmoduleWorkTree, "in_submodule.txt", "This is a file in a submodule."); gitSubmodule.commit().setMessage("Initial commit").call(); // Add the submodule. git.submoduleInit().call(); git.submoduleAdd().setPath("submodule").setURI(gitSubmoduleUri).call(); git.commit().setMessage("Add a new submodule").call(); // Check the files under a submodule do not match nor trigger an 'unknown object' error. mirroringService.mirror().join(); final Revision headRev = client.normalizeRevision(projName, REPO_FOO, Revision.HEAD).join(); final Entry<JsonNode> expectedMirrorState = expectedMirrorState(headRev, "/"); assertThat(client.getFiles(projName, REPO_FOO, Revision.HEAD, "/**").join().values()) .containsExactly(expectedMirrorState); }
repository = new FileRepositoryBuilder().setWorkTree(baseDir).setGitDir(gitDir).setup().build(); } catch (IOException ex) { throw ServerLogger.ROOT_LOGGER.failedToPullRepository(ex, gitConfig.getRepository()); repository = new FileRepositoryBuilder().setWorkTree(baseDir).setGitDir(gitDir).setup().build();
repository = new FileRepositoryBuilder().setWorkTree(baseDir).setGitDir(gitDir).setup().build(); } catch (IOException ex) { throw ServerLogger.ROOT_LOGGER.failedToPullRepository(ex, gitConfig.getRepository()); repository = new FileRepositoryBuilder().setWorkTree(baseDir).setGitDir(gitDir).setup().build();