Search in sources :

Example 1 with StashCreateOperation

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

the class StashCreateUI method createStash.

/**
 * @param shell
 *            the shell to use for showing the message input dialog
 * @return true if a stash create operation was triggered
 */
public boolean createStash(Shell shell) {
    if (!UIUtils.saveAllEditors(repo))
        return false;
    StashCreateDialog commitMessageDialog = new StashCreateDialog(shell);
    if (commitMessageDialog.open() != Window.OK)
        return false;
    String message = commitMessageDialog.getValue();
    if (message.length() == 0)
        message = null;
    boolean includeUntracked = commitMessageDialog.getIncludeUntracked();
    final StashCreateOperation op = new StashCreateOperation(repo, message, includeUntracked);
    Job job = new WorkspaceJob(UIText.StashCreateCommand_jobTitle) {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
                op.execute(monitor);
                RevCommit commit = op.getCommit();
                if (commit == null) {
                    showNoChangesToStash();
                }
            } catch (CoreException e) {
                Activator.logError(UIText.StashCreateCommand_stashFailed, e);
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            if (JobFamilies.STASH.equals(family))
                return true;
            return super.belongsTo(family);
        }
    };
    job.setUser(true);
    job.setRule(op.getSchedulingRule());
    job.schedule();
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) StashCreateOperation(org.eclipse.egit.core.op.StashCreateOperation) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with StashCreateOperation

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

the class StashCreateOperationTest method testDefaultMessage.

@Test
public void testDefaultMessage() throws Exception {
    IFile file = testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
    new AddToIndexOperation(Arrays.asList(file)).execute(null);
    StashCreateOperation stashCreateOperation = new StashCreateOperation(repository);
    stashCreateOperation.execute(null);
    try (RevWalk revWalk = new RevWalk(repository)) {
        RevCommit commit = revWalk.parseCommit(repository.resolve("stash@{0}"));
        assertTrue(commit.getFullMessage().length() > 0);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) StashCreateOperation(org.eclipse.egit.core.op.StashCreateOperation) RevWalk(org.eclipse.jgit.revwalk.RevWalk) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 3 with StashCreateOperation

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

the class StashCreateOperationTest method testUntrackedFlag.

@Test
public void testUntrackedFlag() throws Exception {
    testUtils.addFileToProject(project.getProject(), "foo/untracked.txt", "some text");
    String message = "stash with untracked files";
    StashCreateOperation stashCreateOperation = new StashCreateOperation(repository, message, true);
    stashCreateOperation.execute(null);
    try (RevWalk revWalk = new RevWalk(repository)) {
        RevCommit commit = revWalk.parseCommit(repository.resolve("stash@{0}"));
        // untracked commit is the third parent
        assertEquals(commit.getParentCount(), 3);
    }
}
Also used : StashCreateOperation(org.eclipse.egit.core.op.StashCreateOperation) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 4 with StashCreateOperation

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

the class StashCreateOperationTest method testCustomMessage.

@Test
public void testCustomMessage() throws Exception {
    IFile file = testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
    new AddToIndexOperation(Arrays.asList(file)).execute(null);
    String message = "stash message";
    StashCreateOperation stashCreateOperation = new StashCreateOperation(repository, message);
    stashCreateOperation.execute(null);
    try (RevWalk revWalk = new RevWalk(repository)) {
        RevCommit commit = revWalk.parseCommit(repository.resolve("stash@{0}"));
        assertEquals(message, commit.getFullMessage());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) StashCreateOperation(org.eclipse.egit.core.op.StashCreateOperation) RevWalk(org.eclipse.jgit.revwalk.RevWalk) AddToIndexOperation(org.eclipse.egit.core.op.AddToIndexOperation) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

StashCreateOperation (org.eclipse.egit.core.op.StashCreateOperation)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 Test (org.junit.Test)3 IFile (org.eclipse.core.resources.IFile)2 AddToIndexOperation (org.eclipse.egit.core.op.AddToIndexOperation)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Job (org.eclipse.core.runtime.jobs.Job)1