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

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

Introduction

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

Prototype

@Nullable
public ObjectId resolve(String revstr)
        throws AmbiguousObjectException, IncorrectObjectTypeException, RevisionSyntaxException, IOException 

Source Link

Document

Parse a git revision string and return an object id.

Usage

From source file:org.eclipse.egit.ui.test.history.HistoryViewTest.java

License:Open Source License

@Test
public void testAddTag() throws Exception {
    Repository repo = lookupRepository(repoFile);
    assertNull(repo.resolve(Constants.R_TAGS + "NewTag"));
    final SWTBotTable table = getHistoryViewTable(PROJ1);
    table.getTableItem(0).select();/*from ww w .j  ava 2  s .c o m*/
    final RevCommit[] commit = new RevCommit[1];

    Display.getDefault().syncExec(new Runnable() {

        public void run() {
            TableItem tableItem = table.widget.getSelection()[0];
            ensureTableItemLoaded(tableItem);
            commit[0] = (RevCommit) tableItem.getData();
        }
    });

    ContextMenuHelper.clickContextMenu(table, UIText.GitHistoryPage_CreateTagMenuLabel);
    SWTBotShell dialog = bot.shell(UIText.CreateTagDialog_NewTag);
    dialog.bot().textWithLabel(UIText.CreateTagDialog_tagName).setText("NewTag");
    dialog.bot().styledTextWithLabel(UIText.CreateTagDialog_tagMessage).setText("New Tag message");
    dialog.bot().button(IDialogConstants.OK_LABEL).click();
    TestUtil.joinJobs(JobFamilies.TAG);
    assertNotNull(repo.resolve(Constants.R_TAGS + "NewTag"));
}

From source file:org.eclipse.egit.ui.test.team.actions.BranchAndResetActionTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);//from  w w  w .j av  a  2 s.  c om
    touchAndSubmit(null);

    RepositoriesViewLabelProvider provider = new RepositoriesViewLabelProvider();
    LOCAL_BRANCHES = provider.getText(new LocalNode(new RepositoryNode(null, repo), repo));
    TAGS = provider.getText(new TagsNode(new RepositoryNode(null, repo), repo));
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.CommitActionTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    // TODO delete the second project for the time being (.gitignore is
    // currently not hiding the .project file from commit)
    ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2).delete(false, null);

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);//from w  w w.j  av  a 2  s  .  co  m
    touchAndSubmit(null);

    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.CompareActionsTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    commitOfTag = tag.getObjectId();//from  w ww .j a v a2 s .  c  o m
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);
    touchAndSubmit(null);

    RepositoriesViewLabelProvider provider = GitRepositoriesViewTestUtils.createLabelProvider();
    // LOCAL_BRANCHES = provider.getText(new LocalNode(new RepositoryNode(
    // null, repo), repo));
    TAGS = provider.getText(new TagsNode(new RepositoryNode(null, repo), repo));
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.CompareActionsTest.java

License:Open Source License

@Test
public void testCompareWithPreviousWithMerge() throws Exception {
    Repository repo = lookupRepository(repositoryFile);

    Git git = new Git(repo);
    ObjectId masterId = repo.resolve("refs/heads/master");
    Ref newBranch = git.checkout().setCreateBranch(true).setStartPoint(commitOfTag.name()).setName("toMerge")
            .call();//  ww w .j a  v  a 2  s.c  o m
    ByteArrayInputStream bis = new ByteArrayInputStream("Modified".getBytes());
    ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1).getFolder(FOLDER).getFile(FILE2).setContents(bis,
            false, false, null);
    bis.close();
    git.commit().setAll(true).setMessage("To be merged").call();
    git.merge().include(masterId).call();
    String menuLabel = util.getPluginLocalizedValue("CompareWithPreviousAction.label");
    SWTBotShell selectDialog = openCompareWithDialog(menuLabel, UIText.CommitSelectDialog_WindowTitle);
    assertEquals(2, selectDialog.bot().table().rowCount());
    selectDialog.close();
    // cleanup: checkout again master and delete merged branch
    git.checkout().setName("refs/heads/master").call();
    git.branchDelete().setBranchNames(newBranch.getName()).setForce(true).call();
}

From source file:org.eclipse.egit.ui.test.team.actions.FetchAndMergeActionTest.java

License:Open Source License

private String prepare() throws Exception {
    deleteAllProjects();//  ww  w  .j ava 2s . com
    shareProjects(repositoryFile);
    Repository repo = lookupRepository(repositoryFile);
    RevWalk rw = new RevWalk(repo);
    ObjectId id = repo.resolve(repo.getFullBranch());
    String commitId = rw.parseCommit(id).name();
    touchAndSubmit(null);
    deleteAllProjects();
    shareProjects(childRepositoryFile);
    waitInUI();
    return commitId;
}

From source file:org.eclipse.egit.ui.test.team.actions.PushActionTest.java

License:Open Source License

