Example usage for org.eclipse.jgit.lib Constants HEAD

List of usage examples for org.eclipse.jgit.lib Constants HEAD

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants HEAD.

Prototype

String HEAD

To view the source code for org.eclipse.jgit.lib Constants HEAD.

Click Source Link

Document

Special name for the "HEAD" symbolic-ref.

Usage

From source file:org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriberTest.java

License:Open Source License

/**
 * Both source and destination branches has some different commits but they
 * has also common ancestor. This situation is described more detailed in
 * bug #317934//from  w w  w  .j av  a2s. com
 *
 * This test passes when it is run as a stand alone test case, but it fails
 * when it is run as part of test suite. It throws NPE when it try's to
 * checkout master branch.
 *
 * @throws Exception
 */
@Test
@Ignore
public void shouldReturnCommonAncestorAsBase() throws Exception {
    // when
    String fileName = "Main.java";
    File file = testRepo.createFile(iProject, fileName);
    RevCommit commit = testRepo.appendContentAndCommit(iProject, file, "class Main {}", "initial commit");
    IFile mainJava = testRepo.getIFile(iProject, file);
    // this should be our common ancestor
    ObjectId fileId = findFileId(commit, mainJava);

    testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS + "test");
    testRepo.appendContentAndCommit(iProject, file, "// test 1", "second commit");

    testRepo.checkoutBranch(Constants.R_HEADS + Constants.MASTER);
    testRepo.appendContentAndCommit(iProject, file, "// test 2", "third commit");

    // given
    GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(Constants.HEAD,
            Constants.R_HEADS + "test");
    grvts.getBaseTree();
    IResourceVariantTree baseTree = grvts.getBaseTree();

    // then
    IResourceVariant actual = commonAssertionsForBaseTree(baseTree, mainJava);
    assertEquals(fileId.getName(), actual.getContentIdentifier());
}

From source file:org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriberTest.java

License:Open Source License

/**
 * This test passes when it is run as a stand alone test case, but it fails
 * when it is run as part of test suite. It throws NPE when it try's to
 * checkout master branch.//from  w  w  w.ja v a 2 s. c  o m
 *
 * @throws Exception
 */
@Test
@Ignore
public void shouldReturnRemoteTree() throws Exception {
    // when
    String fileName = "Main.java";
    File file = testRepo.createFile(iProject, fileName);
    testRepo.appendContentAndCommit(iProject, file, "class Main {}", "initial commit");
    IFile mainJava = testRepo.getIFile(iProject, file);

    testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS + "test");
    RevCommit commit = testRepo.appendContentAndCommit(iProject, file, "// test 1", "second commit");
    ObjectId fileId = findFileId(commit, mainJava);

    // given
    GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(Constants.HEAD, "test");
    grvts.getBaseTree();
    IResourceVariantTree remoteTree = grvts.getRemoteTree();

    // then
    assertNotNull(remoteTree);
    assertTrue(remoteTree instanceof GitRemoteResourceVariantTree);
    IResourceVariant resourceVariant = remoteTree.getResourceVariant(mainJava);
    assertNotNull(resourceVariant);
    assertTrue(resourceVariant instanceof GitResourceVariant);
    assertEquals(fileId.getName(), resourceVariant.getContentIdentifier());
}

From source file:org.eclipse.egit.core.synchronize.GitResourceVariantTreeSubscriberTest2.java

License:Open Source License

/**
 * Both source and destination branches has some different commits but they
 * has also common ancestor. This situation is described more detailed in
 * bug #317934/*  ww w. j  a v  a  2s . co  m*/
 *
 * This test passes when it is run as a stand alone test case, but it fails
 * when it is run as part of test suite. It throws NPE when it try's to
 * checkout master branch.
 *
 * @throws Exception
 */
