Example usage for org.eclipse.jgit.api GitCommand call

List of usage examples for org.eclipse.jgit.api GitCommand call

Introduction

In this page you can find the example usage for org.eclipse.jgit.api GitCommand call.

Prototype

@Override
public abstract T call() throws GitAPIException;

Source Link

Document

Execute the command

Usage

From source file:org.eclipse.egit.core.op.RemoveFromIndexOperation.java

License:Open Source License

public void execute(IProgressMonitor m) throws CoreException {
    IProgressMonitor monitor = (m != null) ? m : new NullProgressMonitor();

    monitor.beginTask(CoreText.RemoveFromIndexOperation_removingFilesFromIndex, pathsByRepository.size());

    for (Map.Entry<Repository, Collection<String>> entry : pathsByRepository.entrySet()) {
        Repository repository = entry.getKey();
        Collection<String> paths = entry.getValue();

        GitCommand<?> command = prepareCommand(repository, paths);

        try {/*from  w ww .  j a va  2s  .  co m*/
            command.call();
            monitor.worked(1);
        } catch (GitAPIException e) {
            Activator.logError(e.getMessage(), e);
        } finally {
            findRepositoryMapping(repository).fireRepositoryChanged();
        }
    }

    monitor.done();
}

From source file:org.flowerplatform.web.git.GitUtils.java

License:Open Source License

/**
 * This method must be used to set user configuration before running
 * some GIT commands that uses it.//from   w ww . j a  va 2s.co m
 * 
 * <p>
 * A lock/unlock on repository is done before/after the command is executed
 * because the configuration modifies the same file and this will not be
 * thread safe any more.
 */
public Object runGitCommandInUserRepoConfig(Repository repo, GitCommand<?> command) throws Exception {
    namedLockPool.lock(repo.getDirectory().getPath());

    try {
        StoredConfig c = repo.getConfig();
        c.load();
        User user = (User) CommunicationPlugin.tlCurrentPrincipal.get().getUser();

        c.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_NAME, user.getName());
        c.setString(ConfigConstants.CONFIG_USER_SECTION, null, ConfigConstants.CONFIG_KEY_EMAIL,
                user.getEmail());

        c.save();

        return command.call();
    } catch (Exception e) {
        throw e;
    } finally {
        namedLockPool.unlock(repo.getDirectory().getPath());
    }
}