Example usage for org.eclipse.jgit.internal.storage.file FileRepository getWorkTree

List of usage examples for org.eclipse.jgit.internal.storage.file FileRepository getWorkTree

Introduction

In this page you can find the example usage for org.eclipse.jgit.internal.storage.file FileRepository getWorkTree.

Prototype

@NonNull
public File getWorkTree() throws NoWorkTreeException 

Source Link

Document

Get the root directory of the working tree, where files are checked out for viewing and editing.

Usage

From source file:com.tenxdev.ovcs.command.AbstractChangeCommand.java

License:Open Source License

/**
 * Fetch all changed objects from database, write original source to disk,
 * warn if original is different from last commit, then write all changed
 * source to disk.//from  w  w w . j  a  v a 2 s  .c o m
 *
 * @param repository
 *            the local git repository
 * @return a list of changed files
 * @throws OvcsException
 *             for errors during processing
 */
protected List<ChangeEntry> writeChanges(final FileRepository repository) throws OvcsException {
    final Path workingDirectory = repository.getWorkTree().toPath();
    try (Connection conn = getDbConnectionForRepo(repository)) {
        try (CallableStatement stmt = conn.prepareCall("begin\n"
                + "DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',false);\n"
                + "DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'TABLESPACE',false);\n"
                + "DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SEGMENT_ATTRIBUTES',false);\nend;")) {

            stmt.execute();
        }
        try (PreparedStatement stmt = conn.prepareStatement(CHANGES_QUERY)) {
            try (ResultSet rset = stmt.executeQuery()) {
                writeChangesFirstPass(rset, workingDirectory);
            }
        }
        try (PreparedStatement stmt = conn.prepareStatement(CHANGES_QUERY)) {
            try (ResultSet rset = stmt.executeQuery()) {
                return writeChangesSecondPass(rset, workingDirectory);
            }
        }
    } catch (final SQLException e) {
        throw new OvcsException("Unable to query database: " + e.getMessage(), e);
    }
}

From source file:com.tenxdev.ovcs.command.SyncCommand.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w  w  w.  java2s. co  m*/
 */
@Override
public void execute(final String... args) throws OvcsException {
    if (args.length != 1) {
        throw new UsageException(USAGE);
    }
    final FileRepository repository = getRepoForCurrentDir();
    try {
        final File workingDirectory = repository.getWorkTree();
        new Git(repository).pull().setProgressMonitor(new TextProgressMonitor()).call();
        try (Connection conn = getDbConnectionForRepo(repository)) {
            writeSchemaObjects(conn, workingDirectory.toPath());
            commitAndPush();
        } catch (final SQLException e) {
            throw new OvcsException("Unable to connect to database: " + e.getMessage(), e);
        }
    } catch (final GitAPIException e) {
        throw new OvcsException("Unable to synchronize with remote repository: " + e.getMessage(), e);
    } finally {
        repository.close();
    }
}

From source file:org.eclipse.egit.ui.submodule.SubmoduleSyncTest.java

License:Open Source License

@Test
public void syncSubmodule() throws Exception {
    deleteAllProjects();/*  w  ww.  ja  v a2 s  .co m*/
    assertProjectExistence(PROJ1, false);
    clearView();
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryFile);
    shareProjects(repositoryFile);
    assertProjectExistence(PROJ1, true);
    refreshAndWait();
    assertHasRepo(repositoryFile);
    FileRepository repo = lookupRepository(repositoryFile);

    SubmoduleAddCommand command = new SubmoduleAddCommand(repo);
    String path = "sub";
    command.setPath(path);
    String uri = new URIish(repo.getDirectory().toURI().toString()).toString();
    command.setURI(uri);
    Repository subRepo = command.call();
    assertNotNull(subRepo);

    String newUri = "git://server/repo.git";
    File modulesFile = new File(repo.getWorkTree(), Constants.DOT_GIT_MODULES);
    FileBasedConfig config = new FileBasedConfig(modulesFile, repo.getFS());
    config.load();
    config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path, ConfigConstants.CONFIG_KEY_URL, newUri);
    config.save();

    assertEquals(uri, repo.getConfig().getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
            ConfigConstants.CONFIG_KEY_URL));
    assertEquals(uri, subRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION,
            Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));

    refreshAndWait();
    SWTBotTree tree = getOrOpenView().bot().tree();
    tree.getAllItems()[0].expand().expandNode(UIText.RepositoriesViewLabelProvider_SubmodulesNodeText).select();
    ContextMenuHelper.clickContextMenuSync(tree,
            myUtil.getPluginLocalizedValue(SYNC_SUBMODULE_CONTEXT_MENU_LABEL));
    TestUtil.joinJobs(JobFamilies.SUBMODULE_SYNC);
    refreshAndWait();

    assertEquals(newUri, repo.getConfig().getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, path,
            ConfigConstants.CONFIG_KEY_URL));
    assertEquals(newUri, subRepo.getConfig().getString(ConfigConstants.CONFIG_REMOTE_SECTION,
            Constants.DEFAULT_REMOTE_NAME, ConfigConstants.CONFIG_KEY_URL));
}

From source file:org.eclipse.egit.ui.view.repositories.GitRepositoriesViewRepoDeletionTest.java

License:Open Source License

@Test
public void testDeleteRepositoryWithContentOk() throws Exception {
    deleteAllProjects();//from   w w w.  j av  a2s  .  c o m
    assertProjectExistence(PROJ1, false);
    clearView();
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(repositoryFile);
    shareProjects(repositoryFile);
    assertProjectExistence(PROJ1, true);
    refreshAndWait();
    assertHasRepo(repositoryFile);
    SWTBotTree tree = getOrOpenView().bot().tree();
    tree.getAllItems()[0].select();
    ContextMenuHelper.clickContextMenu(tree,
            myUtil.getPluginLocalizedValue(DELETE_REPOSITORY_CONTEXT_MENU_LABEL));
    SWTBotShell shell = bot.shell(UIText.DeleteRepositoryConfirmDialog_DeleteRepositoryWindowTitle);
    shell.activate();
    FileRepository repo = lookupRepository(repositoryFile);
    String workDir = repo.getWorkTree().getPath();
    String checkboxLabel = NLS.bind(UIText.DeleteRepositoryConfirmDialog_DeleteWorkingDirectoryCheckbox,
            workDir);
    shell.bot().checkBox(checkboxLabel).select();
    shell.bot().button(IDialogConstants.OK_LABEL).click();
    TestUtil.joinJobs(JobFamilies.REPOSITORY_DELETE);

    refreshAndWait();
    assertEmpty();
    assertProjectExistence(PROJ1, false);
    assertFalse(repositoryFile.exists());
}