Search in sources :

Example 6 with CommitOperation

use of org.eclipse.egit.core.op.CommitOperation in project jbosstools-openshift by jbosstools.

the class EGitUtils method commit.

private static RevCommit commit(IProject project, String commitMessage, Repository repository, IProgressMonitor monitor) throws CoreException {
    Assert.isLegal(project != null, "Could not commit project. No project provided");
    Assert.isLegal(repository != null, MessageFormat.format("Could not commit. Project \"{0}\" is not connected to a repository (call #connect(project, repository) first)", project.getName()));
    /**
     * TODO: add capability to commit selectively
     */
    UserConfig userConfig = getUserConfig(repository);
    CommitOperation op = new CommitOperation(null, null, null, getFormattedUser(userConfig.getAuthorName(), userConfig.getAuthorEmail()), getFormattedUser(userConfig.getCommitterName(), userConfig.getCommitterEmail()), commitMessage);
    op.setCommitAll(true);
    op.setRepository(repository);
    op.execute(monitor);
    return op.getCommit();
}
Also used : CommitOperation(org.eclipse.egit.core.op.CommitOperation) UserConfig(org.eclipse.jgit.lib.UserConfig)

Example 7 with CommitOperation

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

the class LocalRepositoryTestCase method addAndCommit.

protected static void addAndCommit(IFile file, String commitMessage) throws Exception {
    IProject prj = file.getProject();
    if (!prj.isAccessible())
        throw new IllegalStateException("No project to touch");
    IFile[] commitables = new IFile[] { file };
    ArrayList<IFile> untracked = new ArrayList<IFile>();
    untracked.addAll(Arrays.asList(commitables));
    CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, commitMessage);
    op.execute(null);
    TestUtil.waitForJobs(50, 5000);
}
Also used : IFile(org.eclipse.core.resources.IFile) CommitOperation(org.eclipse.egit.core.op.CommitOperation) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject)

Example 8 with CommitOperation

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

the class LocalRepositoryTestCase method touchAndSubmit.

/**
 * Modify with the given content and commit.
 *
 * @param newContent
 *            new file content
 * @param commitMessage
 *            may be null
 * @throws Exception
 */
protected static void touchAndSubmit(String newContent, String commitMessage) throws Exception {
    IFile file = touch(newContent);
    IFile[] commitables = new IFile[] { file };
    ArrayList<IFile> untracked = new ArrayList<IFile>();
    untracked.addAll(Arrays.asList(commitables));
    String message = commitMessage;
    if (message == null)
        message = newContent;
    CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, message);
    op.execute(null);
    TestUtil.waitForJobs(50, 5000);
}
Also used : IFile(org.eclipse.core.resources.IFile) CommitOperation(org.eclipse.egit.core.op.CommitOperation) ArrayList(java.util.ArrayList)

Example 9 with CommitOperation

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

the class LocalRepositoryTestCase method createProjectAndCommitToRepository.

protected File createProjectAndCommitToRepository(String repoName, String project1Name, String project2Name) throws Exception {
    Repository myRepository = createLocalTestRepository(repoName);
    File gitDir = myRepository.getDirectory();
    // we need to commit into master first
    IProject firstProject = createStandardTestProjectInRepository(myRepository, project1Name);
    try {
        new ConnectProviderOperation(firstProject, gitDir).execute(null);
    } catch (Exception e) {
        Activator.logError("Failed to connect project to repository", e);
    }
    assertConnected(firstProject);
    IProject secondProject = null;
    if (project2Name != null) {
        secondProject = createStandardTestProjectInRepository(myRepository, project2Name);
        try {
            new ConnectProviderOperation(secondProject, gitDir).execute(null);
        } catch (Exception e) {
            Activator.logError("Failed to connect project to repository", e);
        }
        assertConnected(secondProject);
    }
    IFile dotProject = firstProject.getFile(".project");
    assertTrue(".project is not accessible: " + dotProject, dotProject.isAccessible());
    IFolder folder = firstProject.getFolder(FOLDER);
    IFile textFile = folder.getFile(FILE1);
    IFile textFile2 = folder.getFile(FILE2);
    IFile[] commitables = null;
    if (secondProject != null) {
        folder = secondProject.getFolder(FOLDER);
        IFile secondtextFile = folder.getFile(FILE1);
        IFile secondtextFile2 = folder.getFile(FILE2);
        commitables = new IFile[] { dotProject, textFile, textFile2, secondtextFile, secondtextFile2 };
    } else {
        commitables = new IFile[] { dotProject, textFile, textFile2 };
    }
    ArrayList<IFile> untracked = new ArrayList<IFile>();
    untracked.addAll(Arrays.asList(commitables));
    // commit to stable
    CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
    op.execute(null);
    // now create a stable branch (from master)
    createStableBranch(myRepository);
    // and check in some stuff into master again
    String newContent = "Touched at " + System.currentTimeMillis();
    IFile file = touch(firstProject.getName(), FOLDER + '/' + FILE1, newContent);
    addAndCommit(file, newContent);
    // Make sure cache entry is already listening for changes
    IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
    cache.getIndexDiffCacheEntry(lookupRepository(gitDir));
    return gitDir;
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) Repository(org.eclipse.jgit.lib.Repository) CommitOperation(org.eclipse.egit.core.op.CommitOperation) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 10 with CommitOperation

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

the class AbstractSynchronizeViewTest method createAndCommitDotGitignore.

private static void createAndCommitDotGitignore() throws CoreException, UnsupportedEncodingException {
    IProject secondPoject = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ2);
    IFile gitignore = secondPoject.getFile(".gitignore");
    gitignore.create(new ByteArrayInputStream("/.project\n".getBytes(secondPoject.getDefaultCharset())), false, null);
    IFile[] commitables = new IFile[] { gitignore };
    ArrayList<IFile> untracked = new ArrayList<IFile>();
    untracked.addAll(Arrays.asList(commitables));
    CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Add .gitignore file");
    op.execute(null);
}
Also used : IFile(org.eclipse.core.resources.IFile) ByteArrayInputStream(java.io.ByteArrayInputStream) CommitOperation(org.eclipse.egit.core.op.CommitOperation) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject)

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