List of usage examples for org.eclipse.jgit.api CheckoutCommand setName
public CheckoutCommand setName(String name)
From source file:br.com.riselabs.cotonet.builder.NetworkBuilder.java
License:Open Source License
/** * Returns the conflicting files of the given scenario. * //from w ww. ja va 2s.c o m * @param scenario * @return * @throws CheckoutConflictException * @throws GitAPIException */ private List<File> getConflictingFiles(MergeScenario scenario) throws CheckoutConflictException, GitAPIException { Git git = Git.wrap(getProject().getRepository()); // this is for the cases of restarting after exception in a conflict // scenario analysis try { git.reset().setRef(scenario.getLeft().getName()).setMode(ResetType.HARD).call(); } catch (JGitInternalException e) { Logger.log(log, "[" + project.getName() + "] JGit Reset Command ended with exception." + " Trying external reset command."); ExternalGitCommand egit = new ExternalGitCommand(); try { egit.setType(CommandType.RESET).setDirectory(project.getRepository().getDirectory().getParentFile()) .call(); } catch (BlameException e1) { Logger.logStackTrace(log, e1); return null; } } CheckoutCommand ckoutCmd = git.checkout(); ckoutCmd.setName(scenario.getLeft().getName()); ckoutCmd.setStartPoint(scenario.getLeft()); ckoutCmd.call(); MergeCommand mergeCmd = git.merge(); mergeCmd.setCommit(false); mergeCmd.setStrategy(MergeStrategy.RECURSIVE); mergeCmd.include(scenario.getRight()); Set<String> conflictingPaths; try { // dealing with MissingObjectException MergeResult mResult = mergeCmd.call(); // dealing with Ghosts conflicts conflictingPaths = mResult.getConflicts().keySet(); } catch (NullPointerException | JGitInternalException e) { StringBuilder sb = new StringBuilder(); sb.append("[" + project.getName() + ":" + project.getUrl() + "] " + "Skipping merge scenario due to '" + e.getMessage() + "'\n"); sb.append("--> Exception: " + e.getClass()); sb.append("--> Skipped scenario:\n"); sb.append("::Base:" + scenario.getBase().getName() + "\n"); sb.append("::Left:" + scenario.getLeft().getName() + "\n"); sb.append("::Right:" + scenario.getRight().getName() + "\n"); Logger.log(log, sb.toString()); return null; } List<File> result = new ArrayList<File>(); for (String path : conflictingPaths) { result.add(new File(getProject().getRepository().getDirectory().getParent(), path)); } return result; }
From source file:br.com.riselabs.cotonet.test.helpers.ConflictBasedRepositoryTestCase.java
License:Open Source License
public MergeResult runMerge(MergeScenario scenario) throws RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException, CheckoutConflictException, GitAPIException { Git git = Git.wrap(db);//from w w w . j a v a 2s.c o m CheckoutCommand ckoutCmd = git.checkout(); ckoutCmd.setName(scenario.getLeft().getName()); ckoutCmd.setStartPoint(scenario.getLeft()); ckoutCmd.call(); MergeCommand mergeCmd = git.merge(); mergeCmd.setCommit(false); mergeCmd.include(scenario.getRight()); return mergeCmd.call(); }
From source file:com.ejwa.gitdepmavenplugin.DownloaderMojo.java
License:Open Source License
private void checkout(Git git, Pom pom, GitDependency dependency) throws MojoExecutionException { final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency); final String version = dependencyHandler.getDependencyVersion(pom); try {//from w ww . j ava 2 s .c o m final Repository repository = git.getRepository(); final ObjectId rev = repository.resolve(version); final RevCommit rc = new RevWalk(repository).parseCommit(rev); final CheckoutCommand checkout = git.checkout(); checkout.setName("maven-gitdep-branch-" + rc.getCommitTime()); checkout.setStartPoint(rc); checkout.setCreateBranch(true); checkout.call(); final Status status = checkout.getResult().getStatus(); if (status != Status.OK) { throw new MojoExecutionException( String.format("Invalid checkout state (%s) of dependency.", status)); } } catch (IOException | InvalidRefNameException | RefAlreadyExistsException | RefNotFoundException ex) { throw new MojoExecutionException(String.format("Failed to check out dependency for %s.%s", dependency.getGroupId(), dependency.getArtifactId()), ex); } }
From source file:com.ejwa.mavengitdepplugin.DownloaderMojo.java
License:Open Source License
private void checkout(Git git, POM pom, GitDependency dependency) { final GitDependencyHandler dependencyHandler = new GitDependencyHandler(dependency); final String version = dependencyHandler.getDependencyVersion(pom); try {// www . j av a2s .c o m final ObjectId rev = git.getRepository().resolve(version); final RevCommit rc = new RevWalk(git.getRepository()).parseCommit(rev); final CheckoutCommand checkout = git.checkout(); checkout.setName("maven-gitdep-branch-" + rc.getCommitTime()); checkout.setStartPoint(rc); checkout.setCreateBranch(true); checkout.call(); final Status status = checkout.getResult().getStatus(); if (!status.equals(Status.OK)) { getLog().error("Status of checkout: " + status); throw new IllegalStateException("Invalid checkout state of dependency."); } } catch (Exception ex) { getLog().error(ex); throw new IllegalStateException("Failed to check out dependency."); } }
From source file:com.google.gerrit.acceptance.git.GitUtil.java
License:Apache License
public static void checkout(Git git, String name) throws GitAPIException { CheckoutCommand checkout = git.checkout(); checkout.setName(name); checkout.call();/*w ww . j av a2 s. c o m*/ }
From source file:com.meltmedia.cadmium.core.git.GitService.java
License:Apache License
public void switchBranch(String branchName) throws RefNotFoundException, Exception { Repository repository = git.getRepository(); if (branchName != null && !repository.getBranch().equals(branchName)) { log.info("Switching branch from {} to {}", repository.getBranch(), branchName); CheckoutCommand checkout = git.checkout(); if (isTag(branchName)) { checkout.setName(branchName); } else {/*from w w w .j av a2s .co m*/ checkout.setName("refs/heads/" + branchName); if (repository.getRef("refs/heads/" + branchName) == null) { CreateBranchCommand create = git.branchCreate(); create.setName(branchName); create.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM); create.setStartPoint("origin/" + branchName); create.call(); } } checkout.call(); } }
From source file:com.mpdeimos.ct_tests.looper.GitRevisionLooper.java
License:Apache License
/** {@inheritDoc} */ @Override/*w w w .jav a 2s . c om*/ public RevIterator iterator() { return new RevIterator() { int index = commits.size(); @Override public void remove() { throw new IllegalStateException(); } @Override public RevisionInfo next() { final Commit commit = commits.get(--index); return new RevisionInfo(commits.size() - index - 1, commit.getId(), commit, root) { /** {@inheritDoc} * @throws ConQATException */ @Override public File getPath() throws ConQATException { CheckoutCommand checkout = new CheckoutCommand(repository) { /**/}; checkout.setName(commit.getId()); //checkout.setForce(true); try { checkout.call(); } catch (Exception e) { getLogger().error(e); ResetCommand reset = new ResetCommand(repository) { /**/}; reset.setMode(ResetType.HARD); reset.setRef(commit.getId()); try { reset.call(); CheckoutCommand checkout2 = new CheckoutCommand(repository) { /**/}; checkout2.setName(commit.getId()); // checkout2.setForce(true); checkout2.call(); } catch (Exception e1) { getLogger().error(e1); throw new ConQATException(e1); } } return super.getPath(); } }; } @Override public boolean hasNext() { return index > 0; } @Override public Commit peekCommit() { if (!hasNext()) throw new IllegalStateException(); return commits.get(index - 1); } }; }
From source file:com.mpdeimos.ct_tests.vcs.GitFileDiffTest.java
License:Apache License
@Test public void testAddedFiles() { try {/* w ww . j av a 2s .co m*/ // ArrayList<RevCommit> commits = new ArrayList<RevCommit>(); // // Repository repository = new FileRepository(gitDir); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setWorkTree(useTestFile("diff1")).build(); ObjectId head = repository.resolve("new"); // TreeWalk treeWalk = TreeUtils.diffWithParents(repository, head); // scan = DiffEntry.scan(treeWalk); // treeWalk.release(); CommitFinder finder = new CommitFinder(repository); GitCommitListFilter filter = new GitCommitListFilter(); finder.setFilter(filter); finder.findFrom(head); for (Commit commit : filter.getCommits()) { // ResetCommand reset = new Git(repository).reset(); // reset.setMode(ResetType.HARD); // reset.setRef(commit.getId()); CheckoutCommand checkout = new Git(repository).checkout(); checkout.setName(commit.getId()); // checkout.setStartPoint(commit.getId()); // checkout.addPath("."); try { // Ref call = reset.call(); checkout.call(); System.out.println(checkout.getResult().getStatus() + " checked out " + commit.getMessage()); } catch (Exception e) { fail(e.getMessage()); } // System.out.println(change.getCommit().getFullMessage()); } // head = repository.resolve("HEAD~1"); // RevWalk revWalk = new RevWalk(repository); // RevCommit tip = revWalk.parseCommit(head); // revWalk.markStart(tip); // revWalk. // TreeWalk treeWalk = new TreeWalk(repository); // treeWalk.setRecursive(true); // treeWalk.addTree(tip.getTree()); // // revWalk.markStart(tip); // GitFileDiff[] compute = GitFileDiff.compute(treeWalk, tip); // System.out.println(compute); } catch (Exception e) { fail(e.getMessage()); } }
From source file:com.rimerosolutions.ant.git.tasks.CheckoutTask.java
License:Apache License
@Override protected void doExecute() throws BuildException { try {/* w w w .j a va 2 s . com*/ CheckoutCommand checkoutCommand = git.checkout(); if (createBranch) { checkoutCommand.setCreateBranch(true); if (trackBranchOnCreate) { checkoutCommand.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK); } } if (!GitTaskUtils.isNullOrBlankString(branchName)) { checkoutCommand.setName(branchName); } if (!GitTaskUtils.isNullOrBlankString(startPoint)) { checkoutCommand.setStartPoint(Constants.DEFAULT_REMOTE_NAME + "/" + startPoint); } checkoutCommand.call(); CheckoutResult checkoutResult = checkoutCommand.getResult(); if (checkoutResult.getStatus().equals(CheckoutResult.Status.CONFLICTS)) { String conflicts = checkoutResult.getConflictList().toString(); throw new GitBuildException(String.format("Conflicts were found:%s.", conflicts)); } else if (checkoutResult.getStatus().equals(CheckoutResult.Status.NONDELETED)) { String undeleted = checkoutResult.getUndeletedList().toString(); throw new GitBuildException(String.format("Some files could not be deleted:%s.", undeleted)); } } catch (RefAlreadyExistsException e) { throw new GitBuildException( String.format("Cannot create branch '%s', as it already exists!", branchName), e); } catch (RefNotFoundException e) { throw new GitBuildException(String.format("The branch '%s' was not found.", branchName), e); } catch (InvalidRefNameException e) { throw new GitBuildException("An invalid branch name was specified.", e); } catch (CheckoutConflictException e) { throw new GitBuildException("Some checkout conflicts were found.", e); } catch (GitAPIException e) { throw new GitBuildException(String.format("Could not checkout branch '%s'.", branchName), e); } }
From source file:com.romanenco.gitt.git.GitHelper.java
License:Open Source License
/** * Checkout specific branch or tag./* www .j a va2 s . c om*/ * * @param localPath * @param name * @throws GitError */ public static void checkout(String localPath, String name) throws GitError { try { Git git = Git.open(new File(localPath)); CheckoutCommand co = git.checkout(); co.setName(name); co.call(); } catch (Exception e) { GittApp.saveErrorTrace(e); throw new GitError(); } }