List of usage examples for org.eclipse.jgit.lib Repository create
public void create() throws IOException
From source file:org.eclipse.egit.ui.view.synchronize.AbstractSynchronizeViewTest.java
License:Open Source License
protected void createEmptyRepository() throws Exception { File gitDir = new File(new File(getTestDirectory(), EMPTY_REPOSITORY), Constants.DOT_GIT); Repository myRepository = new FileRepository(gitDir); myRepository.create(); // we need to commit into master first IProject firstProject = ResourcesPlugin.getWorkspace().getRoot().getProject(EMPTY_PROJECT); if (firstProject.exists()) firstProject.delete(true, null); IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(EMPTY_PROJECT); desc.setLocation(new Path(new File(myRepository.getWorkTree(), EMPTY_PROJECT).getPath())); firstProject.create(desc, null);/* w ww . j a v a 2 s . co m*/ firstProject.open(null); IFolder folder = firstProject.getFolder(FOLDER); folder.create(false, true, null); IFile textFile = folder.getFile(FILE1); textFile.create(new ByteArrayInputStream("Hello, world".getBytes(firstProject.getDefaultCharset())), false, null); IFile textFile2 = folder.getFile(FILE2); textFile2.create(new ByteArrayInputStream("Some more content".getBytes(firstProject.getDefaultCharset())), false, null); new ConnectProviderOperation(firstProject, gitDir).execute(null); }
From source file:org.eclipse.egit.ui.view.synchronize.SynchronizeViewRemoteAwareChangeSetModelTest.java
License:Open Source License
protected void createMockLogicalRepository() throws Exception { File gitDir = new File(new File(getTestDirectory(), MOCK_LOGICAL_PROJECT), Constants.DOT_GIT); Repository repo = FileRepositoryBuilder.create(gitDir); repo.create(); // we need to commit into master first IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(MOCK_LOGICAL_PROJECT); if (project.exists()) { project.delete(true, null);//from w w w .j av a 2s . c o m TestUtil.waitForJobs(100, 5000); } IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(MOCK_LOGICAL_PROJECT); desc.setLocation(new Path(new File(repo.getWorkTree(), MOCK_LOGICAL_PROJECT).getPath())); project.create(desc, null); project.open(null); assertTrue("Project is not accessible: " + project, project.isAccessible()); TestUtil.waitForJobs(50, 5000); try { new ConnectProviderOperation(project, gitDir).execute(null); } catch (Exception e) { Activator.logError("Failed to connect project to repository", e); } assertConnected(project); mockLogicalFile = project.getFile("index.mocklogical"); mockLogicalFile.create( new ByteArrayInputStream("file1.txt\nfile2.txt".getBytes(project.getDefaultCharset())), false, null); IFile file1 = project.getFile("file1.txt"); file1.create(new ByteArrayInputStream("Content 1".getBytes(project.getDefaultCharset())), false, null); IFile file2 = project.getFile("file2.txt"); file2.create(new ByteArrayInputStream("Content 2".getBytes(project.getDefaultCharset())), false, null); IFile[] commitables = new IFile[] { mockLogicalFile, file1, file2 }; List<IFile> untracked = new ArrayList<>(); untracked.addAll(Arrays.asList(commitables)); CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit"); op.execute(null); RevCommit firstCommit = op.getCommit(); CreateLocalBranchOperation createBranchOp = new CreateLocalBranchOperation(repo, "refs/heads/stable", firstCommit); createBranchOp.execute(null); // Delete file2.txt from logical model and add file3 mockLogicalFile = touch(MOCK_LOGICAL_PROJECT, "index.mocklogical", "file1.txt\nfile3.txt"); file2.delete(true, null); touch(MOCK_LOGICAL_PROJECT, "file1.txt", "Content 1 modified"); IFile file3 = project.getFile("file3.txt"); file3.create(new ByteArrayInputStream("Content 3".getBytes(project.getDefaultCharset())), false, null); commitables = new IFile[] { mockLogicalFile, file1, file2, file3 }; untracked = new ArrayList<>(); untracked.add(file3); op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Second commit"); op.execute(null); }
From source file:org.eclipse.mylyn.reviews.r4e.ui.tests.utils.TestUtils.java
License:Open Source License
private static Repository createRepository(IProject aProject) throws CoreException, IOException { TestUtils.waitForJobs();/*from ww w . ja v a2 s. co m*/ File gitDir = new File(aProject.getLocation().toOSString(), Constants.DOT_GIT); Repository repository = new FileRepository(gitDir); try { repository.create(); Config storedConfig = repository.getConfig(); storedConfig.setEnum("core", null, "autocrlf", AutoCRLF.FALSE); } catch (IllegalStateException e) { //Jusy go on } return repository; }
From source file:org.eclipse.releng.tests.LocalDiskRepositoryTest.java
License:Eclipse Distribution License
/** * Creates a new empty repository.//from w ww. ja va2 s . c o m * * @param bare * true to create a bare repository; false to make a repository * within its working directory * @return the newly created repository, opened for access * @throws IOException * the repository could not be created in the temporary area */ private Repository createRepository(boolean bare) throws IOException { File gitdir = createUniqueTestGitDir(bare); Repository db = new FileRepository(gitdir); Assert.assertFalse(gitdir.exists()); db.create(); toClose.add(db); return db; }
From source file:org.eclipse.winery.repository.backend.filebased.GitBasedRepository.java
License:Open Source License
/** * @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 */// w ww .ja v a 2 s. c om 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(); String repoUrl = gitBasedRepositoryConfiguration.getRepositoryUrl(); String branch = gitBasedRepositoryConfiguration.getBranch(); if (!Files.exists(this.repositoryRoot.resolve(".git"))) { if (repoUrl != null && !repoUrl.isEmpty()) { this.git = cloneRepository(repoUrl, branch); } else { gitRepo.create(); this.git = new Git(gitRepo); } } else { this.git = new Git(gitRepo); } if (this.repositoryRoot.resolve(Constants.DEFAULT_LOCAL_REPO_NAME).toFile().exists()) { if (!(this instanceof MultiRepository)) { this.workingRepositoryRoot = this.repositoryRoot.resolve(Constants.DEFAULT_LOCAL_REPO_NAME); } else { this.workingRepositoryRoot = repositoryDep; } } else { this.workingRepositoryRoot = repositoryDep; } this.eventBus = new EventBus(); // explicitly enable longpaths to ensure proper handling of long pathss gitRepo.getConfig().setBoolean("core", null, "longpaths", true); gitRepo.getConfig().save(); if (gitBasedRepositoryConfiguration.isAutoCommit() && !this.git.status().call().isClean()) { this.addCommit("Files changed externally."); } }
From source file:org.exist.git.xquery.Create.java
License:Open Source License
@Override public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { try {/* ww w . j a v a2s.c om*/ String localPath = args[0].getStringValue(); if (!(localPath.endsWith("/"))) localPath += File.separator; Repository newRepo = new RepositoryBuilder().setFS(FS).setGitDir(new Resource(localPath + ".git")) .setMustExist(false).build(); newRepo.create(); return BooleanValue.TRUE; } catch (Throwable e) { throw new XPathException(this, Module.EXGIT001, e); } }
From source file:org.nbgit.ui.clone.CloneAction.java
License:Open Source License
public static void doInit(Repository repo, URIish uri, OutputLogger logger) throws IOException, URISyntaxException { repo.create(); repo.getConfig().setBoolean("core", null, "bare", false); repo.getConfig().save();//w w w . j a v a 2 s .c o m logger.output("Initialized empty Git repository in " + repo.getWorkDir().getAbsolutePath()); logger.flushLog(); // save remote final RemoteConfig rc = new RemoteConfig(repo.getConfig(), "origin"); rc.addURI(uri); rc.addFetchRefSpec(new RefSpec().setForceUpdate(true).setSourceDestination(Constants.R_HEADS + "*", Constants.R_REMOTES + "origin" + "/*")); rc.update(repo.getConfig()); repo.getConfig().save(); }
From source file:org.nbgit.ui.init.InitAction.java
License:Open Source License
public void performAction(ActionEvent e) { final Git git = Git.getInstance(); File[] files = context.getRootFiles().toArray(new File[context.getRootFiles().size()]); if (files == null || files.length == 0) { return; // If there is a .git directory in an ancestor of any of the files in // the context we fail. }//from w ww. j a va2s.c o m for (File file : files) { if (!file.isDirectory()) { file = file.getParentFile(); } if (git.getTopmostManagedParent(file) != null) { Git.LOG.log(Level.SEVERE, "Found .git directory in ancestor of {0} ", // NOI18N file); return; } } final Project proj = GitUtils.getProject(context); File projFile = GitUtils.getProjectFile(proj); if (projFile == null) { OutputLogger logger = OutputLogger.getLogger(Git.GIT_OUTPUT_TAB_TITLE); logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_TITLE")); // NOI18N logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_TITLE_SEP")); // NOI18N logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_NOT_SUPPORTED_INVIEW_INFO")); // NOI18N logger.output(""); // NOI18N JOptionPane.showMessageDialog(null, NbBundle.getMessage(InitAction.class, "MSG_CREATE_NOT_SUPPORTED_INVIEW"), // NOI18N NbBundle.getMessage(InitAction.class, "MSG_CREATE_NOT_SUPPORTED_INVIEW_TITLE"), // NOI18N JOptionPane.INFORMATION_MESSAGE); logger.closeLog(); return; } String projName = GitProjectUtils.getProjectName(projFile); File rootDir = getCommonAncestor(files); final File root = getCommonAncestor(rootDir, projFile); if (root == null) { return; } final String prjName = projName; final Repository repo = git.getRepository(root); RequestProcessor rp = git.getRequestProcessor(root.getAbsolutePath()); GitProgressSupport supportCreate = new GitProgressSupport() { public void perform() { try { OutputLogger logger = getLogger(); logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_TITLE")); // NOI18N logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_TITLE_SEP")); // NOI18N logger.output(NbBundle.getMessage(InitAction.class, "MSG_CREATE_INIT", prjName, root)); // NOI18N repo.create(); } catch (IOException ex) { notifyLater(ex); } } }; supportCreate.start(rp, root.getAbsolutePath(), org.openide.util.NbBundle.getMessage(InitAction.class, "MSG_Create_Progress")); // NOI18N GitProgressSupport supportAdd = new GitProgressSupport() { public void perform() { OutputLogger logger = getLogger(); try { List<File> files = getFileList(repo, root); IndexBuilder.create(repo).log(logger).addAll(files).write(); logger.output(NbBundle.getMessage(InitAction.class, "MSG_CREATE_ADD", files.size(), root.getAbsolutePath())); // NOI18N logger.output(""); // NOI18N logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_DONE_WARNING")); // NOI18N } catch (IOException ex) { notifyLater(ex); } finally { logger.outputInRed(NbBundle.getMessage(InitAction.class, "MSG_CREATE_DONE")); // NOI18N logger.output(""); // NOI18N } } }; supportAdd.start(rp, root.getAbsolutePath(), org.openide.util.NbBundle.getMessage(InitAction.class, "MSG_Create_Add_Progress")); // NOI18N GitProgressSupport supportStatus = new StatusTask(context) { @Override public void performAfter() { git.versionedFilesChanged(); git.refreshAllAnnotations(); } }; supportStatus.start(rp, root.getAbsolutePath(), NbBundle.getMessage(InitAction.class, "MSG_Create_Status_Progress")); // NOI18N }
From source file:org.wise.portal.presentation.web.controllers.author.project.JGitUtils.java
License:Open Source License
/** * @param directoryPath/*www . j a v a 2 s.c o m*/ * @param doCreate create the directory if it doesn't exit * @return * @throws IOException */ public static Repository getGitRepository(String directoryPath, boolean doCreate) throws IOException { // prepare a new folder File localPath = new File(directoryPath); File gitDir = new File(localPath, ".git"); if (!doCreate && !gitDir.exists()) { return null; } else { Repository repository = FileRepositoryBuilder.create(gitDir); if (doCreate && !gitDir.exists()) { repository.create(); } return repository; } }
From source file:org.xwiki.git.GitHelper.java
License:Open Source License
public Repository createGitTestRepository(String repoName) throws Exception { File localDirectory = getRepositoryFile(repoName); File gitDirectory = new File(localDirectory, ".git"); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(gitDirectory).readEnvironment().findGitDir().build(); if (!gitDirectory.exists()) { repository.create(); }/*from w ww . j ava2 s. c o m*/ return repository; }