List of usage examples for org.eclipse.jgit.api Git wrap
public static Git wrap(Repository repo)
From source file:org.eclipse.egit.ui.internal.commit.RepositoryCommit.java
License:Open Source License
/** * Get notes for this commit./*from ww w .ja va 2s . c om*/ * * @return non-null but possibly empty array of {@link RepositoryCommitNote} * instances. */ public RepositoryCommitNote[] getNotes() { if (notes == null) { List<RepositoryCommitNote> noteList = new ArrayList<RepositoryCommitNote>(); try { Repository repo = getRepository(); Git git = Git.wrap(repo); RevCommit revCommit = getRevCommit(); for (Ref ref : repo.getRefDatabase().getRefs(Constants.R_NOTES).values()) { Note note = git.notesShow().setNotesRef(ref.getName()).setObjectId(revCommit).call(); if (note != null) noteList.add(new RepositoryCommitNote(this, ref, note)); } notes = noteList.toArray(new RepositoryCommitNote[noteList.size()]); } catch (Exception e) { Activator.logError("Error showing notes", e); //$NON-NLS-1$ notes = new RepositoryCommitNote[0]; } } return notes; }
From source file:org.eclipse.egit.ui.internal.submodules.SubmoduleFolderTest.java
License:Open Source License
@Before public void setUp() throws Exception { parentRepositoryGitDir = createProjectAndCommitToRepository(); childRepositoryGitDir = createProjectAndCommitToRepository(CHILDREPO, CHILDPROJECT); Activator.getDefault().getRepositoryUtil().addConfiguredRepository(parentRepositoryGitDir); parentRepository = lookupRepository(parentRepositoryGitDir); childRepository = lookupRepository(childRepositoryGitDir); parentProject = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1); IFolder folder = parentProject.getFolder(FOLDER); IFolder subfolder = folder.getFolder(SUBFOLDER); subfolder.create(false, true, null); assertTrue(subfolder.exists());/* w w w . ja v a 2 s. co m*/ IFile someFile = subfolder.getFile("dummy.txt"); touch(PROJ1, someFile.getProjectRelativePath().toOSString(), "Dummy content"); addAndCommit(someFile, "Commit sub/dummy.txt"); childFolder = subfolder.getFolder(CHILD); Git.wrap(parentRepository).submoduleAdd().setPath(childFolder.getFullPath().toPortableString()) .setURI(childRepository.getDirectory().toURI().toString()).call(); TestRepository parentRepo = new TestRepository(parentRepository); parentRepo.trackAllFiles(parentProject); parentRepo.commit("Commit submodule"); assertTrue(SubmoduleWalk.containsGitModulesFile(parentRepository)); parentProject.refreshLocal(IResource.DEPTH_INFINITE, null); assertTrue(childFolder.exists()); // Let's get rid of the child project imported directly from the child // repository. childProject = ResourcesPlugin.getWorkspace().getRoot().getProject(CHILDPROJECT); childProject.delete(false, true, null); // Re-import it from the parent repo's submodule! IFile projectFile = childFolder.getFolder(CHILDPROJECT).getFile(IProjectDescription.DESCRIPTION_FILE_NAME); assertTrue(projectFile.exists()); ProjectRecord pr = new ProjectRecord(projectFile.getLocation().toFile()); ProjectUtils.createProjects(Collections.singleton(pr), null, null); assertTrue(childProject.isOpen()); // Now we have a parent repo in a state as if we had recursively // cloned some remote repo with a submodule and then imported all // projects. Look up the submodule repository instance through the // repository cache, so that we get the same instance that EGit // uses. subRepository = SubmoduleWalk.getSubmoduleRepository(childFolder.getParent().getLocation().toFile(), CHILD); assertNotNull(subRepository); subRepositoryGitDir = subRepository.getDirectory(); subRepository.close(); subRepository = lookupRepository(subRepositoryGitDir); assertNotNull(subRepository); }
From source file:org.eclipse.emf.compare.git.pgm.internal.app.LogicalMergeApplication.java
License:Open Source License
/** * Builds the message to display to the user when merge ends on a conflicting state. * //from w w w . j a v a 2s . co m * @param mergeResult * {@link MergeResult}. * @return a message. */ private String buildConflictingMessage(MergeResult mergeResult) { final StringBuilder messageBuildder = new StringBuilder(); try { // Should use mergeResult.getConflicting() however due to its random result we prefer using the // status of the git repository. final Status status = Git.wrap(repo).status().call(); List<String> conflictingFile = Lists.newArrayList(status.getConflicting()); // In order to have a determinist order. Collections.sort(conflictingFile); for (String conflicting : conflictingFile) { messageBuildder.append("Auto-merging failed in ").append(conflicting).append(EOL); } } catch (NoWorkTreeException e) { // Does nothing since this for console message } catch (GitAPIException e) { // Does nothing since this for console message } messageBuildder.append("Automatic merge failed; fix conflicts and then commit the result.").append(EOL); return messageBuildder.toString(); }
From source file:org.eclipse.oomph.gitbash.repository.PushDirectAction.java
License:Open Source License
@Override protected void run(Shell shell, final Repository repository) throws Exception { new Job("Pushing directly") { @Override/*from w w w. ja va 2 s . co m*/ protected IStatus run(IProgressMonitor monitor) { monitor.beginTask(getName(), 101); try { Git git = Git.wrap(repository); monitor.worked(1); git.push().setRemote("direct").setProgressMonitor( new EclipseGitProgressTransformer(new SubProgressMonitor(monitor, 50))).call(); monitor.setTaskName("Pulling"); git.pull().setProgressMonitor( new EclipseGitProgressTransformer(new SubProgressMonitor(monitor, 50))).call(); return Status.OK_STATUS; } catch (Exception ex) { return Activator.getStatus(ex); } finally { monitor.done(); } } }.schedule(); }
From source file:org.eclipse.orion.server.git.servlets.GitSubmoduleHandlerV1.java
License:Open Source License
public static void removeSubmodule(Repository db, Repository parentRepo, String pathToSubmodule) throws Exception { pathToSubmodule = pathToSubmodule.replace("\\", "/"); StoredConfig gitSubmodulesConfig = getGitSubmodulesConfig(parentRepo); gitSubmodulesConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule); gitSubmodulesConfig.save();/* w w w . ja va 2 s. c o m*/ StoredConfig repositoryConfig = parentRepo.getConfig(); repositoryConfig.unsetSection(CONFIG_SUBMODULE_SECTION, pathToSubmodule); repositoryConfig.save(); Git git = Git.wrap(parentRepo); git.add().addFilepattern(DOT_GIT_MODULES).call(); RmCommand rm = git.rm().addFilepattern(pathToSubmodule); if (gitSubmodulesConfig.getSections().size() == 0) { rm.addFilepattern(DOT_GIT_MODULES); } rm.call(); FileUtils.delete(db.getWorkTree(), FileUtils.RECURSIVE); FileUtils.delete(db.getDirectory(), FileUtils.RECURSIVE); }
From source file:org.eclipse.tycho.extras.sourceref.jgit.JGitSourceReferencesProvider.java
License:Open Source License
public String getSourceReferencesHeader(MavenProject project, ScmUrl scmUrl) throws MojoExecutionException { File basedir = project.getBasedir().getAbsoluteFile(); FileRepositoryBuilder builder = new FileRepositoryBuilder().readEnvironment().findGitDir(basedir) .setMustExist(true);/*ww w . j a v a 2s .c o m*/ Repository repo; Git git; try { repo = builder.build(); git = Git.wrap(repo); } catch (IOException e) { throw new MojoExecutionException("IO exception trying to create git repo ", e); } ObjectId head = resolveHead(repo); StringBuilder result = new StringBuilder(scmUrl.getUrl()); result.append(";path=\""); result.append(getRelativePath(basedir, repo.getWorkTree())); result.append("\""); String tag = findTagForHead(git, head); if (tag != null) { // may contain e.g. spaces, so we quote it result.append(";tag=\""); result.append(tag); result.append("\""); } result.append(";commitId="); result.append(head.getName()); return result.toString(); }
From source file:org.flowerplatform.web.git.operation.ResetOperation.java
License:Open Source License
public void execute() throws Exception { ProgressMonitor monitor = ProgressMonitor .create(GitPlugin.getInstance().getMessage("git.resetPage.monitor.title"), channel); monitor.beginTask(GitPlugin.getInstance().getMessage("git.resetPage.monitor.message", new Object[] { type.name(), refName }), 2); try {/*from w w w . ja v a 2 s.c o m*/ IProject[] validProjects = null; if (type.equals(ResetType.HARD)) { // validProjects = GitPlugin.getInstance().getGitUtils().getValidProjects(repository); // GitPlugin.getInstance().getGitUtils().backupProjectConfigFiles(null, validProjects); } Git.wrap(repository).reset().setMode(type).setRef(refName).call(); monitor.worked(1); if (type.equals(ResetType.HARD)) { // GitPlugin.getInstance().getGitUtils().refreshValidProjects(validProjects, new SubProgressMonitor(monitor, 1)); } } catch (Exception e) { throw e; } finally { monitor.done(); // GitPlugin.getInstance().getGitUtils().restoreProjectConfigFiles(repository, null); } }
From source file:org.gitective.core.filter.commit.NoteContentFilter.java
License:Open Source License
@Override public CommitFilter setRepository(final Repository repository) { super.setRepository(repository); if (repository != null) { show = Git.wrap(repository).notesShow(); noteRefs = getNoteRefs(repository); } else {/* w ww. j a v a 2s .co m*/ show = null; noteRefs = null; } return this; }
From source file:org.gitistics.test.RepositoryWokerImpl.java
License:Open Source License
public RepositoryWokerImpl(File dir, Repository repository) throws Exception { this.dir = dir; this.repository = repository; this.git = Git.wrap(repository); }
From source file:org.gitistics.test.RepositoryWokerImpl.java
License:Open Source License
public RepositoryWorker add(String file, String content) { try {// w w w.j av a2 s.co m File f = new File(dir, file); if (!f.exists()) { f.createNewFile(); } FileUtils.writeStringToFile(f, content); Git.wrap(repository).add().addFilepattern(file).call(); return this; } catch (Exception e) { throw new RuntimeException(e); } }