@Test
public void shouldReturnCommonAncestorAsBase() throws Exception {
    // when
    String fileName = "Main.java";
    File file = testRepo.createFile(iProject, fileName);
    RevCommit commit = testRepo.appendContentAndCommit(iProject, file, "class Main {}", "initial commit");
    IFile mainJava = testRepo.getIFile(iProject, file);
    // this should be our common ancestor

    testRepo.createAndCheckoutBranch(Constants.HEAD, Constants.R_HEADS + "test");
    testRepo.appendContentAndCommit(iProject, file, "// test 1", "second commit");

    testRepo.checkoutBranch(Constants.R_HEADS + Constants.MASTER);
    testRepo.appendContentAndCommit(iProject, file, "// test 2", "third commit");

    // given
    GitResourceVariantTreeSubscriber grvts = createGitResourceVariantTreeSubscriber(Constants.HEAD,
            Constants.R_HEADS + "test");
    grvts.getBaseTree();
    IResourceVariantTree baseTree = grvts.getBaseTree();

    // then
    IResourceVariant actual = commonAssertionsForBaseTree(baseTree, mainJava);
    assertEquals(commit.abbreviate(7).name() + "...", actual.getContentIdentifier());
}

From source file:org.eclipse.egit.core.test.op.EditCommitOperationTest.java

License:Open Source License

@Test
public void edit() throws Exception {
    EditCommitOperation op = new EditCommitOperation(testRepository.getRepository(), firstCommit);
    op.execute(new NullProgressMonitor());

    assertEquals(RepositoryState.REBASING_INTERACTIVE, testRepository.getRepository().getRepositoryState());

    List<RebaseTodoLine> todos = testRepository.getRepository().readRebaseTodo(GIT_REBASE_TODO, false);
    assertEquals(1, todos.size());/*w  w  w . j  a va 2 s .  c o  m*/
    assertEquals(RebaseTodoLine.Action.PICK, todos.get(0).getAction());
    assertTrue(secondCommit.getId().startsWith(todos.get(0).getCommit()));

    ObjectId headId = testRepository.getRepository().resolve(Constants.HEAD);
    assertEquals(firstCommit.getId(), headId);
}

From source file:org.eclipse.egit.core.test.op.RebaseOperationTest.java

License:Open Source License

@Test
public void testStopAndAbortOnConflict() throws Exception {
    IFile file = project.createFile("theFile.txt", "Hello, world".getBytes("UTF-8"));
    // first commit in master: add theFile.txt
    RevCommit first = testRepository.addAndCommit(project.project, new File(file.getLocationURI()),
            "Adding theFile.txt");

    testRepository.createBranch(MASTER, TOPIC);

    file.setContents(new ByteArrayInputStream("master".getBytes("UTF-8")), 0, null);
    // second commit in master: modify theFile.txt
    RevCommit second = git.commit().setAll(true).setMessage("Modify theFile.txt").call();
    assertEquals(first, second.getParent(0));

    // checkout topic
    testRepository.checkoutBranch(TOPIC);

    // set conflicting content in topic
    file.setContents(new ByteArrayInputStream("topic".getBytes("UTF-8")), 0, null);
    // topic commit: add second file
    RevCommit topicCommit = testRepository.addAndCommit(project.project, new File(file.getLocationURI()),
            "Changing theFile.txt again");

    // parent of topic commit should be first master commit before rebase
    assertEquals(first, topicCommit.getParent(0));

    // rebase topic onto master
    RebaseOperation op = new RebaseOperation(testRepository.getRepository(),
            testRepository.getRepository().getRef(MASTER));
    op.execute(null);/*from www  .j  av  a  2 s.c  o  m*/

    RebaseResult res = op.getResult();
    assertEquals(RebaseResult.Status.STOPPED, res.getStatus());

    // let's try to abort this here
    RebaseOperation abort = new RebaseOperation(repository, Operation.ABORT);
    abort.execute(null);
    RebaseResult abortResult = abort.getResult();
    assertEquals(Status.ABORTED, abortResult.getStatus());

    assertEquals(topicCommit, repository.resolve(Constants.HEAD));
}

From source file:org.eclipse.egit.core.test.TestRepository.java

License:Open Source License

/**
 * Checks if a file with the given path exists in the HEAD tree
 *
 * @param path/*w  w  w .  j  a  v  a 2 s. c  o  m*/
 * @return true if the file exists
 * @throws IOException
 */
public boolean inHead(String path) throws IOException {
    ObjectId headId = repository.resolve(Constants.HEAD);
    RevWalk rw = new RevWalk(repository);
    TreeWalk tw = null;
    try {
        tw = TreeWalk.forPath(repository, path, rw.parseTree(headId));
        return tw != null;
    } finally {
        rw.release();
        rw.dispose();
        if (tw != null)
            tw.release();
    }
}

From source file:org.eclipse.egit.internal.relengtools.GitCopyrightAdapter.java

