List of usage examples for org.eclipse.jgit.storage.file FileRepositoryBuilder FileRepositoryBuilder
FileRepositoryBuilder
From source file:edu.nju.cs.inform.jgit.unfinished.TestSubmodules.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { File mainRepoDir = createRepository(); try (Repository mainRepo = openMainRepo(mainRepoDir)) { addSubmodule(mainRepo);/*from w ww .j a v a2 s.com*/ FileRepositoryBuilder builder = new FileRepositoryBuilder(); try (Repository subRepo = builder.setGitDir(new File("testrepo/.git")).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build()) { if (subRepo.isBare()) { throw new IllegalStateException( "Repository at " + subRepo.getDirectory() + " should not be bare"); } } } System.out.println("All done!"); }
From source file:edu.nju.cs.inform.jgit.unfinished.TestSubmodules.java
License:Apache License
private static Repository openMainRepo(File mainRepoDir) throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository mainRepo = builder.setGitDir(new File(mainRepoDir.getAbsolutePath(), ".git")).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build();//from w ww . j a v a2 s .c o m if (mainRepo.isBare()) { throw new IllegalStateException("Repository at " + mainRepoDir + " should not be bare"); } return mainRepo; }
From source file:edu.nju.cs.inform.jgit.unfinished.TrackMaster.java
License:Apache License
public static void main(String[] args) throws IOException, InvalidRemoteException, TransportException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); localPath.delete();//from ww w . j a v a 2 s.co m // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).call()) { // now open the created repository FileRepositoryBuilder builder = new FileRepositoryBuilder(); try (Repository repository = builder.setGitDir(localPath).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build()) { try (Git git = new Git(repository)) { git.branchCreate().setName("master") // ?!? .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM) .setStartPoint("origin/master").setForce(true).call(); } System.out.println("Now tracking master in repository at " + repository.getDirectory() + " from origin/master at " + REMOTE_URL); } } }
From source file:edu.tum.cs.mylyn.provisioning.git.ui.GitProvisioningWizard.java
License:Open Source License
private void configureRepository(RepositoryWrapper repositoryInfo, String destinationDirectory, boolean importProjects, IProgressMonitor monitor) { try {//ww w . j a v a 2 s . c o m File destinationDir = new File(destinationDirectory); File repositoryPath = new File(destinationDir + File.separator + GIT_DIR); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(repositoryPath).readEnvironment().build(); repository.getConfig().fromText(repositoryInfo.getConfig().toText()); repository.create(); monitor.worked(10); monitor.worked(10); pull(repository); monitor.worked(50); if (importProjects) { importProjects(repository, monitor); } monitor.worked(30); org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().lookupRepository(repositoryPath); } catch (Exception e) { StatusHandler .log(new Status(Status.WARNING, Activator.PLUGIN_ID, "error provisioning git projects", e)); //$NON-NLS-1$ } }
From source file:edu.wustl.lookingglass.community.CommunityRepository.java
License:Open Source License
private Git load() throws IOException, URISyntaxException, IllegalStateException, GitAPIException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(this.gitDir).readEnvironment().build(); Git newGit;//ww w .ja v a 2 s. c o m if (hasAtLeastOneReference(repository)) { // The repository is valid newGit = new Git(repository); } else { // The current git dir isn't valid... so let's make a new one. Logger.warning("invalid git dir found " + this.gitDir + "; deleting."); FileUtils.forceDelete(this.gitDir); newGit = init(); } // We need to make sure this repo stays in shape... // so let's do some maintenance every now and then... Properties gcStats = newGit.gc().getStatistics(); int looseObjects = Integer.valueOf(gcStats.getProperty("numberOfLooseObjects", "0")); if ((AUTO_GC_LOOSE_OBJECTS != 0) && (looseObjects > AUTO_GC_LOOSE_OBJECTS)) { newGit.gc().call(); } return newGit; }
From source file:eu.atos.paas.git.Repository.java
License:Open Source License
public Repository(File projectDir) throws IOException { if (!projectDir.isDirectory()) { throw new IllegalArgumentException(projectDir + " must be a directory"); }//ww w .java 2 s.c o m this.projectDir = Objects.requireNonNull(projectDir); FileRepositoryBuilder builder = new FileRepositoryBuilder().findGitDir(this.projectDir); if (builder.getGitDir() == null) { throw new IllegalArgumentException("Could not find a Git repository up from " + projectDir); } this.repo = builder.build(); }
From source file:eu.cloud4soa.cli.roo.addon.commands.GitManager.java
License:Apache License
public void init() throws Exception { FileRepositoryBuilder builder;/*w w w. j a v a2 s .com*/ gitRepository = new FileRepository(localPath + "/" + ".git"); builder = new FileRepositoryBuilder(); gitRepository = builder.setGitDir(new File(localPath + "/.git")).readEnvironment().findGitDir().build(); git = new Git(gitRepository); GithubSshSessionFactory factory = new GithubSshSessionFactory(); factory.setKeyLocation(sshKeyDir); factory.setPassphrase(passphrase); SshSessionFactory.setInstance(factory); }
From source file:eu.trentorise.opendata.josman.JosmanProject.java
public void generateSite() { LOG.log(Level.INFO, "Fetching {0}/{1} tags.", new Object[] { repoOrganization, repoName }); repoTags = Josmans.fetchTags(repoOrganization, repoName); MavenXpp3Reader reader = new MavenXpp3Reader(); try {/*from w w w . j a va 2 s .c om*/ pom = reader.read(new FileInputStream(new File(sourceRepoDir, "pom.xml"))); } catch (Exception ex) { throw new RuntimeException("Error while reading pom!", ex); } try { File repoFile = new File(sourceRepoDir, ".git"); FileRepositoryBuilder builder = new FileRepositoryBuilder(); repo = builder.setGitDir(repoFile).readEnvironment() // scan environment GIT_* variables .build(); } catch (Exception ex) { throw new RuntimeException("Error while reading local git repo!", ex); } LOG.log(Level.INFO, "Cleaning target: {0} ....", pagesDir.getAbsolutePath()); if (!pagesDir.getAbsolutePath().endsWith("site")) { throw new RuntimeException("target directory does not end with 'site' !"); } try { FileUtils.deleteDirectory(pagesDir); LOG.info("Done deleting directory"); } catch (IOException ex) { throw new RuntimeException("Error while deleting directory " + pagesDir.getAbsolutePath(), ex); } SemVersion snapshotVersion = SemVersion.of(pom.getVersion()).withPreReleaseVersion(""); if (snapshotMode) { LOG.log(Level.INFO, "Processing local version"); buildIndex(snapshotVersion); processDocsDir(snapshotVersion); createLatestDocsDirectory(snapshotVersion); } else { if (repoTags.isEmpty()) { throw new NotFoundException("There are no tags at all in the repository!!"); } SemVersion latestPublishedVersion = Josmans.latestVersion(repoName, repoTags); LOG.log(Level.INFO, "Processing published version"); buildIndex(latestPublishedVersion); String curBranch = Josmans.readRepoCurrentBranch(sourceRepoDir); SortedMap<String, RepositoryTag> filteredTags = Josmans.versionTagsToProcess(repoName, repoTags, ignoredVersions); for (RepositoryTag tag : filteredTags.values()) { LOG.log(Level.INFO, "Processing release tag {0}", tag.getName()); processGitDocsDir(Josmans.version(repoName, tag.getName())); } } Josmans.copyDirFromResource(Josmans.class, "/website-template", pagesDir); try { File targetImgDir = new File(pagesDir, "img"); File programLogo = programLogo(sourceDocsDir(), repoName); if (programLogo.exists()) { LOG.log(Level.INFO, "Found program logo: {0}", programLogo.getAbsolutePath()); LOG.log(Level.INFO, " copying it into dir {0}", targetImgDir.getAbsolutePath()); FileUtils.copyFile(programLogo, new File(targetImgDir, programLogoName(repoName))); } FileUtils.copyFile(new File(sourceRepoDir, "LICENSE.txt"), new File(pagesDir, "LICENSE.txt")); } catch (Exception ex) { throw new RuntimeException("Error while copying files!", ex); } LOG.log(Level.INFO, "\n\nSite is now browsable at {0}\n\n", pagesDir.getAbsolutePath()); }
From source file:eu.trentorise.opendata.josman.Josmans.java
License:Open Source License
/** * Reads a local project current branch. * * @param projectPath path to project root folder (the one that _contains_ * the .git folder)/*from w ww . j a v a 2 s. co m*/ * @return the current branch of provided repo */ public static String readRepoCurrentBranch(File projectPath) { checkNotNull(projectPath); try { FileRepositoryBuilder builder = new FileRepositoryBuilder(); org.eclipse.jgit.lib.Repository repo = builder.setGitDir(new File(projectPath, ".git")) .readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); return repo.getBranch(); } catch (IOException ex) { throw new RuntimeException("Couldn't read current branch from " + projectPath.getAbsolutePath()); } }
From source file:eu.trentorise.opendata.josman.test.GitTest.java
@Test public void testReadRepo() throws IOException, GitAPIException { File repoFile = createSampleGitRepo(); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repo = builder.setGitDir(repoFile).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build();//from w ww .ja v a2 s. c om LOG.log(Level.INFO, "directory: {0}", repo.getDirectory().getAbsolutePath()); LOG.log(Level.INFO, "Having repository: {0}", repo.getDirectory().getAbsolutePath()); LOG.log(Level.INFO, "current branch: {0}", repo.getBranch()); }