Search in sources :

Example 21 with ConnectProviderOperation

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

the class ShowBlameActionHandlerTest method createJavaProjectAndCommitToRepository.

private IJavaProject createJavaProjectAndCommitToRepository() throws Exception {
    Repository myRepository = createLocalTestRepository(REPO1);
    File gitDir = myRepository.getDirectory();
    IJavaProject jProject = createJavaProject(myRepository, JAVA_PROJECT_NAME);
    IProject project = jProject.getProject();
    try {
        new ConnectProviderOperation(project, gitDir).execute(null);
    } catch (Exception e) {
        Activator.logError("Failed to connect project to repository", e);
    }
    assertConnected(project);
    // Check in at least the java file
    IFolder folder = project.getFolder(SRC_FOLDER_NAME).getFolder(PACKAGE_NAME);
    IFile file = folder.getFile(JAVA_FILE_NAME);
    IFile[] commitables = new IFile[] { file };
    ArrayList<IFile> untracked = new ArrayList<IFile>();
    untracked.addAll(Arrays.asList(commitables));
    // commit to master
    CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
    op.execute(null);
    // Make sure cache entry is already listening for changes
    IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
    cache.getIndexDiffCacheEntry(lookupRepository(gitDir));
    return jProject;
}
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) CoreException(org.eclipse.core.runtime.CoreException) Repository(org.eclipse.jgit.lib.Repository) IJavaProject(org.eclipse.jdt.core.IJavaProject) 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 22 with ConnectProviderOperation

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

the class TestRepository method connect.

/**
 * Connect a project to this repository
 *
 * @param project
 * @throws Exception
 */
public void connect(IProject project) throws Exception {
    ConnectProviderOperation op = new ConnectProviderOperation(project, this.getRepository().getDirectory());
    op.execute(null);
    TestUtils.waitForJobs(50, 5000, null);
}
Also used : ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation)

Example 23 with ConnectProviderOperation

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

the class HistoryTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    // ensure we are working on an empty repository
    if (gitDir.exists())
        FileUtils.delete(gitDir, FileUtils.RECURSIVE | FileUtils.RETRY);
    thisGit = FileRepositoryBuilder.create(gitDir);
    workDir = thisGit.getWorkTree();
    thisGit.create();
    try (Git git = new Git(thisGit)) {
        createFile("Project-1/A.txt", "A.txt - first version\n");
        createFile("Project-1/B.txt", "B.txt - first version\n");
        git.add().addFilepattern("Project-1/A.txt").addFilepattern("Project-1/B.txt").call();
        git.commit().setAuthor(jauthor).setCommitter(jcommitter).setMessage("Foo\n\nMessage").call();
        createFile("Project-1/B.txt", "B.txt - second version\n");
        git.add().addFilepattern("Project-1/B.txt").call();
        git.commit().setAuthor(jauthor).setCommitter(jcommitter).setMessage("Modified").call();
    }
    ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
    operation.execute(null);
}
Also used : Git(org.eclipse.jgit.api.Git) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) Before(org.junit.Before)

Example 24 with ConnectProviderOperation

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

the class ConnectProviderOperationTest method testAutoIgnoresDerivedFolder.

@Test
public void testAutoIgnoresDerivedFolder() throws Exception {
    // enable auto-ignore
    IEclipsePreferences p = InstanceScope.INSTANCE.getNode(Activator.getPluginId());
    boolean autoignore = p.getBoolean(GitCorePreferences.core_autoIgnoreDerivedResources, false);
    if (!autoignore) {
        p.putBoolean(GitCorePreferences.core_autoIgnoreDerivedResources, true);
    }
    try {
        Repository repository = FileRepositoryBuilder.create(gitDir);
        repository.create();
        repository.close();
        project.setBinFolderDerived();
        project.createSourceFolder();
        // not connected: no ignore
        IFolder binFolder = project.getProject().getFolder("bin");
        IPath binPath = binFolder.getLocation();
        assertTrue(binFolder.exists());
        assertFalse(RepositoryUtil.canBeAutoIgnored(binPath));
        IFolder srcFolder = project.getProject().getFolder("src");
        IPath srcPath = srcFolder.getLocation();
        assertTrue(srcFolder.exists());
        assertFalse(RepositoryUtil.canBeAutoIgnored(srcPath));
        IFolder notThere = project.getProject().getFolder("notThere");
        IPath notTherePath = notThere.getLocation();
        assertFalse(notThere.exists());
        assertFalse(RepositoryUtil.canBeAutoIgnored(notTherePath));
        // connect to git
        ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), gitDir);
        operation.execute(null);
        assertTrue(RepositoryProvider.isShared(project.getProject()));
        Job.getJobManager().join(JobFamilies.AUTO_IGNORE, null);
        // connected, and already automatically ignored
        assertFalse(RepositoryUtil.canBeAutoIgnored(binPath));
        // connected, and *can* be automatically ignored
        assertTrue(RepositoryUtil.canBeAutoIgnored(srcPath));
        // connected but not existing: we should not autoignore
        assertFalse(RepositoryUtil.canBeAutoIgnored(notTherePath));
        assertTrue(gitDir.exists());
    } finally {
        if (!autoignore) {
            p.putBoolean(GitCorePreferences.core_autoIgnoreDerivedResources, false);
        }
    }
}
Also used : TestRepository(org.eclipse.egit.core.test.TestRepository) Repository(org.eclipse.jgit.lib.Repository) IPath(org.eclipse.core.runtime.IPath) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 25 with ConnectProviderOperation

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

the class ConnectProviderOperationTest method testNoRepository.

@Test
public void testNoRepository() throws Exception {
    ConnectProviderOperation operation = new ConnectProviderOperation(project.getProject(), new File("../..", Constants.DOT_GIT));
    try {
        operation.execute(null);
        Assert.fail("Connect without repository should fail!");
    } catch (CoreException e) {
    // expected
    }
    assertFalse(RepositoryProvider.isShared(project.getProject()));
    assertFalse(gitDir.exists());
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ConnectProviderOperation(org.eclipse.egit.core.op.ConnectProviderOperation) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Test(org.junit.Test)

Aggregations

ConnectProviderOperation (org.eclipse.egit.core.op.ConnectProviderOperation)29 IProject (org.eclipse.core.resources.IProject)16 File (java.io.File)14 Repository (org.eclipse.jgit.lib.Repository)12 Test (org.junit.Test)11 IFile (org.eclipse.core.resources.IFile)10 CoreException (org.eclipse.core.runtime.CoreException)9 Path (org.eclipse.core.runtime.Path)9 IProjectDescription (org.eclipse.core.resources.IProjectDescription)7 IPath (org.eclipse.core.runtime.IPath)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 ArrayList (java.util.ArrayList)6 IFolder (org.eclipse.core.resources.IFolder)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 SubMonitor (org.eclipse.core.runtime.SubMonitor)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 TestRepository (org.eclipse.egit.core.test.TestRepository)4 Git (org.eclipse.jgit.api.Git)4 HashMap (java.util.HashMap)3