Example usage for org.eclipse.jgit.lib Repository exactRef

List of usage examples for org.eclipse.jgit.lib Repository exactRef

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Repository exactRef.

Prototype

@Nullable
public final Ref exactRef(String name) throws IOException 

Source Link

Document

Get a ref by name.

Usage

From source file:com.google.gerrit.server.project.DeleteRef.java

License:Apache License

private ReceiveCommand createDeleteCommand(ProjectResource project, Repository r, String refName)
        throws OrmException, IOException, ResourceConflictException {
    Ref ref = r.getRefDatabase().getRef(refName);
    ReceiveCommand command;// w  w w.j a  va  2s  . c  o m
    if (ref == null) {
        command = new ReceiveCommand(ObjectId.zeroId(), ObjectId.zeroId(), refName);
        command.setResult(Result.REJECTED_OTHER_REASON,
                "it doesn't exist or you do not have permission to delete it");
        return command;
    }
    command = new ReceiveCommand(ref.getObjectId(), ObjectId.zeroId(), ref.getName());

    if (!project.getControl().controlForRef(refName).canDelete()) {
        command.setResult(Result.REJECTED_OTHER_REASON,
                "it doesn't exist or you do not have permission to delete it");
    }

    if (!refName.startsWith(R_TAGS)) {
        Branch.NameKey branchKey = new Branch.NameKey(project.getNameKey(), ref.getName());
        if (!queryProvider.get().setLimit(1).byBranchOpen(branchKey).isEmpty()) {
            command.setResult(Result.REJECTED_OTHER_REASON, "it has open changes");
        }
    }

    RefUpdate u = r.updateRef(refName);
    u.setForceUpdate(true);
    u.setExpectedOldObjectId(r.exactRef(refName).getObjectId());
    u.setNewObjectId(ObjectId.zeroId());
    refDeletionValidator.validateRefOperation(project.getName(), identifiedUser.get(), u);
    return command;
}

From source file:com.google.gerrit.server.StarredChangesUtil.java

License:Apache License

private static ObjectId getObjectId(Repository repo, String refName) throws IOException {
    Ref ref = repo.exactRef(refName);
    return ref != null ? ref.getObjectId() : ObjectId.zeroId();
}

From source file:com.mangosolutions.rcloud.rawgist.repository.git.ReadGistOperation.java

private RevCommit resolveCommit(Repository repository) throws IOException {
    try (RevWalk revWalk = new RevWalk(repository)) {
        if (StringUtils.isEmpty(commitId)) {
            Ref head = repository.exactRef(REF_HEAD_MASTER);
            if (head != null) {
                return revWalk.parseCommit(head.getObjectId());
            }/*from  w w w.  j  a v  a 2s .  co m*/
            return null;
        } else {
            return revWalk.parseCommit(ObjectId.fromString(this.commitId));
        }
    }
}

From source file:org.dstadler.jgit.porcelain.ShowBranchDiff.java

License:Apache License

private static AbstractTreeIterator prepareTreeParser(Repository repository, String ref) throws IOException {
    // from the commit we can build the tree which allows us to construct the TreeParser
    Ref head = repository.exactRef(ref);
    try (RevWalk walk = new RevWalk(repository)) {
        RevCommit commit = walk.parseCommit(head.getObjectId());
        RevTree tree = walk.parseTree(commit.getTree().getId());

        CanonicalTreeParser oldTreeParser = new CanonicalTreeParser();
        try (ObjectReader oldReader = repository.newObjectReader()) {
            oldTreeParser.reset(oldReader, tree.getId());
        }/*from  w  w w  .  j av a2s  . c  om*/

        walk.dispose();

        return oldTreeParser;
    }
}

From source file:org.eclipse.egit.gitflow.GitFlowRepositoryTest.java

License:Open Source License

