Search in sources :

Example 1 with CommitOperation

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) CommitOperation(org.eclipse.egit.core.op.CommitOperation) Before(org.junit.Before)

Example 2 with CommitOperation

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);
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) CreateLocalBranchOperation(org.eclipse.egit.core.op.CreateLocalBranchOperation) IProject(org.eclipse.core.resources.IProject) Repository(org.eclipse.jgit.lib.Repository) ByteArrayInputStream(java.io.ByteArrayInputStream) CommitOperation(org.eclipse.egit.core.op.CommitOperation) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 3 with CommitOperation

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));
}
Also used : IFile(org.eclipse.core.resources.IFile) CommitOperation(org.eclipse.egit.core.op.CommitOperation) Test(org.junit.Test)

Example 4 with CommitOperation

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");
}
Also used : IFile(org.eclipse.core.resources.IFile) CommitOperation(org.eclipse.egit.core.op.CommitOperation) Test(org.junit.Test)

Example 5 with CommitOperation

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);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) CommitOperation(org.eclipse.egit.core.op.CommitOperation) CommitHelper(org.eclipse.egit.ui.internal.commit.CommitHelper) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

CommitOperation (org.eclipse.egit.core.op.CommitOperation)22 IFile (org.eclipse.core.resources.IFile)16 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 IProject (org.eclipse.core.resources.IProject)7 CoreException (org.eclipse.core.runtime.CoreException)6 AddToIndexOperation (org.eclipse.egit.core.op.AddToIndexOperation)6 File (java.io.File)5 IOException (java.io.IOException)4 Repository (org.eclipse.jgit.lib.Repository)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IFolder (org.eclipse.core.resources.IFolder)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 Job (org.eclipse.core.runtime.jobs.Job)2 IndexDiffCache (org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)2 BranchOperation (org.eclipse.egit.core.op.BranchOperation)2