List of usage examples for org.eclipse.jgit.lib RefUpdate delete
public Result delete() throws IOException
From source file:com.google.gerrit.server.StarredChangesUtil.java
License:Apache License
public void unstar(Account.Id accountId, Project.NameKey project, Change.Id changeId) throws OrmException { try (Repository repo = repoManager.openRepository(allUsers); RevWalk rw = new RevWalk(repo)) { RefUpdate u = repo.updateRef(RefNames.refsStarredChanges(changeId, accountId)); u.setForceUpdate(true);/*w w w.j a v a2 s .co m*/ u.setRefLogIdent(serverIdent); u.setRefLogMessage("Unstar change " + changeId.get(), true); RefUpdate.Result result = u.delete(); switch (result) { case FORCED: indexer.index(dbProvider.get(), project, changeId); return; case FAST_FORWARD: case IO_FAILURE: case LOCK_FAILURE: case NEW: case NOT_ATTEMPTED: case NO_CHANGE: case REJECTED: case REJECTED_CURRENT_BRANCH: case RENAMED: default: throw new OrmException(String.format("Unstar change %d for account %d failed: %s", changeId.get(), accountId.get(), result.name())); } } catch (IOException e) { throw new OrmException( String.format("Unstar change %d for account %d failed", changeId.get(), accountId.get()), e); } }
From source file:com.googlesource.gerrit.plugins.manifest.TempRef.java
License:Apache License
public void close() throws IOException { Repository repo = repoManager.openRepository(tempRef.getParentKey()); try {/*from ww w . j a va2s . c om*/ RefUpdate refUpdate = repo.updateRef(tempRef.get()); refUpdate.setNewObjectId(ObjectId.zeroId()); refUpdate.setForceUpdate(true); refUpdate.delete(); } finally { tempRef = null; repo.close(); } }
From source file:com.madgag.agit.TagViewer.java
License:Open Source License
@Override public boolean onOptionsItemSelected(MenuItem item) { Log.i(TAG, "onOptionsItemSelected " + item); switch (item.getItemId()) { case DELETE_ID: try {/*from w w w . j a v a2 s .c om*/ RefUpdate update = repo().updateRef(tagRef.getName()); update.setForceUpdate(true); // update.setNewObjectId(head); // update.setForceUpdate(force || remote); Result result = update.delete(); Toast.makeText(this, "Tag deletion : " + result.name(), Toast.LENGTH_SHORT).show(); finish(); } catch (IOException e) { Log.e(TAG, "Couldn't delete " + revTag.getName(), e); throw new RuntimeException(e); } return true; } return super.onOptionsItemSelected(item); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitServerUtil.java
License:Apache License
/** * Removes branches of a bare repository which are not present in a remote repository *///ww w . j av a 2s . c o m private static void pruneRemovedBranches(@NotNull Repository db, @NotNull Transport tn) throws IOException { FetchConnection conn = null; try { conn = tn.openFetch(); Map<String, Ref> remoteRefMap = conn.getRefsMap(); for (Map.Entry<String, Ref> e : db.getAllRefs().entrySet()) { if (!remoteRefMap.containsKey(e.getKey())) { try { RefUpdate refUpdate = db.getRefDatabase().newUpdate(e.getKey(), false); refUpdate.setForceUpdate(true); refUpdate.delete(); } catch (Exception ex) { LOG.info("Failed to prune removed ref " + e.getKey(), ex); break; } } } } finally { if (conn != null) conn.close(); } }
From source file:models.PullRequest.java
License:Apache License
public PullRequestMergeResult attemptMerge() throws IOException, GitAPIException { // fetch the branch to merge String tempBranchToCheckConflict = fetchSourceTemporarilly(); // merge// w ww . j a va2 s. c o m Merger.MergeResult mergeResult = new Merger(toBranch, tempBranchToCheckConflict).merge(); // Make a PullRequestMergeResult to return PullRequestMergeResult pullRequestMergeResult = new PullRequestMergeResult(); pullRequestMergeResult.setPullRequest(this); if (mergeResult.conflicts()) { pullRequestMergeResult.setConflictStateOfPullRequest(); } else { pullRequestMergeResult.setResolvedStateOfPullRequest(); } pullRequestMergeResult.setGitCommits(GitRepository.diffCommits(getRepository(), mergeResult.getLeftParentId(), mergeResult.getRightParentId())); // Clean Up: Delete the temporary branch RefUpdate refUpdate = getRepository().updateRef(tempBranchToCheckConflict); refUpdate.setForceUpdate(true); refUpdate.delete(); return pullRequestMergeResult; }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
@Override public void tagDelete(TagDeleteRequest request) throws GitException { try {/* ww w . j a v a 2 s .c om*/ String tagName = request.getName(); Ref tagRef = repository.findRef(tagName); if (tagRef == null) { throw new IllegalArgumentException("Tag " + tagName + " not found. "); } RefUpdate updateRef = repository.updateRef(tagRef.getName()); updateRef.setRefLogMessage("tag deleted", false); updateRef.setForceUpdate(true); Result deleteResult = updateRef.delete(); if (deleteResult != Result.FORCED && deleteResult != Result.FAST_FORWARD) { throw new GitException(String.format(ERROR_TAG_DELETE, tagName, deleteResult)); } } catch (IOException exception) { throw new GitException(exception.getMessage(), exception); } }
From source file:org.eclipse.egit.ui.common.LocalRepositoryTestCase.java
License:Open Source License
protected static File createRemoteRepository(File repositoryDir) throws Exception { FileRepository myRepository = lookupRepository(repositoryDir); File gitDir = new File(testDirectory, REPO2); Repository myRemoteRepository = new FileRepository(gitDir); myRemoteRepository.create();//from ww w . ja va 2s . c o m // double-check that this is bare assertTrue(myRemoteRepository.isBare()); createStableBranch(myRepository); // now we configure a pure push destination myRepository.getConfig().setString("remote", "push", "pushurl", "file:///" + myRemoteRepository.getDirectory().getPath()); myRepository.getConfig().setString("remote", "push", "push", "+refs/heads/*:refs/heads/*"); // and a pure fetch destination myRepository.getConfig().setString("remote", "fetch", "url", "file:///" + myRemoteRepository.getDirectory().getPath()); myRepository.getConfig().setString("remote", "fetch", "fetch", "+refs/heads/*:refs/heads/*"); // a destination with both fetch and push urls and specs myRepository.getConfig().setString("remote", "both", "pushurl", "file:///" + myRemoteRepository.getDirectory().getPath()); myRepository.getConfig().setString("remote", "both", "push", "+refs/heads/*:refs/heads/*"); myRepository.getConfig().setString("remote", "both", "url", "file:///" + myRemoteRepository.getDirectory().getPath()); myRepository.getConfig().setString("remote", "both", "fetch", "+refs/heads/*:refs/heads/*"); // a destination with only a fetch url and push and fetch specs myRepository.getConfig().setString("remote", "mixed", "push", "+refs/heads/*:refs/heads/*"); myRepository.getConfig().setString("remote", "mixed", "url", "file:///" + myRemoteRepository.getDirectory().getPath()); myRepository.getConfig().setString("remote", "mixed", "fetch", "+refs/heads/*:refs/heads/*"); myRepository.getConfig().save(); // and push PushConfiguredRemoteAction pa = new PushConfiguredRemoteAction(myRepository, "push"); pa.run(null, false); try { // delete the stable branch again RefUpdate op = myRepository.updateRef("refs/heads/stable"); op.setRefLogMessage("branch deleted", //$NON-NLS-1$ false); // we set the force update in order // to avoid having this rejected // due to minor issues op.setForceUpdate(true); op.delete(); } catch (IOException ioe) { throw new InvocationTargetException(ioe); } return myRemoteRepository.getDirectory(); }
From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTagHandlingTest.java
License:Open Source License
@Before public void before() throws Exception { repository = lookupRepository(repositoryFile); for (String ref : repository.getTags().keySet()) { RefUpdate op = repository.updateRef(ref, true); op.setRefLogMessage("tag deleted", //$NON-NLS-1$ false);//w w w . ja va2 s. c om // we set the force update in order // to avoid having this rejected // due to minor issues op.setForceUpdate(true); op.delete(); } revWalk = new RevWalk(repository); }
From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewTestBase.java
License:Open Source License
protected static File createRemoteRepository(File repositoryDir) throws Exception { Repository myRepository = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache() .lookupRepository(repositoryDir); File gitDir = new File(getTestDirectory(), REPO2); Repository myRemoteRepository = lookupRepository(gitDir); myRemoteRepository.create();//from w w w . j a v a 2 s . co m createStableBranch(myRepository); // now we configure the push destination myRepository.getConfig().setString("remote", "push", "pushurl", "file:///" + myRemoteRepository.getDirectory().getPath()); myRepository.getConfig().setString("remote", "push", "push", "+refs/heads/*:refs/heads/*"); // TODO Bug: for some reason, this seems to be required myRepository.getConfig().setString(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, "0"); myRepository.getConfig().save(); // and push PushConfiguredRemoteAction pa = new PushConfiguredRemoteAction(myRepository, "push"); pa.run(null, false); TestUtil.joinJobs(JobFamilies.PUSH); try { // delete the stable branch again RefUpdate op = myRepository.updateRef("refs/heads/stable"); op.setRefLogMessage("branch deleted", //$NON-NLS-1$ false); // we set the force update in order // to avoid having this rejected // due to minor issues op.setForceUpdate(true); op.delete(); } catch (IOException ioe) { throw new InvocationTargetException(ioe); } return myRemoteRepository.getDirectory(); }
From source file:org.jfrog.bamboo.release.scm.git.DeleteTagCommand.java
License:Eclipse Distribution License
/** * Executes the {@code tag} command with all the options and parameters collected by the setter methods of this * class. Each instance of this class should only be used for one invocation of the command (means: one call to * {@link #call()})//from ww w . j a v a 2s .co m * * @return a {@link RevTag} object representing the successful tag * @throws NoHeadException when called on a git repo without a HEAD reference * @throws JGitInternalException a low-level exception of JGit has occurred. The original exception can be retrieved * by calling {@link Exception#getCause()}. Expect only {@code IOException's} to be * wrapped. */ @Override public RefUpdate.Result call() throws JGitInternalException, ConcurrentRefUpdateException, InvalidTagNameException, NoHeadException { checkCallable(); RepositoryState state = repo.getRepositoryState(); processOptions(state); Map<String, Ref> tags = repo.getTags(); for (Map.Entry<String, Ref> entry : tags.entrySet()) { if (entry.getKey().equals(getName())) { Ref value = entry.getValue(); RefUpdate update; try { update = repo.updateRef(value.getName()); update.setForceUpdate(true); RefUpdate.Result delete = update.delete(); return delete; } catch (IOException e) { throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfTagCommand, e); } } } throw new JGitInternalException(JGitText.get().exceptionCaughtDuringExecutionOfTagCommand); }