List of usage examples for org.eclipse.jgit.api Git wrap
public static Git wrap(Repository repo)
From source file:com.genuitec.org.eclipse.egit.core.op.ResetOperation.java
License:Open Source License
private void reset(IProgressMonitor monitor) throws CoreException { monitor.beginTask(NLS.bind(CoreText.ResetOperation_performingReset, type.toString().toLowerCase(), refName), 2);/* w w w . ja va 2s. c om*/ IProject[] validProjects = null; if (type == ResetType.HARD) validProjects = ProjectUtil.getValidOpenProjects(repository); ResetCommand reset = Git.wrap(repository).reset(); reset.setMode(type); reset.setRef(refName); try { reset.call(); } catch (GitAPIException e) { throw new TeamException(e.getLocalizedMessage(), e.getCause()); } monitor.worked(1); // only refresh if working tree changes if (type == ResetType.HARD) ProjectUtil.refreshValidProjects(validProjects, !closeRemovedProjects, new SubProgressMonitor(monitor, 1)); monitor.done(); }
From source file:com.gitblit.transport.ssh.git.GarbageCollectionCommand.java
License:Apache License
@Override protected void runImpl() throws IOException, Failure { try {//from ww w .ja v a 2 s . co m GarbageCollectCommand gc = Git.wrap(repo).gc(); logGcInfo("before:", gc.getStatistics()); gc.setProgressMonitor(NullProgressMonitor.INSTANCE); Properties statistics = gc.call(); logGcInfo("after: ", statistics); } catch (Exception e) { throw new Failure(1, "fatal: Cannot run gc: ", e); } }
From source file:com.google.devtools.build.lib.bazel.repository.GitCloneFunction.java
License:Open Source License
private boolean isUpToDate(GitRepositoryDescriptor descriptor) { // Initializing/checking status of/etc submodules cleanly is hard, so don't try for now. if (descriptor.initSubmodules) { return false; }/* w ww. j a v a 2 s . co m*/ Repository repository = null; try { repository = new FileRepositoryBuilder() .setGitDir(descriptor.directory.getChild(Constants.DOT_GIT).getPathFile()).setMustExist(true) .build(); ObjectId head = repository.resolve(Constants.HEAD); ObjectId checkout = repository.resolve(descriptor.checkout); if (head != null && checkout != null && head.equals(checkout)) { Status status = Git.wrap(repository).status().call(); if (!status.hasUncommittedChanges()) { // new_git_repository puts (only) BUILD and WORKSPACE, and // git_repository doesn't add any files. Set<String> untracked = status.getUntracked(); if (untracked.isEmpty() || (untracked.size() == 2 && untracked.contains("BUILD") && untracked.contains("WORKSPACE"))) { return true; } } } } catch (GitAPIException | IOException e) { // Any exceptions here, we'll just blow it away and try cloning fresh. // The fresh clone avoids any weirdness due to what's there and has nicer // error reporting. } finally { if (repository != null) { repository.close(); } } return false; }
From source file:com.google.devtools.build.lib.bazel.repository.GitCloner.java
License:Open Source License
private static boolean isUpToDate(GitRepositoryDescriptor descriptor) { // Initializing/checking status of/etc submodules cleanly is hard, so don't try for now. if (descriptor.initSubmodules) { return false; }//from w w w . j a v a 2 s . co m Repository repository = null; try { repository = new FileRepositoryBuilder() .setGitDir(descriptor.directory.getChild(Constants.DOT_GIT).getPathFile()).setMustExist(true) .build(); ObjectId head = repository.resolve(Constants.HEAD); ObjectId checkout = repository.resolve(descriptor.checkout); if (head != null && checkout != null && head.equals(checkout)) { Status status = Git.wrap(repository).status().call(); if (!status.hasUncommittedChanges()) { // new_git_repository puts (only) BUILD and WORKSPACE, and // git_repository doesn't add any files. Set<String> untracked = status.getUntracked(); if (untracked.isEmpty() || (untracked.size() == 2 && untracked.contains("BUILD") && untracked.contains("WORKSPACE"))) { return true; } } } } catch (GitAPIException | IOException e) { // Any exceptions here, we'll just blow it away and try cloning fresh. // The fresh clone avoids any weirdness due to what's there and has nicer // error reporting. } finally { if (repository != null) { repository.close(); } } return false; }
From source file:com.google.gerrit.server.git.GarbageCollection.java
License:Apache License
public GarbageCollectionResult run(List<Project.NameKey> projectNames, boolean aggressive, PrintWriter writer) { GarbageCollectionResult result = new GarbageCollectionResult(); Set<Project.NameKey> projectsToGc = gcQueue.addAll(projectNames); for (Project.NameKey projectName : Sets.difference(Sets.newHashSet(projectNames), projectsToGc)) { result.addError(new GarbageCollectionResult.Error( GarbageCollectionResult.Error.Type.GC_ALREADY_SCHEDULED, projectName)); }//w w w . j ava 2s . c om for (Project.NameKey p : projectsToGc) { try (Repository repo = repoManager.openRepository(p)) { logGcConfiguration(p, repo, aggressive); print(writer, "collecting garbage for \"" + p + "\":\n"); GarbageCollectCommand gc = Git.wrap(repo).gc(); gc.setAggressive(aggressive); logGcInfo(p, "before:", gc.getStatistics()); gc.setProgressMonitor( writer != null ? new TextProgressMonitor(writer) : NullProgressMonitor.INSTANCE); Properties statistics = gc.call(); logGcInfo(p, "after: ", statistics); print(writer, "done.\n\n"); fire(p, statistics); } catch (RepositoryNotFoundException e) { logGcError(writer, p, e); result.addError(new GarbageCollectionResult.Error( GarbageCollectionResult.Error.Type.REPOSITORY_NOT_FOUND, p)); } catch (Exception e) { logGcError(writer, p, e); result.addError(new GarbageCollectionResult.Error(GarbageCollectionResult.Error.Type.GC_FAILED, p)); } finally { gcQueue.gcFinished(p); } } return result; }
From source file:com.google.gerrit.server.project.GetStatistics.java
License:Apache License
@Override public RepositoryStatistics apply(ProjectResource rsrc) throws ResourceNotFoundException, ResourceConflictException { try (Repository repo = repoManager.openRepository(rsrc.getNameKey())) { GarbageCollectCommand gc = Git.wrap(repo).gc(); return new RepositoryStatistics(gc.getStatistics()); } catch (GitAPIException | JGitInternalException e) { throw new ResourceConflictException(e.getMessage()); } catch (IOException e) { throw new ResourceNotFoundException(rsrc.getName()); }//w w w. j a v a 2 s.c o m }
From source file:com.googlecode.ounit.GitQuestion.java
License:Open Source License
@Override protected void fetchQuestion() { File cacheDir = new File(WORKDIR, REPO_DIR); srcDir = new File(cacheDir, id + "-" + revision); if (srcDir.exists()) { getLog().debug("Question found in {}", srcDir); return;//from www. jav a 2 s . c om } try { getLog().debug("Checking out revision {} from {} to {}", new Object[] { revision, cloneDir, srcDir }); Git git = Git.wrap(new RepositoryBuilder().setMustExist(true) .setIndexFile(new File(srcDir, ".gitindex")).setGitDir(cloneDir).setWorkTree(srcDir).build()); git.checkout().setName(revision).call(); } catch (Exception e) { getLog().error("Error checking out revision " + revision + " from " + cloneDir, e); throw new RuntimeException("Failed to fetch question", e); } }
From source file:com.googlesource.gerrit.plugins.github.git.PullRequestImportJob.java
License:Apache License
private void fetchGitHubPullRequest(Repository gitRepo, GHPullRequest pr) throws GitAPIException, InvalidRemoteException, TransportException { status.update(Code.SYNC, "Fetching", "Fetching PullRequests from GitHub"); Git git = Git.wrap(gitRepo); FetchCommand fetch = git.fetch();/* w w w . j a v a2 s .c o m*/ fetch.setRemote(ghRepository.getCloneUrl()); fetch.setRefSpecs( new RefSpec("+refs/pull/" + pr.getNumber() + "/head:refs/remotes/origin/pr/" + pr.getNumber())); fetch.setProgressMonitor(this); fetch.call(); }
From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java
License:Open Source License
@Secured({ Role.User }) @Override/*from w w w . j a va 2s. co m*/ public String createBranch(String repoName, String branchName) throws EntityNotFoundException { try { Repository r = findRepositoryByName(repoName); Git git = Git.wrap(r); CreateBranchCommand command = git.branchCreate(); command.setName(branchName); /* * command.setStartPoint(getStartPoint().name()); if (upstreamMode != null) * command.setUpstreamMode(upstreamMode); command.call(); */ command.call(); r.close(); return branchName; } catch (IOException e) { throw new RuntimeException(e); } catch (GitAPIException e) { throw new RuntimeException(e); } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:com.tasktop.c2c.server.scm.service.GitServiceBean.java
License:Open Source License
@Secured({ Role.User }) @Override/*from ww w .ja va 2s . c o m*/ public void deleteBranch(String repoName, String branchName) throws EntityNotFoundException { try { Repository r = findRepositoryByName(repoName); Git git = Git.wrap(r); DeleteBranchCommand command = git.branchDelete(); command.setBranchNames(branchName); command.setForce(true); command.call(); r.close(); } catch (IOException e) { throw new RuntimeException(e); } catch (GitAPIException e) { throw new RuntimeException(e); } catch (URISyntaxException e) { throw new RuntimeException(e); } }