License:Open Source License

@Override
public int getLastModifiedYear(IFile file, IProgressMonitor monitor) throws CoreException {
    try {/*from  ww w.j  a  v  a 2s.  c o m*/
        monitor.beginTask("Fetching logs from Git", 100); //$NON-NLS-1$
        final RepositoryMapping mapping = RepositoryMapping.getMapping(file);
        if (mapping != null) {
            final Repository repo = mapping.getRepository();
            if (repo != null) {
                RevWalk walk = null;
                try {
                    final ObjectId start = repo.resolve(Constants.HEAD);
                    walk = new RevWalk(repo);
                    walk.setTreeFilter(PathFilter.create(mapping.getRepoRelativePath(file)));
                    walk.markStart(walk.lookupCommit(start));
                    final RevCommit commit = walk.next();
                    if (commit != null) {
                        if (filterString != null
                                && commit.getFullMessage().toLowerCase().indexOf(filterString) != -1) {
                            // the last update was a copyright checkin -
                            // ignore
                            return 0;
                        }
                        final Calendar calendar = Calendar.getInstance();
                        calendar.setTimeInMillis(0);
                        calendar.add(Calendar.SECOND, commit.getCommitTime());
                        return calendar.get(Calendar.YEAR);
                    }
                } catch (final IOException e) {
                    throw new CoreException(new Status(IStatus.ERROR, "org.eclipse.egit.relengtools", 0,
                            NLS.bind("An error occured when processing {0}", file.getName()), e));
                } finally {
                    if (walk != null)
                        walk.release();
                }
            }
        }
    } finally {
        monitor.done();
    }

    return -1;
}

From source file:org.eclipse.egit.internal.relengtools.ReleaseWizard.java

License:Open Source License

private void tagProject(IProject project, IProgressMonitor monitor) throws Exception {
    monitor = new SubProgressMonitor(monitor, 1);
    monitor.beginTask("Tagging " + project.getName(), 1);

    final boolean shouldMoveTag = tagPage.isMoveButtonSelected();
    final RepositoryMapping rm = RepositoryMapping.getMapping(project);
    final Repository repository = rm.getRepository();

    final RevWalk rw = new RevWalk(repository);
    final RevObject target = rw.parseAny(repository.resolve(Constants.HEAD));

    final PersonIdent personIdent = new PersonIdent(repository);
    final String tagName = tagPage.getTagString();
    final TagBuilder tag = new TagBuilder();
    tag.setTag(tagName);/*from   w  w w.j  a v  a  2  s.  c om*/
    tag.setTagger(personIdent);
    tag.setObjectId(target);

    final TagOperation operation = new TagOperation(repository, tag, shouldMoveTag);

    operation.execute(monitor);
    monitor.done();
}

From source file:org.eclipse.egit.internal.relengtools.ShowInfoHandler.java

License:Open Source License

public static RevCommit getLatestCommitFor(RepositoryMapping mapping, Repository repo, IProject project)
        throws Exception {
    final RevWalk walk = new RevWalk(repo);
    walk.reset();//from w w w.  j av  a2 s.  c  o  m
    walk.sort(RevSort.TOPO, true);
    walk.sort(RevSort.COMMIT_TIME_DESC, true);
    walk.setTreeFilter(
            AndTreeFilter.create(TreeFilter.ANY_DIFF, PathFilter.create(mapping.getRepoRelativePath(project))));
    final ObjectId start = repo.resolve(Constants.HEAD);
    walk.markStart(walk.parseCommit(start));

    // I should only be able to see commits that contain files
    // where project is a path prefix
    final RevCommit commit = walk.next();
    return commit;
}

From source file:org.eclipse.egit.ui.internal.actions.CommitAction.java

License:Open Source License

private void loadPreviousCommit() {
    IProject project = getProjectsForSelectedResources()[0];

    Repository repo = RepositoryMapping.getMapping(project).getRepository();
    try {// w  w w.j av a2  s  .c om
        ObjectId parentId = repo.resolve(Constants.HEAD);
        if (parentId != null)
            previousCommit = repo.mapCommit(parentId);
    } catch (IOException e) {
        Utils.handleError(getTargetPart().getSite().getShell(), e, UIText.CommitAction_errorDuringCommit,
                UIText.CommitAction_errorRetrievingCommit);
    }
}