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;
}
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);
}
}
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);
}
}
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());
}
}
Aggregations