List of usage examples for org.eclipse.jgit.lib Repository resolve
@Nullable public ObjectId resolve(String revstr) throws AmbiguousObjectException, IncorrectObjectTypeException, RevisionSyntaxException, IOException
From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java
License:Open Source License
private void setupWalk(WebWalk walk, Repository repo, String path) throws IOException { walk.addAdditionalRefs(repo.getRefDatabase().getAdditionalRefs()); walk.addAdditionalRefs(repo.getRefDatabase().getRefs(Constants.R_NOTES).values()); walk.sort(RevSort.COMMIT_TIME_DESC, true); walk.sort(RevSort.BOUNDARY, true);//from ww w . j a va 2 s .co m walk.setRetainBody(false); setWalkStartPoints(walk, repo, walk.parseCommit(repo.resolve(Constants.HEAD))); createFileWalker(walk, repo, path); }
From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java
License:Open Source License
@RemoteInvocation public List<HistoryFileDiffEntryDto> getCommitFileDiffs(StatefulServiceInvocationContext context, HistoryEntryDto entry, HistoryViewInfoDto info) { List<HistoryFileDiffEntryDto> entries = new ArrayList<HistoryFileDiffEntryDto>(); try {//w ww . j a va 2 s . c o m Repository repo = RepositoryCache .open(FileKey.exact(new File(info.getRepositoryLocation()), FS.DETECTED)); RevWalk walk = new RevWalk(repo); RevCommit commit = walk.parseCommit(repo.resolve(entry.getId())); for (RevCommit parent : commit.getParents()) { walk.parseBody(parent); } FileDiff[] fileDiffs = FileDiff.compute(createFileWalker(new WebWalk(repo), repo, info.getPath()), commit, TreeFilter.ALL); for (FileDiff fd : fileDiffs) { HistoryFileDiffEntryDto fileEntry = new HistoryFileDiffEntryDto(); fileEntry.setFile(fd.getLabel(fd)); //fileEntry.setImage(GitPlugin.getInstance().getGitUtils().getImageURL(fd.getImageDescriptor(fd))); entries.add(fileEntry); } walk.dispose(); } catch (Exception e) { context.getCommunicationChannel().sendCommandWithPush( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return null; } return entries; }
From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java
License:Open Source License
@RemoteInvocation public String getCommitMessage(StatefulServiceInvocationContext context, HistoryEntryDto entry, String repositoryLocation) { try {// ww w . j av a 2 s .c om Repository repo = RepositoryCache.open(FileKey.exact(new File(repositoryLocation), FS.DETECTED)); ; RevCommit commit = new RevWalk(repo).parseCommit(repo.resolve(entry.getId())); return getCommitMessage(repo, entry, commit); } catch (Exception e) { context.getCommunicationChannel().sendCommandWithPush( new DisplaySimpleMessageClientCommand(CommonPlugin.getInstance().getMessage("error"), e.getMessage(), DisplaySimpleMessageClientCommand.ICON_ERROR)); return null; } }
From source file:org.gitective.core.CommitUtils.java
License:Open Source License
/** * Resolve the revision string to a commit object id * * @param repository//w w w . j av a 2s . c o m * @param revision * @return commit id */ protected static ObjectId resolve(final Repository repository, final String revision) { try { return repository.resolve(revision); } catch (IOException e) { throw new GitException(e, repository); } }
From source file:org.jabylon.team.git.GitTeamProvider.java
License:Open Source License
@Override public Collection<PropertyFileDiff> update(ProjectVersion project, IProgressMonitor monitor) throws TeamProviderException { SubMonitor subMon = SubMonitor.convert(monitor, 100); List<PropertyFileDiff> updatedFiles = new ArrayList<PropertyFileDiff>(); try {//from w w w . ja va 2 s . c o m Repository repository = createRepository(project); Git git = Git.wrap(repository); FetchCommand fetchCommand = git.fetch(); URI uri = project.getParent().getRepositoryURI(); if (uri != null) fetchCommand.setRemote(stripUserInfo(uri).toString()); String refspecString = "refs/heads/{0}:refs/remotes/origin/{0}"; refspecString = MessageFormat.format(refspecString, project.getName()); RefSpec spec = new RefSpec(refspecString); fetchCommand.setRefSpecs(spec); subMon.subTask("Fetching from remote"); if (!"https".equals(uri.scheme()) && !"http".equals(uri.scheme())) fetchCommand.setTransportConfigCallback(createTransportConfigCallback(project.getParent())); fetchCommand.setCredentialsProvider(createCredentialsProvider(project.getParent())); fetchCommand.setProgressMonitor(new ProgressMonitorWrapper(subMon.newChild(80))); fetchCommand.call(); ObjectId remoteHead = repository.resolve("refs/remotes/origin/" + project.getName() + "^{tree}"); DiffCommand diff = git.diff(); subMon.subTask("Caculating Diff"); diff.setProgressMonitor(new ProgressMonitorWrapper(subMon.newChild(20))); diff.setOldTree(new FileTreeIterator(repository)); CanonicalTreeParser p = new CanonicalTreeParser(); ObjectReader reader = repository.newObjectReader(); try { p.reset(reader, remoteHead); } finally { reader.release(); } diff.setNewTree(p); checkCanceled(subMon); List<DiffEntry> diffs = diff.call(); for (DiffEntry diffEntry : diffs) { checkCanceled(subMon); updatedFiles.add(convertDiffEntry(diffEntry)); LOGGER.trace(diffEntry.toString()); } if (!updatedFiles.isEmpty()) { checkCanceled(subMon); //no more cancel after this point ObjectId lastCommitID = repository .resolve("refs/remotes/origin/" + project.getName() + "^{commit}"); LOGGER.info("Merging remote commit {} to {}/{}", new Object[] { lastCommitID, project.getName(), project.getParent().getName() }); //TODO: use rebase here? if (isRebase(project)) { RebaseCommand rebase = git.rebase(); rebase.setUpstream("refs/remotes/origin/" + project.getName()); RebaseResult result = rebase.call(); if (result.getStatus().isSuccessful()) { LOGGER.info("Rebase finished: {}", result.getStatus()); } else { LOGGER.error("Rebase of {} failed. Attempting abort", project.relativePath()); rebase = git.rebase(); rebase.setOperation(Operation.ABORT); result = rebase.call(); LOGGER.error("Abort finished with {}", result.getStatus()); } } else { MergeCommand merge = git.merge(); merge.include(lastCommitID); MergeResult mergeResult = merge.call(); LOGGER.info("Merge finished: {}", mergeResult.getMergeStatus()); } } else LOGGER.info("Update finished successfully. Nothing to merge, already up to date"); } catch (JGitInternalException e) { throw new TeamProviderException(e); } catch (InvalidRemoteException e) { throw new TeamProviderException(e); } catch (GitAPIException e) { throw new TeamProviderException(e); } catch (AmbiguousObjectException e) { throw new TeamProviderException(e); } catch (IOException e) { throw new TeamProviderException(e); } finally { monitor.done(); } return updatedFiles; }
From source file:org.jboss.tools.openshift.egit.internal.test.util.TestUtils.java
License:Open Source License
/** * verifies that repository contains exactly the given files. * /*from w w w .java 2 s. c om*/ * @param repository * @param paths * @throws Exception */ private RepoDiff createRepoDiff(Repository repository, String... expectedPaths) throws Exception { RepoDiff repoDiff = new RepoDiff(); Set<String> expectedFiles = new HashSet<String>(Arrays.asList(expectedPaths)); TreeWalk treeWalk = new TreeWalk(repository); treeWalk.addTree(repository.resolve("HEAD^{tree}")); treeWalk.setRecursive(true); while (treeWalk.next()) { String path = treeWalk.getPathString(); if (!expectedFiles.contains(path)) { repoDiff.addUnexpected(path); } expectedFiles.remove(path); } repoDiff.addAllMissing(expectedFiles); return repoDiff; }
From source file:org.jboss.tools.openshift.egit.internal.test.util.TestUtils.java
License:Open Source License
/** * verifies that repository contains exactly the given files with the given * content. Usage example:<br>/*from w w w. j av a 2s. c o m*/ * * <code> * assertRepositoryContainsFiles(repository, "foo/a.txt", "content of A", * "foo/b.txt", "content of B") * </code> * * @param repository * @param args * @throws Exception */ public void assertRepositoryContainsFilesWithContent(Repository repository, String... args) throws Exception { HashMap<String, String> expectedfiles = mkmap(args); TreeWalk treeWalk = new TreeWalk(repository); treeWalk.addTree(repository.resolve("HEAD^{tree}")); treeWalk.setRecursive(true); while (treeWalk.next()) { String path = treeWalk.getPathString(); assertTrue(expectedfiles.containsKey(path)); ObjectId objectId = treeWalk.getObjectId(0); byte[] expectedContent = expectedfiles.get(path).getBytes(); byte[] repoContent = treeWalk.getObjectReader().open(objectId).getBytes(); if (!Arrays.equals(repoContent, expectedContent)) { fail("File " + path + " has repository content " + new String(repoContent) + " instead of expected content " + new String(expectedContent)); } expectedfiles.remove(path); } if (expectedfiles.size() > 0) { StringBuilder message = new StringBuilder("Repository does not contain expected files: "); for (String path : expectedfiles.keySet()) { message.append(path); message.append(" "); } fail(message.toString()); } }
From source file:org.jenkinsci.plugins.os_ci.utils.GitClient.java
License:Apache License
public static void archive() throws GitAPIException { String localPath, remotePath; Repository localRepo; Git git;/*from w ww . j av a 2 s . c om*/ try { localPath = "C:\\Users\\agrosmar\\git\\gitTry"; // remotePath = "git@github.com:me/mytestrepo.git"; localRepo = new FileRepository(localPath + "/.git"); git = new Git(localRepo); // "http://gitlab.cisco.com/control-plane-ci/deployment-scripts/blob/master/GLOBAL FileOutputStream out = new FileOutputStream(new File("c://git.zip")); git.archive().setTree(localRepo.resolve("")).setFormat("zip").setOutputStream(out).call(); } catch (Exception e) { e.printStackTrace(); } // ObjectId tree = null; }
From source file:org.kercoin.magrit.core.utils.GitUtils.java
License:Open Source License
public RevCommit getCommit(Repository repo, String revstr) throws MissingObjectException, IncorrectObjectTypeException, AmbiguousObjectException, IOException { ObjectId ref = repo.resolve(revstr); if (ref == null) return null; RevWalk walk = new RevWalk(repo); try {//from w ww . j a va2s .c om return walk.parseCommit(ref); } finally { walk.dispose(); } }
From source file:org.kercoin.magrit.core.utils.GitUtils.java
License:Open Source License
public byte[] showBytes(Repository repository, String revstr) throws AmbiguousObjectException, IOException { ObjectId ref = repository.resolve(revstr); if (ref == null) { return null; }/*from w w w . j ava 2 s . c o m*/ return repository.getObjectDatabase().newReader().open(ref).getBytes(); }