Search in sources :

Example 1 with ResetOperation

use of org.eclipse.egit.core.op.ResetOperation in project egit by eclipse.

the class CompareActionsTest method testCompareWithIndex.

@Test
public void testCompareWithIndex() throws Exception {
    String compareWithIndexActionLabel = util.getPluginLocalizedValue("CompareWithIndexAction_label");
    clickCompareWith(compareWithIndexActionLabel);
    // compare with index should not have any changes
    assertTreeCompareNoChange();
    // change test file -> should have one change
    setTestFileContent("Hello there");
    clickCompareWith(compareWithIndexActionLabel);
    assertTreeCompareChanges(1);
    // add to index -> no more changes
    try (Git git = new Git(lookupRepository(repositoryFile))) {
        git.add().addFilepattern(PROJ1 + "/" + FOLDER + "/" + FILE1).call();
    }
    clickCompareWith(compareWithIndexActionLabel);
    assertTreeCompareNoChange();
    // reset -> there should be no more changes
    ResetOperation rop = new ResetOperation(lookupRepository(repositoryFile), "refs/heads/master", ResetType.HARD);
    rop.execute(new NullProgressMonitor());
    clickCompareWith(compareWithIndexActionLabel);
    assertTreeCompareNoChange();
}
Also used : ResetOperation(org.eclipse.egit.core.op.ResetOperation) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Git(org.eclipse.jgit.api.Git) Test(org.junit.Test)

Example 2 with ResetOperation

use of org.eclipse.egit.core.op.ResetOperation in project egit by eclipse.

the class ResetOperationTest method testSoftReset.

@Test
public void testSoftReset() throws Exception {
    setupRepository();
    String fileInIndexPath = fileInIndex.getLocation().toPortableString();
    new ResetOperation(repository, initialCommit.getName(), ResetType.SOFT).execute(null);
    // .project must remain
    assertTrue(projectFile.exists());
    assertTrue(project.getProject().exists());
    // check if HEAD points to initial commit now
    assertTrue(repository.resolve("HEAD").equals(initialCommit));
    // untrackedFile and fileInIndex must still exist
    assertTrue(untrackedFile.exists());
    assertTrue(fileInIndex.exists());
    // fileInIndex must no longer be in HEAD
    assertFalse(testRepository.inHead(fileInIndexPath));
    // fileInIndex must exist in the index
    assertTrue(testRepository.inIndex(fileInIndexPath));
}
Also used : ResetOperation(org.eclipse.egit.core.op.ResetOperation) Test(org.junit.Test)

Example 3 with ResetOperation

use of org.eclipse.egit.core.op.ResetOperation in project egit by eclipse.

the class ResetOperationTest method testHardReset.

@Test
public void testHardReset() throws Exception {
    setupRepository();
    String fileInIndexPath = fileInIndex.getLocation().toPortableString();
    new ResetOperation(repository, initialCommit.getName(), ResetType.HARD).execute(null);
    // .project must disappear, related Eclipse project must be deleted
    assertFalse(projectFile.exists());
    assertFalse(project.getProject().exists());
    // check if HEAD points to initial commit now
    assertTrue(repository.resolve("HEAD").equals(initialCommit));
    // check if files were removed
    assertFalse(untrackedFile.exists());
    assertFalse(fileInIndex.exists());
    // fileInIndex must no longer be in HEAD and in the index
    assertFalse(testRepository.inHead(fileInIndexPath));
    assertFalse(testRepository.inIndex(fileInIndexPath));
}
Also used : ResetOperation(org.eclipse.egit.core.op.ResetOperation) Test(org.junit.Test)

Example 4 with ResetOperation

use of org.eclipse.egit.core.op.ResetOperation in project egit by eclipse.

the class CleanupUncomittedChangesDialog method buttonPressed.

@Override
protected void buttonPressed(int buttonId) {
    switch(buttonId) {
        case IDialogConstants.PROCEED_ID:
            CommitUI commitUI = new CommitUI(getShell(), repository, new IResource[0], true);
            shouldContinue = commitUI.commit();
            break;
        case IDialogConstants.ABORT_ID:
            final ResetOperation operation = new ResetOperation(repository, Constants.HEAD, ResetType.HARD);
            String jobname = NLS.bind(UIText.ResetAction_reset, Constants.HEAD);
            JobUtil.scheduleUserWorkspaceJob(operation, jobname, JobFamilies.RESET);
            shouldContinue = true;
            break;
        case IDialogConstants.SKIP_ID:
            StashCreateUI stashCreateUI = new StashCreateUI(repository);
            shouldContinue = stashCreateUI.createStash(getShell());
            break;
        case IDialogConstants.CANCEL_ID:
        default:
            break;
    }
    super.buttonPressed(buttonId);
}
Also used : ResetOperation(org.eclipse.egit.core.op.ResetOperation) StashCreateUI(org.eclipse.egit.ui.internal.stash.StashCreateUI) CommitUI(org.eclipse.egit.ui.internal.commit.CommitUI)

Example 5 with ResetOperation

use of org.eclipse.egit.core.op.ResetOperation in project egit by eclipse.

the class CompareActionsTest method testCompareWithHead.

@Test
public void testCompareWithHead() throws Exception {
    String compareWithHeadMenuLabel = util.getPluginLocalizedValue("CompareWithHeadAction_label");
    clickCompareWithAndWaitForSync(compareWithHeadMenuLabel);
    closeFirstEmptySynchronizeDialog();
    assertSynchronizeNoChange();
    // change test file -> should have one change
    setTestFileContent("Hello there");
    clickCompareWithAndWaitForSync(compareWithHeadMenuLabel);
    assertSynchronizeFile1Changed();
    // add to index -> should still show as change
    try (Git git = new Git(lookupRepository(repositoryFile))) {
        git.add().addFilepattern(PROJ1 + "/" + FOLDER + "/" + FILE1).call();
    }
    clickCompareWithAndWaitForSync(compareWithHeadMenuLabel);
    assertSynchronizeFile1Changed();
    // reset -> there should be no more changes
    ResetOperation rop = new ResetOperation(lookupRepository(repositoryFile), "refs/heads/master", ResetType.HARD);
    rop.execute(new NullProgressMonitor());
    clickCompareWithAndWaitForSync(compareWithHeadMenuLabel);
    assertSynchronizeNoChange();
}
Also used : ResetOperation(org.eclipse.egit.core.op.ResetOperation) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Git(org.eclipse.jgit.api.Git) Test(org.junit.Test)

Aggregations

ResetOperation (org.eclipse.egit.core.op.ResetOperation)8 Test (org.junit.Test)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Git (org.eclipse.jgit.api.Git)2 CommitUI (org.eclipse.egit.ui.internal.commit.CommitUI)1 ResetTargetSelectionDialog (org.eclipse.egit.ui.internal.dialogs.ResetTargetSelectionDialog)1 StashCreateUI (org.eclipse.egit.ui.internal.stash.StashCreateUI)1 ResetType (org.eclipse.jgit.api.ResetCommand.ResetType)1 Repository (org.eclipse.jgit.lib.Repository)1