List of usage examples for org.eclipse.jgit.lib Repository create
public abstract void create(boolean bare) throws IOException;
From source file:org.eclipse.egit.ui.internal.repository.NewRepositoryWizard.java
License:Open Source License
@Override public boolean performFinish() { RepositoryCache cache = Activator.getDefault().getRepositoryCache(); try {/*ww w. ja v a 2 s . co m*/ File repoFile = new File(myCreatePage.getDirectory()); if (!myCreatePage.getBare()) repoFile = new File(repoFile, Constants.DOT_GIT); Repository newRepo = cache.lookupRepository(repoFile); newRepo.create(myCreatePage.getBare()); Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repoFile); } catch (IOException e) { org.eclipse.egit.ui.Activator.handleError(e.getMessage(), e, false); } return true; }
From source file:org.eclipse.mylyn.reviews.r4e.core.rfs.ReviewsRFSProxy.java
License:Open Source License
/** * @param aReviewGroupDir//w w w . jav a 2 s. com * @return * @throws ReviewsFileStorageException */ private Repository initializeRepo(File aReviewGroupDir) throws ReviewsFileStorageException { try { Repository newRepo = new FileRepository(aReviewGroupDir); newRepo.create(true); newRepo.getConfig().setString("core", null, "sharedrepository", "0666"); newRepo.getConfig().save(); return newRepo; } catch (IOException e) { throw new ReviewsFileStorageException(e); } }
From source file:org.eclipse.ptp.internal.rdt.sync.git.core.JGitRepo.java
License:Open Source License
/** * Build the JGit repository - creating resources, such as Git-specific files, if necessary. * * @param localDirectory//from w w w .ja v a2 s . c o m * Repository location * @param monitor * @return * @throws GitAPIException * on JGit-specific problems * @throws IOException * on file system problems */ private Git buildRepo(String localDirectory, IProgressMonitor monitor) throws GitAPIException, IOException { final RecursiveSubMonitor subMon = RecursiveSubMonitor.convert(monitor, 10); try { // Get local Git repository, creating it if necessary. File localDir = new File(localDirectory); FileRepositoryBuilder repoBuilder = new FileRepositoryBuilder(); File gitDirFile = new File(localDirectory + File.separator + GitSyncService.gitDir); Repository repository = repoBuilder.setWorkTree(localDir).setGitDir(gitDirFile).build(); boolean repoExists = gitDirFile.exists(); if (!repoExists) { repository.create(false); } git = new Git(repository); if (!repoExists) { fileFilter = new GitSyncFileFilter(this, SyncManager.getDefaultFileFilter()); fileFilter.saveFilter(); } else { fileFilter = new GitSyncFileFilter(this); fileFilter.loadFilter(); } subMon.worked(5); // An initial commit to create the master branch. subMon.subTask(Messages.JGitRepo_0); if (!repoExists) { commit(subMon.newChild(4)); } else { subMon.worked(4); } return git; } finally { if (monitor != null) { monitor.done(); } } }
From source file:org.eclipse.ptp.rdt.sync.git.core.GitRemoteSyncConnection.java
License:Open Source License
/** * // ww w.jav a 2s. c o m * @param monitor * @param localDirectory * @param remoteHost * @return the repository * @throws IOException * on problems writing to the file system. * @throws RemoteExecutionException * on failure to run remote commands. * @throws RemoteSyncException * on problems with initial local commit. TODO: Consider the * consequences of exceptions that occur at various points, * which can leave the repo in a partial state. For example, if * the repo is created but the initial commit fails. TODO: * Consider evaluating the output of "git init". */ private Git buildRepo(IProgressMonitor monitor) throws IOException, RemoteExecutionException, RemoteSyncException { SubMonitor subMon = SubMonitor.convert(monitor, 100); subMon.subTask(Messages.GitRemoteSyncConnection_building_repo); try { final File localDir = new File(localDirectory); final FileRepositoryBuilder repoBuilder = new FileRepositoryBuilder(); File gitDirFile = new File(localDirectory + File.separator + gitDir); Repository repository = repoBuilder.setWorkTree(localDir).setGitDir(gitDirFile).build(); git = new Git(repository); // Create and configure local repository if it is not already present if (!(gitDirFile.exists())) { repository.create(false); // An initial commit to create the master branch. doCommit(); } // Create remote directory if necessary. try { CommandRunner.createRemoteDirectory(connection, remoteDirectory, subMon.newChild(5)); } catch (final CoreException e) { throw new RemoteSyncException(e); } // Initialize remote directory if necessary boolean existingGitRepo = doRemoteInit(subMon.newChild(5)); // Prepare remote site for committing (stage files using git) and // then commit remote files if necessary // Include untracked files for new git boolean needToCommitRemote = prepareRemoteForCommit(subMon.newChild(90), !existingGitRepo); // repos if (needToCommitRemote) { commitRemoteFiles(subMon.newChild(5)); } return git; } finally { if (monitor != null) { monitor.done(); } } }
From source file:org.ihtsdo.ttk.services.sync.Example.java
License:Apache License
/** * Method description//from w w w .j a v a 2 s . c om * * * @param args */ public static void main(String[] args) { try { // jGit provides the ability to manage the git repositories from // your code in a very easy manner. For example, to create the new // repository, you just have to indicate the target directory: File targetDir = new File("target/newRepository.git"); Repository repo = new FileRepository(targetDir); repo.create(true); //Cloning the existing git repository is also very easy and nice: Git.cloneRepository().setURI(targetDir.toURI().toString()).setDirectory(new File("target/working-copy")) .setBranch("master").setBare(false).setRemote("origin").setNoCheckout(false).call(); // And here is the way how you can add the changes, // commit and push them to the origin: Git git = new Git(new FileRepository(new File("target/working-copy"))); git.add().addFilepattern(".").call(); git.commit().setMessage("some comment").call(); git.push().setPushAll().setRemote("origin").call(); // http://jzelenkov.com/post/35653947951/diving-into-jgit // http://download.eclipse.org/jgit/docs/jgit-2.0.0.201206130900-r/apidocs/org/eclipse/jgit/api/package-summary.html // http://blogs.atlassian.com/2013/04/git-flow-comes-to-java/ } catch (IOException ex) { Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex); } catch (GitAPIException ex) { Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.kercoin.magrit.core.build.QueueServiceImpl.java
License:Open Source License
private Repository findBuildPlace(Repository repository) throws IOException { String originalPath = repository.getDirectory().getAbsolutePath(); String targetPath = originalPath.replaceFirst( context.configuration().getRepositoriesHomeDir().getAbsolutePath(), context.configuration().getWorkHomeDir().getAbsolutePath()); File workTree = new File(targetPath); workTree.mkdirs();/* w w w .j av a 2 s .com*/ Repository workRepo = new RepositoryBuilder().setWorkTree(workTree).build(); if (!workRepo.getDirectory().exists()) { workRepo.create(false); } return workRepo; }
From source file:org.kercoin.magrit.sshd.commands.ReceivePackCommand.java
License:Open Source License
Repository parse(String command) throws IOException { String parts[] = command.substring(17).split(" "); if (parts.length != 1) { throw new IllegalArgumentException( "Illegal git-receive-pack invokation ; the repository must be supplied"); }//from w w w . jav a2 s . c o m String repoPath = parts[0].substring(1, parts[0].length() - 1); Repository repo = createRepository(repoPath); if (!repo.getDirectory().exists()) { repo.create(true); } return repo; }
From source file:org.kuali.student.git.model.GitRepositoryUtils.java
License:Educational Community License
public static Repository buildFileRepository(File repositoryPath, boolean create, boolean bare) throws IOException { FileRepositoryBuilder builder = new FileRepositoryBuilder(); if (bare) {//ww w .jav a 2 s . c om builder = builder.setGitDir(repositoryPath); } else { builder.setWorkTree(repositoryPath); } builder = builder.readEnvironment(); Repository repo = builder.build(); if (create) repo.create(bare); return repo; }
From source file:org.obiba.opal.core.cfg.OpalViewPersistenceStrategy.java
License:Open Source License
private File cloneDatasourceViewsGit(String datasourceName) throws Exception { File targetDir = getDatasourceViewsGit(datasourceName); // Create datasource views bare git repo Repository newRepo = new FileRepository(targetDir); if (!targetDir.exists()) { newRepo.create(true); }// w w w. ja v a 2 s . co m String remoteUrl = "file://" + targetDir.getAbsolutePath(); File tmp = getTmpDirectory(); File localRepo = new File(tmp, "opal-" + Long.toString(System.nanoTime())); JGitUtils.cloneRepository(localRepo.getParentFile(), localRepo.getName(), remoteUrl, false, null); return localRepo; }
From source file:org.springframework.cloud.config.server.test.ConfigServerTestUtils.java
License:Apache License
public static Repository prepareBareRemote() throws IOException { // Create a folder in the temp folder that will act as the remote repository File remoteDir = File.createTempFile("remote", ""); remoteDir.delete();//from www . ja v a 2 s . c o m remoteDir.mkdirs(); // Create a bare repository FileKey fileKey = FileKey.exact(remoteDir, FS.DETECTED); Repository remoteRepo = fileKey.open(false); remoteRepo.create(true); return remoteRepo; }