use of org.eclipse.egit.core.op.CommitOperation in project egit by eclipse.
the class CreatePatchActionTest method setup.
@Before
public void setup() throws Exception {
createProjectAndCommitToRepository();
IFile[] commitables = getAllFiles();
CommitOperation cop = new CommitOperation(commitables, Arrays.asList(commitables), TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
cop.setAmending(true);
cop.execute(null);
}
use of org.eclipse.egit.core.op.CommitOperation in project egit by eclipse.
the class SynchronizeViewRemoteAwareChangeSetModelTest method createMockLogicalRepository.
protected void createMockLogicalRepository() throws Exception {
File gitDir = new File(new File(getTestDirectory(), MOCK_LOGICAL_PROJECT), Constants.DOT_GIT);
Repository repo = FileRepositoryBuilder.create(gitDir);
repo.create();
// we need to commit into master first
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(MOCK_LOGICAL_PROJECT);
if (project.exists()) {
project.delete(true, null);
TestUtil.waitForJobs(100, 5000);
}
IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(MOCK_LOGICAL_PROJECT);
desc.setLocation(new Path(new File(repo.getWorkTree(), MOCK_LOGICAL_PROJECT).getPath()));
project.create(desc, null);
project.open(null);
assertTrue("Project is not accessible: " + project, project.isAccessible());
TestUtil.waitForJobs(50, 5000);
try {
new ConnectProviderOperation(project, gitDir).execute(null);
} catch (Exception e) {
Activator.logError("Failed to connect project to repository", e);
}
assertConnected(project);
mockLogicalFile = project.getFile("index.mocklogical");
mockLogicalFile.create(new ByteArrayInputStream("file1.txt\nfile2.txt".getBytes(project.getDefaultCharset())), false, null);
IFile file1 = project.getFile("file1.txt");
file1.create(new ByteArrayInputStream("Content 1".getBytes(project.getDefaultCharset())), false, null);
IFile file2 = project.getFile("file2.txt");
file2.create(new ByteArrayInputStream("Content 2".getBytes(project.getDefaultCharset())), false, null);
IFile[] commitables = new IFile[] { mockLogicalFile, file1, file2 };
List<IFile> untracked = new ArrayList<>();
untracked.addAll(Arrays.asList(commitables));
CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
op.execute(null);
RevCommit firstCommit = op.getCommit();
CreateLocalBranchOperation createBranchOp = new CreateLocalBranchOperation(repo, "refs/heads/stable", firstCommit);
createBranchOp.execute(null);
// Delete file2.txt from logical model and add file3
mockLogicalFile = touch(MOCK_LOGICAL_PROJECT, "index.mocklogical", "file1.txt\nfile3.txt");
file2.delete(true, null);
touch(MOCK_LOGICAL_PROJECT, "file1.txt", "Content 1 modified");
IFile file3 = project.getFile("file3.txt");
file3.create(new ByteArrayInputStream("Content 3".getBytes(project.getDefaultCharset())), false, null);
commitables = new IFile[] { mockLogicalFile, file1, file2, file3 };
untracked = new ArrayList<>();
untracked.add(file3);
op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Second commit");
op.execute(null);
}
use of org.eclipse.egit.core.op.CommitOperation in project egit by eclipse.
the class CommitOperationTest method testCommitUntracked.
@Test
public void testCommitUntracked() throws Exception {
IFile fileA = testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
IFile fileB = testUtils.addFileToProject(project.getProject(), "foo/b.txt", "some text");
testUtils.addFileToProject(project.getProject(), "foo/c.txt", "some text");
IFile[] filesToCommit = { fileA, fileB };
CommitOperation commitOperation = new CommitOperation(filesToCommit, Arrays.asList(filesToCommit), TestUtils.AUTHOR, TestUtils.COMMITTER, "first commit");
commitOperation.execute(null);
testUtils.assertRepositoryContainsFiles(repository, getRepoRelativePaths(filesToCommit));
}
use of org.eclipse.egit.core.op.CommitOperation in project egit by eclipse.
the class CommitOperationTest method testCommitWithStaging.
@Test
public void testCommitWithStaging() throws Exception {
IFile fileA = testUtils.addFileToProject(project.getProject(), "foo/a.txt", "some text");
IFile fileB = testUtils.addFileToProject(project.getProject(), "foo/b.txt", "some text");
IFile[] filesToCommit = { fileA, fileB };
CommitOperation commitOperation = new CommitOperation(filesToCommit, Arrays.asList(filesToCommit), TestUtils.AUTHOR, TestUtils.COMMITTER, "first commit");
commitOperation.execute(null);
testUtils.changeContentOfFile(project.getProject(), fileA, "new content of A");
testUtils.changeContentOfFile(project.getProject(), fileB, "new content of B");
resources.add(fileA);
resources.add(fileB);
commitOperation = new CommitOperation(filesToCommit, EMPTY_FILE_LIST, TestUtils.AUTHOR, TestUtils.COMMITTER, "first commit");
commitOperation.execute(null);
testUtils.assertRepositoryContainsFilesWithContent(repository, "foo/a.txt", "new content of A", "foo/b.txt", "new content of B");
}
use of org.eclipse.egit.core.op.CommitOperation in project egit by eclipse.
the class InitHandler method createInitialCommit.
private void createInitialCommit(Repository repository) throws ExecutionException {
CommitHelper commitHelper = new CommitHelper(repository);
CommitOperation commitOperation;
try {
commitOperation = new CommitOperation(repository, commitHelper.getAuthor(), commitHelper.getCommitter(), UIText.InitHandler_initialCommit);
commitOperation.execute(null);
} catch (CoreException e) {
throw new ExecutionException(e.getMessage(), e);
}
}
Aggregations