Search in sources :

Example 6 with ResetOperation

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

the class ResetOperationTest method testMixedReset.

@Test
public void testMixedReset() throws Exception {
    setupRepository();
    String fileInIndexPath = fileInIndex.getLocation().toPortableString();
    new ResetOperation(repository, initialCommit.getName(), ResetType.MIXED).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 not in the index
    assertFalse(testRepository.inIndex(fileInIndexPath));
}
Also used : ResetOperation(org.eclipse.egit.core.op.ResetOperation) Test(org.junit.Test)

Example 7 with ResetOperation

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

the class ResetActionHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Repository repository = getRepository(true, event);
    if (repository == null)
        return null;
    if (!repository.getRepositoryState().canResetHead()) {
        MessageDialog.openError(getShell(event), UIText.ResetAction_errorResettingHead, NLS.bind(UIText.ResetAction_repositoryState, repository.getRepositoryState().getDescription()));
        return null;
    }
    ResetTargetSelectionDialog branchSelectionDialog = new ResetTargetSelectionDialog(getShell(event), repository);
    if (branchSelectionDialog.open() == IDialogConstants.OK_ID) {
        final String refName = branchSelectionDialog.getRefName();
        final ResetType type = branchSelectionDialog.getResetType();
        String jobname = NLS.bind(UIText.ResetAction_reset, refName);
        final ResetOperation operation = new ResetOperation(repository, refName, type);
        JobUtil.scheduleUserWorkspaceJob(operation, jobname, JobFamilies.RESET);
    }
    return null;
}
Also used : ResetOperation(org.eclipse.egit.core.op.ResetOperation) Repository(org.eclipse.jgit.lib.Repository) ResetTargetSelectionDialog(org.eclipse.egit.ui.internal.dialogs.ResetTargetSelectionDialog) ResetType(org.eclipse.jgit.api.ResetCommand.ResetType)

Example 8 with ResetOperation

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

the class ResetMenu method performReset.

/**
 * @param shell
 * @param repo
 * @param commitId
 * @param resetType
 */
public static void performReset(Shell shell, final Repository repo, final ObjectId commitId, ResetType resetType) {
    final String jobName;
    switch(resetType) {
        case HARD:
            if (!CommandConfirmation.confirmHardReset(shell, repo)) {
                return;
            }
            jobName = UIText.HardResetToRevisionAction_hardReset;
            break;
        case SOFT:
            jobName = UIText.SoftResetToRevisionAction_softReset;
            break;
        case MIXED:
            jobName = UIText.MixedResetToRevisionAction_mixedReset;
            break;
        default:
            // other types are currently not used
            return;
    }
    ResetOperation operation = new ResetOperation(repo, commitId.getName(), resetType);
    JobUtil.scheduleUserWorkspaceJob(operation, jobName, JobFamilies.RESET);
}
Also used : ResetOperation(org.eclipse.egit.core.op.ResetOperation)

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