private void pushTo(String destination, boolean withConfirmPage)
        throws Exception, MissingObjectException, IncorrectObjectTypeException, IOException {
    Repository repo = lookupRepository(remoteRepositoryFile);
    RevWalk rw = new RevWalk(repo);
    String previous = rw.parseCommit(repo.resolve("HEAD")).name();

    touchAndSubmit(null);/*from   ww w.  ja v a2  s.com*/
    SWTBotShell pushDialog = openPushDialog();

    SWTBotCombo destinationCombo = pushDialog.bot().comboBox();
    String[] items = destinationCombo.items();
    for (int i = 0; i < items.length; i++) {
        if (items[i].startsWith(destination))
            destinationCombo.setSelection(i);
    }

    pushDialog.bot().button(IDialogConstants.NEXT_LABEL).click();
    if (withConfirmPage)
        pushDialog.bot().button(IDialogConstants.NEXT_LABEL).click();
    pushDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
    SWTBotShell confirm = bot.shell(NLS.bind(UIText.ResultDialog_title, destination));
    String result = confirm.bot().table().getTableItem(0).getText(3);

    assertTrue("Wrong result", previous.startsWith(result.substring(0, 7)));

    confirm.close();

    pushDialog = openPushDialog();

    destinationCombo = pushDialog.bot().comboBox();
    for (int i = 0; i < items.length; i++) {
        if (items[i].startsWith(destination))
            destinationCombo.setSelection(i);
    }

    pushDialog.bot().button(IDialogConstants.NEXT_LABEL).click();
    if (withConfirmPage)
        pushDialog.bot().button(IDialogConstants.NEXT_LABEL).click();
    pushDialog.bot().button(IDialogConstants.FINISH_LABEL).click();
    confirm = bot.shell(NLS.bind(UIText.ResultDialog_title, destination));
    result = confirm.bot().table().getTableItem(0).getText(3);

    confirm.close();

    assertEquals("Wrong result", UIText.PushResultTable_statusUpToDate, result);
}

From source file:org.eclipse.egit.ui.test.team.actions.ReplaceActionsTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    commitOfTag = tag.getObjectId();//from  ww w.  j  av  a2s  . c o m
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);
    touchAndSubmit(null);
    waitInUI();
}

From source file:org.eclipse.egit.ui.test.team.actions.ReplaceActionsTest.java

License:Open Source License

@Test
public void testReplaceWithPreviousWithMerge() throws Exception {
    Repository repo = lookupRepository(repositoryFile);
    Git git = new Git(repo);
    ObjectId masterId = repo.resolve("refs/heads/master");
    Ref newBranch = git.checkout().setCreateBranch(true).setStartPoint(commitOfTag.name()).setName("toMerge")
            .call();/* ww w  . j  ava 2 s .com*/
    ByteArrayInputStream bis = new ByteArrayInputStream("Modified".getBytes());
    ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1).getFolder(FOLDER).getFile(FILE2).setContents(bis,
            false, false, null);
    bis.close();
    PersonIdent committer = new PersonIdent("COMMITTER", "a.c@d", new Date(),
            TimeZone.getTimeZone("GMT-03:30"));
    git.commit().setAll(true).setCommitter(committer).setMessage("To be merged").call();
    git.merge().include(masterId).call();
    String newContent = getTestFileContent();
    String menuLabel = util.getPluginLocalizedValue("replaceWithPreviousVersionAction.label");
    clickReplaceWith(menuLabel);
    bot.shell(UIText.DiscardChangesAction_confirmActionTitle).bot().button(IDialogConstants.OK_LABEL).click();
    SWTBotShell selectDialog = bot.shell(UIText.CommitSelectDialog_WindowTitle);
    assertEquals(2, selectDialog.bot().table().rowCount());
    selectDialog.close();
    // we have closed, so nothing should have changed
    String oldContent = getTestFileContent();
    assertTrue(newContent.equals(oldContent));

    clickReplaceWith(menuLabel);
    bot.shell(UIText.DiscardChangesAction_confirmActionTitle).bot().button(IDialogConstants.OK_LABEL).click();
    selectDialog = bot.shell(UIText.CommitSelectDialog_WindowTitle);
    selectDialog.bot().table().select(1);
    selectDialog.bot().button(IDialogConstants.OK_LABEL).click();
    TestUtil.joinJobs(org.eclipse.egit.ui.JobFamilies.DISCARD_CHANGES);
    oldContent = getTestFileContent();
    assertFalse(newContent.equals(oldContent));
    // cleanup: checkout again master and delete merged branch
    git.checkout().setName("refs/heads/master").call();
    git.branchDelete().setBranchNames(newBranch.getName()).setForce(true).call();
}

From source file:org.eclipse.egit.ui.test.team.actions.TagActionTest.java

License:Open Source License

@BeforeClass
public static void setup() throws Exception {
    perspective = bot.activePerspective();
    bot.perspectiveById("org.eclipse.pde.ui.PDEPerspective").activate();

    repositoryFile = createProjectAndCommitToRepository();
    Repository repo = lookupRepository(repositoryFile);

    TagBuilder tag = new TagBuilder();
    tag.setTag("SomeTag");
    tag.setTagger(RawParseUtils.parsePersonIdent(TestUtil.TESTAUTHOR));
    tag.setMessage("I'm just a little tag");
    tag.setObjectId(repo.resolve(repo.getFullBranch()), Constants.OBJ_COMMIT);
    TagOperation top = new TagOperation(repo, tag, false);
    top.execute(null);//w w  w  .java 2  s  . c o m
    touchAndSubmit(null);
    waitInUI();
}