@Test
public void testGetFeatureBranchName() throws Exception {
    repository1.createInitialCommit("testGetFeatureBranchName\n\nfirst commit\n");

    Repository repository = repository1.getRepository();
    GitFlowRepository gfRepo = new GitFlowRepository(repository);

    InitParameters initParameters = new InitParameters();
    initParameters.setDevelop(DEVELOP);/*from  www .  j  a  v a  2 s . c o m*/
    initParameters.setMaster(GitFlowDefaults.MASTER);
    initParameters.setFeature(FEATURE_PREFIX);
    initParameters.setRelease(RELEASE_PREFIX);
    initParameters.setHotfix(HOTFIX_PREFIX);
    initParameters.setVersionTag(VERSION_TAG);
    new InitOperation(repository, initParameters).execute(null);

    assertTrue(gfRepo.getFeatureBranches().isEmpty());

    new FeatureStartOperation(gfRepo, MY_FEATURE).execute(null);

    Ref actualFeatureRef = repository.exactRef(R_HEADS + gfRepo.getConfig().getFeaturePrefix() + MY_FEATURE);
    assertEquals(MY_FEATURE, gfRepo.getFeatureBranchName(actualFeatureRef));
}

From source file:org.eclipse.egit.gitflow.op.AbstractGitFlowOperationTest.java

License:Open Source License

protected Ref findBranch(Repository repository, String branchName) throws IOException {
    return repository.exactRef(R_HEADS + branchName);
}

From source file:org.eclipse.egit.gitflow.op.FeatureRebaseOperation.java

License:Open Source License

@Override
public void execute(IProgressMonitor monitor) throws CoreException {
    try {/*from  www .  j  a v a  2s .  com*/
        if (!repository.isFeature()) {
            throw new WrongGitFlowStateException(CoreText.FeatureRebaseOperation_notOnAFeatureBranch);
        }

        Repository jgitRepo = repository.getRepository();
        Ref develop = jgitRepo.exactRef(repository.getConfig().getDevelopFull());
        RebaseOperation op = new RebaseOperation(jgitRepo, develop);
        op.execute(null);

        operationResult = op.getResult();
    } catch (WrongGitFlowStateException | IOException e) {
        throw new CoreException(error(e.getMessage(), e));
    }
}

From source file:org.eclipse.egit.gitflow.ui.internal.dialogs.FeatureBranchSelectionDialog.java

License:Open Source License

private void checkPage() {
    List<Ref> selection = filteredFeatures.getSelection();
    if (selection.isEmpty() || selection.get(0) == null) {
        getButton(OK).setEnabled(false);
        return;//from w  w w  . j a  va  2s  . c  o  m
    }
    Repository repository = gfRepo.getRepository();
    try {
        Ref currentBranch = repository.exactRef(repository.getFullBranch());
        getButton(OK).setEnabled(!selection.get(0).equals(currentBranch));
    } catch (IOException e) {
        Activator.logError("Unable to find current branch", e); //$NON-NLS-1$
    }
}

From source file:org.eclipse.egit.gitflow.ui.internal.dialogs.InitDialog.java

License:Open Source License

private boolean isMasterBranchAvailable(String master, Repository repository) {
    try {//w  w  w .ja  v  a2 s.c  om
        return repository.exactRef(R_HEADS + master) != null;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.egit.ui.gitflow.InitHandlerTest.java

License:Open Source License

@Test
public void testInitEmptyRepoMissingMaster() throws Exception {
    String projectName = "AnyProjectName";
    TestRepository testRepository = createAndShare(projectName);

    selectProject(projectName);//from w w w  . j a  va 2 s .co m
    clickInit();
    bot.button("Yes").click();
    fillDialog(MASTER_BRANCH_MISSING);
    bot.waitUntil(shellIsActive(UIText.InitDialog_masterBranchIsMissing));
    bot.button("Yes").click();
    bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, "Git flow jobs"));

    Repository localRepository = testRepository.getRepository();
    GitFlowRepository gitFlowRepository = new GitFlowRepository(localRepository);
    GitFlowConfig config = gitFlowRepository.getConfig();

    assertEquals(DEVELOP_BRANCH, localRepository.getBranch());
    assertEquals(MASTER_BRANCH_MISSING, config.getMaster());
    assertEquals(FEATURE_BRANCH_PREFIX, config.getFeaturePrefix());
    assertEquals(RELEASE_BRANCH_PREFIX, config.getReleasePrefix());
    assertEquals(HOTFIX_BRANCH_PREFIX, config.getHotfixPrefix());
    assertEquals(VERSION_TAG_PREFIX, config.getVersionTagPrefix());

    assertNotNull(localRepository.exactRef(Constants.R_HEADS + DEVELOP_BRANCH));
}